Improve string formatting v6 (#33698)
This commit is contained in:
1 parent
d7e3b0b755
commit
eae21be5b9
43 files changed
+81
-87
No files matched your search
@@ -64,10 +64,7 @@ async def _create_august_with_devices(
|
||||
if api_call_side_effects is None:
|
||||
api_call_side_effects = {}
|
||||
|
||||
device_data = {
|
||||
"doorbells": [],
|
||||
"locks": [],
|
||||
}
|
||||
device_data = {"doorbells": [], "locks": []}
|
||||
for device in devices:
|
||||
if isinstance(device, LockDetail):
|
||||
device_data["locks"].append(
|
||||
@@ -212,7 +209,7 @@ def _mock_august_doorbell_data(deviceid="mockdeviceid1", houseid="mockhouseid1")
|
||||
return {
|
||||
"_id": deviceid,
|
||||
"DeviceID": deviceid,
|
||||
"name": deviceid + " Name",
|
||||
"name": f"{deviceid} Name",
|
||||
"HouseID": houseid,
|
||||
"UserType": "owner",
|
||||
"serialNumber": "mockserial",
|
||||
@@ -232,7 +229,7 @@ def _mock_august_lock_data(lockid="mocklockid1", houseid="mockhouseid1"):
|
||||
return {
|
||||
"_id": lockid,
|
||||
"LockID": lockid,
|
||||
"LockName": lockid + " Name",
|
||||
"LockName": f"{lockid} Name",
|
||||
"HouseID": houseid,
|
||||
"UserType": "owner",
|
||||
"SerialNumber": "mockserial",
|
||||
|
||||
@@ -28,7 +28,7 @@ def calls(hass):
|
||||
|
||||
def get_switch_name(number):
|
||||
"""Get a mock switch name."""
|
||||
return "Mock Switch #" + str(number)
|
||||
return f"Mock Switch #{number}"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -289,7 +289,7 @@ async def test_reachable_for_state(hass_hue, hue_client, state, is_reachable):
|
||||
|
||||
async def test_discover_full_state(hue_client):
|
||||
"""Test the discovery of full state."""
|
||||
result = await hue_client.get("/api/" + HUE_API_USERNAME)
|
||||
result = await hue_client.get(f"/api/{HUE_API_USERNAME}")
|
||||
|
||||
assert result.status == 200
|
||||
assert "application/json" in result.headers["content-type"]
|
||||
|
||||
@@ -285,7 +285,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
group_conf = OrderedDict()
|
||||
group_conf["second_group"] = {
|
||||
"entities": "light.Bowl, " + test_group.entity_id,
|
||||
"entities": f"light.Bowl, {test_group.entity_id}",
|
||||
"icon": "mdi:work",
|
||||
}
|
||||
group_conf["test_group"] = "hello.world,sensor.happy"
|
||||
|
||||
@@ -110,7 +110,7 @@ class TestHDDTempSensor(unittest.TestCase):
|
||||
)
|
||||
assert (
|
||||
state.attributes.get("friendly_name")
|
||||
== "HD Temperature " + reference["device"]
|
||||
== f"HD Temperature {reference['device']}"
|
||||
)
|
||||
|
||||
@patch("telnetlib.Telnet", new=TelnetMock)
|
||||
@@ -123,7 +123,7 @@ class TestHDDTempSensor(unittest.TestCase):
|
||||
|
||||
reference = self.reference[state.attributes.get("device")]
|
||||
|
||||
assert state.attributes.get("friendly_name") == "FooBar " + reference["device"]
|
||||
assert state.attributes.get("friendly_name") == f"FooBar {reference['device']}"
|
||||
|
||||
@patch("telnetlib.Telnet", new=TelnetMock)
|
||||
def test_hddtemp_one_disk(self):
|
||||
@@ -143,7 +143,7 @@ class TestHDDTempSensor(unittest.TestCase):
|
||||
)
|
||||
assert (
|
||||
state.attributes.get("friendly_name")
|
||||
== "HD Temperature " + reference["device"]
|
||||
== f"HD Temperature {reference['device']}"
|
||||
)
|
||||
|
||||
@patch("telnetlib.Telnet", new=TelnetMock)
|
||||
@@ -179,7 +179,7 @@ class TestHDDTempSensor(unittest.TestCase):
|
||||
)
|
||||
assert (
|
||||
state.attributes.get("friendly_name")
|
||||
== "HD Temperature " + reference["device"]
|
||||
== f"HD Temperature {reference['device']}"
|
||||
)
|
||||
|
||||
@patch("telnetlib.Telnet", new=TelnetMock)
|
||||
|
||||
@@ -666,7 +666,7 @@ class TestInfluxDB(unittest.TestCase):
|
||||
state = mock.MagicMock(
|
||||
state=1,
|
||||
domain=comp["domain"],
|
||||
entity_id=comp["domain"] + "." + comp["id"],
|
||||
entity_id=f"{comp['domain']}.{comp['id']}",
|
||||
object_id=comp["id"],
|
||||
attributes={},
|
||||
)
|
||||
|
||||
@@ -31,7 +31,7 @@ class TestLiteJetLight(unittest.TestCase):
|
||||
self.load_deactivated_callbacks = {}
|
||||
|
||||
def get_load_name(number):
|
||||
return "Mock Load #" + str(number)
|
||||
return f"Mock Load #{number}"
|
||||
|
||||
def on_load_activated(number, callback):
|
||||
self.load_activated_callbacks[number] = callback
|
||||
|
||||
@@ -27,7 +27,7 @@ class TestLiteJetScene(unittest.TestCase):
|
||||
self.hass.start()
|
||||
|
||||
def get_scene_name(number):
|
||||
return "Mock Scene #" + str(number)
|
||||
return f"Mock Scene #{number}"
|
||||
|
||||
self.mock_lj = mock_pylitejet.return_value
|
||||
self.mock_lj.loads.return_value = range(0)
|
||||
|
||||
@@ -31,7 +31,7 @@ class TestLiteJetSwitch(unittest.TestCase):
|
||||
self.switch_released_callbacks = {}
|
||||
|
||||
def get_switch_name(number):
|
||||
return "Mock Switch #" + str(number)
|
||||
return f"Mock Switch #{number}"
|
||||
|
||||
def on_switch_pressed(number, callback):
|
||||
self.switch_pressed_callbacks[number] = callback
|
||||
|
||||
@@ -189,7 +189,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
|
||||
|
||||
assert STATE_ALARM_DISARMED == self.hass.states.get(entity_id).state
|
||||
|
||||
common.alarm_arm_home(self.hass, CODE + "2")
|
||||
common.alarm_arm_home(self.hass, f"{CODE}2")
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert STATE_ALARM_DISARMED == self.hass.states.get(entity_id).state
|
||||
@@ -342,7 +342,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
|
||||
|
||||
assert STATE_ALARM_DISARMED == self.hass.states.get(entity_id).state
|
||||
|
||||
common.alarm_arm_away(self.hass, CODE + "2")
|
||||
common.alarm_arm_away(self.hass, f"{CODE}2")
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert STATE_ALARM_DISARMED == self.hass.states.get(entity_id).state
|
||||
@@ -473,7 +473,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
|
||||
|
||||
assert STATE_ALARM_DISARMED == self.hass.states.get(entity_id).state
|
||||
|
||||
common.alarm_arm_night(self.hass, CODE + "2")
|
||||
common.alarm_arm_night(self.hass, f"{CODE}2")
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert STATE_ALARM_DISARMED == self.hass.states.get(entity_id).state
|
||||
@@ -942,7 +942,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
|
||||
"platform": "manual_mqtt",
|
||||
"name": "test",
|
||||
"pending_time": 5,
|
||||
"code": CODE + "2",
|
||||
"code": f"{CODE}2",
|
||||
"disarm_after_trigger": False,
|
||||
"command_topic": "alarm/command",
|
||||
"state_topic": "alarm/state",
|
||||
|
||||
@@ -99,7 +99,7 @@ class TestPlant(unittest.TestCase):
|
||||
self.hass, plant.DOMAIN, {plant.DOMAIN: {plant_name: GOOD_CONFIG}}
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("plant." + plant_name)
|
||||
state = self.hass.states.get(f"plant.{plant_name}")
|
||||
assert 5 == state.attributes[plant.READING_MOISTURE]
|
||||
|
||||
def test_update_states(self):
|
||||
@@ -113,7 +113,7 @@ class TestPlant(unittest.TestCase):
|
||||
)
|
||||
self.hass.states.set(MOISTURE_ENTITY, 5, {ATTR_UNIT_OF_MEASUREMENT: "us/cm"})
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("plant." + plant_name)
|
||||
state = self.hass.states.get(f"plant.{plant_name}")
|
||||
assert STATE_PROBLEM == state.state
|
||||
assert 5 == state.attributes[plant.READING_MOISTURE]
|
||||
|
||||
@@ -130,7 +130,7 @@ class TestPlant(unittest.TestCase):
|
||||
MOISTURE_ENTITY, STATE_UNAVAILABLE, {ATTR_UNIT_OF_MEASUREMENT: "us/cm"}
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("plant." + plant_name)
|
||||
state = self.hass.states.get(f"plant.{plant_name}")
|
||||
assert state.state == STATE_PROBLEM
|
||||
assert state.attributes[plant.READING_MOISTURE] == STATE_UNAVAILABLE
|
||||
|
||||
@@ -145,14 +145,14 @@ class TestPlant(unittest.TestCase):
|
||||
)
|
||||
self.hass.states.set(MOISTURE_ENTITY, 42, {ATTR_UNIT_OF_MEASUREMENT: "us/cm"})
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("plant." + plant_name)
|
||||
state = self.hass.states.get(f"plant.{plant_name}")
|
||||
assert state.state == STATE_OK
|
||||
assert state.attributes[plant.READING_MOISTURE] == 42
|
||||
self.hass.states.set(
|
||||
MOISTURE_ENTITY, STATE_UNAVAILABLE, {ATTR_UNIT_OF_MEASUREMENT: "us/cm"}
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("plant." + plant_name)
|
||||
state = self.hass.states.get(f"plant.{plant_name}")
|
||||
assert state.state == STATE_PROBLEM
|
||||
assert state.attributes[plant.READING_MOISTURE] == STATE_UNAVAILABLE
|
||||
|
||||
@@ -184,7 +184,7 @@ class TestPlant(unittest.TestCase):
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get("plant." + plant_name)
|
||||
state = self.hass.states.get(f"plant.{plant_name}")
|
||||
assert STATE_UNKNOWN == state.state
|
||||
max_brightness = state.attributes.get(plant.ATTR_MAX_BRIGHTNESS_HISTORY)
|
||||
assert 30 == max_brightness
|
||||
@@ -197,17 +197,17 @@ class TestPlant(unittest.TestCase):
|
||||
)
|
||||
self.hass.states.set(BRIGHTNESS_ENTITY, 100, {ATTR_UNIT_OF_MEASUREMENT: "lux"})
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("plant." + plant_name)
|
||||
state = self.hass.states.get(f"plant.{plant_name}")
|
||||
assert STATE_PROBLEM == state.state
|
||||
|
||||
self.hass.states.set(BRIGHTNESS_ENTITY, 600, {ATTR_UNIT_OF_MEASUREMENT: "lux"})
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("plant." + plant_name)
|
||||
state = self.hass.states.get(f"plant.{plant_name}")
|
||||
assert STATE_OK == state.state
|
||||
|
||||
self.hass.states.set(BRIGHTNESS_ENTITY, 100, {ATTR_UNIT_OF_MEASUREMENT: "lux"})
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("plant." + plant_name)
|
||||
state = self.hass.states.get(f"plant.{plant_name}")
|
||||
assert STATE_OK == state.state
|
||||
|
||||
|
||||
|
||||
@@ -48,14 +48,14 @@ class TestProximity(unittest.TestCase):
|
||||
proximities = ["home", "work"]
|
||||
|
||||
for prox in proximities:
|
||||
state = self.hass.states.get("proximity." + prox)
|
||||
state = self.hass.states.get(f"proximity.{prox}")
|
||||
assert state.state == "not set"
|
||||
assert state.attributes.get("nearest") == "not set"
|
||||
assert state.attributes.get("dir_of_travel") == "not set"
|
||||
|
||||
self.hass.states.set("proximity." + prox, "0")
|
||||
self.hass.states.set(f"proximity.{prox}", "0")
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get("proximity." + prox)
|
||||
state = self.hass.states.get(f"proximity.{prox}")
|
||||
assert state.state == "0"
|
||||
|
||||
def test_proximities_setup(self):
|
||||
|
||||
@@ -181,7 +181,7 @@ async def test_race_condition(hass, monkeypatch):
|
||||
assert updated_sensor
|
||||
|
||||
# test state of new sensor
|
||||
new_sensor = hass.states.get(DOMAIN + ".test3")
|
||||
new_sensor = hass.states.get(f"{DOMAIN}.test3")
|
||||
assert new_sensor
|
||||
assert new_sensor.state == "ok"
|
||||
|
||||
@@ -191,6 +191,6 @@ async def test_race_condition(hass, monkeypatch):
|
||||
assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR]["test3"]
|
||||
|
||||
# test state of new sensor
|
||||
new_sensor = hass.states.get(DOMAIN + ".test3")
|
||||
new_sensor = hass.states.get(f"{DOMAIN}.test3")
|
||||
assert new_sensor
|
||||
assert new_sensor.state == "ko"
|
||||
@@ -40,7 +40,7 @@ async def test_entity_state(hass, device_factory):
|
||||
await setup_platform(hass, BINARY_SENSOR_DOMAIN, devices=[device])
|
||||
state = hass.states.get("binary_sensor.motion_sensor_1_motion")
|
||||
assert state.state == "off"
|
||||
assert state.attributes[ATTR_FRIENDLY_NAME] == device.label + " " + Attribute.motion
|
||||
assert state.attributes[ATTR_FRIENDLY_NAME] == f"{device.label} {Attribute.motion}"
|
||||
|
||||
|
||||
async def test_entity_and_device_attributes(hass, device_factory):
|
||||
@@ -56,7 +56,7 @@ async def test_entity_and_device_attributes(hass, device_factory):
|
||||
# Assert
|
||||
entry = entity_registry.async_get("binary_sensor.motion_sensor_1_motion")
|
||||
assert entry
|
||||
assert entry.unique_id == device.device_id + "." + Attribute.motion
|
||||
assert entry.unique_id == f"{device.device_id}.{Attribute.motion}"
|
||||
entry = device_registry.async_get_device({(DOMAIN, device.device_id)}, [])
|
||||
assert entry
|
||||
assert entry.name == device.label
|
||||
|
||||
@@ -84,7 +84,7 @@ async def test_entity_and_device_attributes(hass, device_factory):
|
||||
# Assert
|
||||
entry = entity_registry.async_get("sensor.sensor_1_battery")
|
||||
assert entry
|
||||
assert entry.unique_id == f"{device.device_id}." + Attribute.battery
|
||||
assert entry.unique_id == f"{device.device_id}.{Attribute.battery}"
|
||||
entry = device_registry.async_get_device({(DOMAIN, device.device_id)}, [])
|
||||
assert entry
|
||||
assert entry.name == device.label
|
||||
|
||||
@@ -15,4 +15,4 @@ def pytest_runtest_makereport(item, call):
|
||||
|
||||
# set a report attribute for each phase of a call, which can
|
||||
# be "setup", "call", "teardown"
|
||||
setattr(item, "rep_" + rep.when, rep)
|
||||
setattr(item, f"rep_{rep.when}", rep)
|
||||
@@ -138,7 +138,7 @@ async def test_invalid_data(hass, aioclient_mock):
|
||||
await async_setup_component(hass, "sensor", {"sensor": VALID_CONFIG})
|
||||
|
||||
for condition in VALID_CONFIG["monitored_conditions"]:
|
||||
state = hass.states.get("sensor.pws_" + condition)
|
||||
state = hass.states.get(f"sensor.pws_{condition}")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ def mocked_requests(*args, **kwargs):
|
||||
},
|
||||
200,
|
||||
)
|
||||
if str(args[0]).endswith("timedOut/" + URL_LIST_END) and FIRST_CALL is True:
|
||||
if str(args[0]).endswith(f"timedOut/{URL_LIST_END}") and FIRST_CALL is True:
|
||||
FIRST_CALL = False
|
||||
# deliver an error when called with expired token
|
||||
return MockResponse({"code": "401", "msg": "Invalid token"}, 200)
|
||||
|
||||
@@ -245,7 +245,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
# pylint: disable=protected-access
|
||||
self.yessssms.yesss._kontomanager,
|
||||
status_code=200,
|
||||
text="test..." + login + "</a>",
|
||||
text=f"test...{login}</a>",
|
||||
)
|
||||
mock.register_uri(
|
||||
"POST",
|
||||
@@ -312,7 +312,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
# pylint: disable=protected-access
|
||||
self.yessssms.yesss._kontomanager,
|
||||
status_code=200,
|
||||
text="test..." + login + "</a>",
|
||||
text=f"test...{login}</a>",
|
||||
)
|
||||
mock.register_uri(
|
||||
"POST",
|
||||
|
||||
@@ -38,7 +38,7 @@ def teardown():
|
||||
|
||||
|
||||
def _path_for(leaf_name):
|
||||
return os.path.join(TMP_DIR, leaf_name + ".json")
|
||||
return os.path.join(TMP_DIR, f"{leaf_name}.json")
|
||||
|
||||
|
||||
def test_save_and_load():
|
||||
|
||||
@@ -129,7 +129,7 @@ def teardown():
|
||||
|
||||
|
||||
def _path_for(leaf_name):
|
||||
return os.path.join(TMP_DIR, leaf_name + ".yaml")
|
||||
return os.path.join(TMP_DIR, f"{leaf_name}.yaml")
|
||||
|
||||
|
||||
def test_save_and_load():
|
||||
|
||||
Reference in new issue
Block a user