mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 05:26:47 +00:00
Use f-strings in integrations starting with "B"-"E" (#32121)
* Use f-strings in integrations starting with B * Use f-strings in integrations starting with C * Use f-strings in integrations starting with D * Use f-strings in integrations starting with E * Fix pylint errors * Fix pylint errors v2 * Fix tests * Fix tests v2
This commit is contained in:
@@ -2,11 +2,7 @@
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import device_tracker
|
||||
from homeassistant.components.device_tracker.const import (
|
||||
ENTITY_ID_FORMAT,
|
||||
SOURCE_TYPE_BLUETOOTH,
|
||||
)
|
||||
from homeassistant.components.device_tracker.const import DOMAIN, SOURCE_TYPE_BLUETOOTH
|
||||
from homeassistant.const import CONF_PLATFORM, STATE_HOME, STATE_NOT_HOME
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@@ -35,14 +31,7 @@ async def test_ensure_device_tracker_platform_validation(hass):
|
||||
dev_id = "paulus"
|
||||
topic = "/location/paulus"
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
device_tracker.DOMAIN,
|
||||
{
|
||||
device_tracker.DOMAIN: {
|
||||
CONF_PLATFORM: "mqtt",
|
||||
"devices": {dev_id: topic},
|
||||
}
|
||||
},
|
||||
hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: topic}}}
|
||||
)
|
||||
assert mock_sp.call_count == 1
|
||||
|
||||
@@ -50,15 +39,13 @@ async def test_ensure_device_tracker_platform_validation(hass):
|
||||
async def test_new_message(hass, mock_device_tracker_conf):
|
||||
"""Test new message."""
|
||||
dev_id = "paulus"
|
||||
entity_id = ENTITY_ID_FORMAT.format(dev_id)
|
||||
entity_id = f"{DOMAIN}.{dev_id}"
|
||||
topic = "/location/paulus"
|
||||
location = "work"
|
||||
|
||||
hass.config.components = set(["mqtt", "zone"])
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
device_tracker.DOMAIN,
|
||||
{device_tracker.DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: topic}}},
|
||||
hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: topic}}}
|
||||
)
|
||||
async_fire_mqtt_message(hass, topic, location)
|
||||
await hass.async_block_till_done()
|
||||
@@ -68,7 +55,7 @@ async def test_new_message(hass, mock_device_tracker_conf):
|
||||
async def test_single_level_wildcard_topic(hass, mock_device_tracker_conf):
|
||||
"""Test single level wildcard topic."""
|
||||
dev_id = "paulus"
|
||||
entity_id = ENTITY_ID_FORMAT.format(dev_id)
|
||||
entity_id = f"{DOMAIN}.{dev_id}"
|
||||
subscription = "/location/+/paulus"
|
||||
topic = "/location/room/paulus"
|
||||
location = "work"
|
||||
@@ -76,13 +63,8 @@ async def test_single_level_wildcard_topic(hass, mock_device_tracker_conf):
|
||||
hass.config.components = set(["mqtt", "zone"])
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
device_tracker.DOMAIN,
|
||||
{
|
||||
device_tracker.DOMAIN: {
|
||||
CONF_PLATFORM: "mqtt",
|
||||
"devices": {dev_id: subscription},
|
||||
}
|
||||
},
|
||||
DOMAIN,
|
||||
{DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: subscription}}},
|
||||
)
|
||||
async_fire_mqtt_message(hass, topic, location)
|
||||
await hass.async_block_till_done()
|
||||
@@ -92,7 +74,7 @@ async def test_single_level_wildcard_topic(hass, mock_device_tracker_conf):
|
||||
async def test_multi_level_wildcard_topic(hass, mock_device_tracker_conf):
|
||||
"""Test multi level wildcard topic."""
|
||||
dev_id = "paulus"
|
||||
entity_id = ENTITY_ID_FORMAT.format(dev_id)
|
||||
entity_id = f"{DOMAIN}.{dev_id}"
|
||||
subscription = "/location/#"
|
||||
topic = "/location/room/paulus"
|
||||
location = "work"
|
||||
@@ -100,13 +82,8 @@ async def test_multi_level_wildcard_topic(hass, mock_device_tracker_conf):
|
||||
hass.config.components = set(["mqtt", "zone"])
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
device_tracker.DOMAIN,
|
||||
{
|
||||
device_tracker.DOMAIN: {
|
||||
CONF_PLATFORM: "mqtt",
|
||||
"devices": {dev_id: subscription},
|
||||
}
|
||||
},
|
||||
DOMAIN,
|
||||
{DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: subscription}}},
|
||||
)
|
||||
async_fire_mqtt_message(hass, topic, location)
|
||||
await hass.async_block_till_done()
|
||||
@@ -116,7 +93,7 @@ async def test_multi_level_wildcard_topic(hass, mock_device_tracker_conf):
|
||||
async def test_single_level_wildcard_topic_not_matching(hass, mock_device_tracker_conf):
|
||||
"""Test not matching single level wildcard topic."""
|
||||
dev_id = "paulus"
|
||||
entity_id = ENTITY_ID_FORMAT.format(dev_id)
|
||||
entity_id = f"{DOMAIN}.{dev_id}"
|
||||
subscription = "/location/+/paulus"
|
||||
topic = "/location/paulus"
|
||||
location = "work"
|
||||
@@ -124,13 +101,8 @@ async def test_single_level_wildcard_topic_not_matching(hass, mock_device_tracke
|
||||
hass.config.components = set(["mqtt", "zone"])
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
device_tracker.DOMAIN,
|
||||
{
|
||||
device_tracker.DOMAIN: {
|
||||
CONF_PLATFORM: "mqtt",
|
||||
"devices": {dev_id: subscription},
|
||||
}
|
||||
},
|
||||
DOMAIN,
|
||||
{DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: subscription}}},
|
||||
)
|
||||
async_fire_mqtt_message(hass, topic, location)
|
||||
await hass.async_block_till_done()
|
||||
@@ -140,7 +112,7 @@ async def test_single_level_wildcard_topic_not_matching(hass, mock_device_tracke
|
||||
async def test_multi_level_wildcard_topic_not_matching(hass, mock_device_tracker_conf):
|
||||
"""Test not matching multi level wildcard topic."""
|
||||
dev_id = "paulus"
|
||||
entity_id = ENTITY_ID_FORMAT.format(dev_id)
|
||||
entity_id = f"{DOMAIN}.{dev_id}"
|
||||
subscription = "/location/#"
|
||||
topic = "/somewhere/room/paulus"
|
||||
location = "work"
|
||||
@@ -148,13 +120,8 @@ async def test_multi_level_wildcard_topic_not_matching(hass, mock_device_tracker
|
||||
hass.config.components = set(["mqtt", "zone"])
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
device_tracker.DOMAIN,
|
||||
{
|
||||
device_tracker.DOMAIN: {
|
||||
CONF_PLATFORM: "mqtt",
|
||||
"devices": {dev_id: subscription},
|
||||
}
|
||||
},
|
||||
DOMAIN,
|
||||
{DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: subscription}}},
|
||||
)
|
||||
async_fire_mqtt_message(hass, topic, location)
|
||||
await hass.async_block_till_done()
|
||||
@@ -166,7 +133,7 @@ async def test_matching_custom_payload_for_home_and_not_home(
|
||||
):
|
||||
"""Test custom payload_home sets state to home and custom payload_not_home sets state to not_home."""
|
||||
dev_id = "paulus"
|
||||
entity_id = ENTITY_ID_FORMAT.format(dev_id)
|
||||
entity_id = f"{DOMAIN}.{dev_id}"
|
||||
topic = "/location/paulus"
|
||||
payload_home = "present"
|
||||
payload_not_home = "not present"
|
||||
@@ -174,9 +141,9 @@ async def test_matching_custom_payload_for_home_and_not_home(
|
||||
hass.config.components = set(["mqtt", "zone"])
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
device_tracker.DOMAIN,
|
||||
DOMAIN,
|
||||
{
|
||||
device_tracker.DOMAIN: {
|
||||
DOMAIN: {
|
||||
CONF_PLATFORM: "mqtt",
|
||||
"devices": {dev_id: topic},
|
||||
"payload_home": payload_home,
|
||||
@@ -198,7 +165,7 @@ async def test_not_matching_custom_payload_for_home_and_not_home(
|
||||
):
|
||||
"""Test not matching payload does not set state to home or not_home."""
|
||||
dev_id = "paulus"
|
||||
entity_id = ENTITY_ID_FORMAT.format(dev_id)
|
||||
entity_id = f"{DOMAIN}.{dev_id}"
|
||||
topic = "/location/paulus"
|
||||
payload_home = "present"
|
||||
payload_not_home = "not present"
|
||||
@@ -207,9 +174,9 @@ async def test_not_matching_custom_payload_for_home_and_not_home(
|
||||
hass.config.components = set(["mqtt", "zone"])
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
device_tracker.DOMAIN,
|
||||
DOMAIN,
|
||||
{
|
||||
device_tracker.DOMAIN: {
|
||||
DOMAIN: {
|
||||
CONF_PLATFORM: "mqtt",
|
||||
"devices": {dev_id: topic},
|
||||
"payload_home": payload_home,
|
||||
@@ -226,7 +193,7 @@ async def test_not_matching_custom_payload_for_home_and_not_home(
|
||||
async def test_matching_source_type(hass, mock_device_tracker_conf):
|
||||
"""Test setting source type."""
|
||||
dev_id = "paulus"
|
||||
entity_id = ENTITY_ID_FORMAT.format(dev_id)
|
||||
entity_id = f"{DOMAIN}.{dev_id}"
|
||||
topic = "/location/paulus"
|
||||
source_type = SOURCE_TYPE_BLUETOOTH
|
||||
location = "work"
|
||||
@@ -234,9 +201,9 @@ async def test_matching_source_type(hass, mock_device_tracker_conf):
|
||||
hass.config.components = set(["mqtt", "zone"])
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
device_tracker.DOMAIN,
|
||||
DOMAIN,
|
||||
{
|
||||
device_tracker.DOMAIN: {
|
||||
DOMAIN: {
|
||||
CONF_PLATFORM: "mqtt",
|
||||
"devices": {dev_id: topic},
|
||||
"source_type": source_type,
|
||||
|
||||
Reference in New Issue
Block a user