Improve string formatting v7 (#33705)

This commit is contained in:
springstan 2020-04-06 00:34:24 +02:00 committed by GitHub
parent 15f41c84f9
commit 67c3a4c970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 164 additions and 164 deletions

View File

@ -56,14 +56,14 @@ def test_generate_aid():
assert isinstance(aid, int)
assert aid >= 2 and aid <= 18446744073709551615
with patch(PATH_HOMEKIT + ".adler32") as mock_adler32:
with patch(f"{PATH_HOMEKIT}.adler32") as mock_adler32:
mock_adler32.side_effect = [0, 1]
assert generate_aid("demo.entity") is None
async def test_setup_min(hass):
"""Test async_setup with min config options."""
with patch(PATH_HOMEKIT + ".HomeKit") as mock_homekit:
with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit:
assert await setup.async_setup_component(hass, DOMAIN, {DOMAIN: {}})
mock_homekit.assert_any_call(
@ -91,7 +91,7 @@ async def test_setup_auto_start_disabled(hass):
}
}
with patch(PATH_HOMEKIT + ".HomeKit") as mock_homekit:
with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit:
mock_homekit.return_value = homekit = Mock()
assert await setup.async_setup_component(hass, DOMAIN, config)
@ -126,7 +126,7 @@ async def test_homekit_setup(hass, hk_driver):
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, None, {}, {}, DEFAULT_SAFE_MODE)
with patch(
PATH_HOMEKIT + ".accessories.HomeDriver", return_value=hk_driver
f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver
) as mock_driver, patch("homeassistant.util.get_local_ip") as mock_ip:
mock_ip.return_value = IP_ADDRESS
await hass.async_add_job(homekit.setup)
@ -151,7 +151,7 @@ async def test_homekit_setup_ip_address(hass, hk_driver):
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, "172.0.0.0", {}, {}, None)
with patch(
PATH_HOMEKIT + ".accessories.HomeDriver", return_value=hk_driver
f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver
) as mock_driver:
await hass.async_add_job(homekit.setup)
mock_driver.assert_called_with(
@ -170,7 +170,7 @@ async def test_homekit_setup_advertise_ip(hass, hk_driver):
)
with patch(
PATH_HOMEKIT + ".accessories.HomeDriver", return_value=hk_driver
f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver
) as mock_driver:
await hass.async_add_job(homekit.setup)
mock_driver.assert_called_with(
@ -186,7 +186,7 @@ async def test_homekit_setup_safe_mode(hass, hk_driver):
"""Test if safe_mode flag is set."""
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, None, {}, {}, True)
with patch(PATH_HOMEKIT + ".accessories.HomeDriver", return_value=hk_driver):
with patch(f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver):
await hass.async_add_job(homekit.setup)
assert homekit.driver.safe_mode is True
@ -197,7 +197,7 @@ async def test_homekit_add_accessory():
homekit.driver = "driver"
homekit.bridge = mock_bridge = Mock()
with patch(PATH_HOMEKIT + ".get_accessory") as mock_get_acc:
with patch(f"{PATH_HOMEKIT}.get_accessory") as mock_get_acc:
mock_get_acc.side_effect = [None, "acc", None]
homekit.add_bridge_accessory(State("light.demo", "on"))
@ -230,7 +230,7 @@ async def test_homekit_entity_filter(hass):
entity_filter = generate_filter(["cover"], ["demo.test"], [], [])
homekit = HomeKit(hass, None, None, None, entity_filter, {}, None)
with patch(PATH_HOMEKIT + ".get_accessory") as mock_get_acc:
with patch(f"{PATH_HOMEKIT}.get_accessory") as mock_get_acc:
mock_get_acc.return_value = None
homekit.add_bridge_accessory(State("cover.test", "open"))
@ -256,8 +256,8 @@ async def test_homekit_start(hass, hk_driver, debounce_patcher):
hass.states.async_set("light.demo", "on")
state = hass.states.async_all()[0]
with patch(PATH_HOMEKIT + ".HomeKit.add_bridge_accessory") as mock_add_acc, patch(
PATH_HOMEKIT + ".show_setup_message"
with patch(f"{PATH_HOMEKIT}.HomeKit.add_bridge_accessory") as mock_add_acc, patch(
f"{PATH_HOMEKIT}.show_setup_message"
) as mock_setup_msg, patch(
"pyhap.accessory_driver.AccessoryDriver.add_accessory"
) as hk_driver_add_acc, patch(
@ -302,8 +302,8 @@ async def test_homekit_reset_accessories(hass):
homekit = HomeKit(hass, None, None, None, {}, {entity_id: {}}, None)
homekit.bridge = Mock()
with patch(PATH_HOMEKIT + ".HomeKit", return_value=homekit), patch(
PATH_HOMEKIT + ".HomeKit.setup"
with patch(f"{PATH_HOMEKIT}.HomeKit", return_value=homekit), patch(
f"{PATH_HOMEKIT}.HomeKit.setup"
), patch("pyhap.accessory.Bridge.add_accessory") as mock_add_accessory, patch(
"pyhap.accessory_driver.AccessoryDriver.config_changed"
) as hk_driver_config_changed:

View File

@ -51,7 +51,7 @@ async def test_default_setup(hass, monkeypatch):
assert create.call_args_list[0][1]["ignore"]
# test default state of cover loaded from config
cover_initial = hass.states.get(DOMAIN + ".test")
cover_initial = hass.states.get(f"{DOMAIN}.test")
assert cover_initial.state == STATE_CLOSED
assert cover_initial.attributes["assumed_state"]
@ -62,7 +62,7 @@ async def test_default_setup(hass, monkeypatch):
event_callback({"id": "protocol_0_0", "command": "up"})
await hass.async_block_till_done()
cover_after_first_command = hass.states.get(DOMAIN + ".test")
cover_after_first_command = hass.states.get(f"{DOMAIN}.test")
assert cover_after_first_command.state == STATE_OPEN
# not sure why, but cover have always assumed_state=true
assert cover_after_first_command.attributes.get("assumed_state")
@ -71,46 +71,46 @@ async def test_default_setup(hass, monkeypatch):
event_callback({"id": "protocol_0_0", "command": "down"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.test").state == STATE_CLOSED
# should respond to group command
event_callback({"id": "protocol_0_0", "command": "allon"})
await hass.async_block_till_done()
cover_after_first_command = hass.states.get(DOMAIN + ".test")
cover_after_first_command = hass.states.get(f"{DOMAIN}.test")
assert cover_after_first_command.state == STATE_OPEN
# should respond to group command
event_callback({"id": "protocol_0_0", "command": "alloff"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.test").state == STATE_CLOSED
# test following aliases
# mock incoming command event for this device alias
event_callback({"id": "test_alias_0_0", "command": "up"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
# test changing state from HA propagates to RFLink
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.test").state == STATE_CLOSED
assert protocol.send_command_ack.call_args_list[0][0][0] == "protocol_0_0"
assert protocol.send_command_ack.call_args_list[0][0][1] == "DOWN"
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
assert protocol.send_command_ack.call_args_list[1][0][1] == "UP"
@ -146,7 +146,7 @@ async def test_firing_bus_event(hass, monkeypatch):
await hass.async_block_till_done()
await hass.async_block_till_done()
assert calls[0].data == {"state": "down", "entity_id": DOMAIN + ".test"}
assert calls[0].data == {"state": "down", "entity_id": f"{DOMAIN}.test"}
async def test_signal_repetitions(hass, monkeypatch):
@ -169,7 +169,7 @@ async def test_signal_repetitions(hass, monkeypatch):
# test if signal repetition is performed according to configuration
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
@ -181,7 +181,7 @@ async def test_signal_repetitions(hass, monkeypatch):
# test if default apply to configured devices
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + ".test1"}
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
)
@ -209,12 +209,12 @@ async def test_signal_repetitions_alternation(hass, monkeypatch):
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + ".test1"}
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
)
@ -241,13 +241,13 @@ async def test_signal_repetitions_cancelling(hass, monkeypatch):
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
@ -274,19 +274,19 @@ async def test_group_alias(hass, monkeypatch):
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
assert hass.states.get(DOMAIN + ".test").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.test").state == STATE_CLOSED
# test sending group command to group alias
event_callback({"id": "test_group_0_0", "command": "allon"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
# test sending group command to group alias
event_callback({"id": "test_group_0_0", "command": "down"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
async def test_nogroup_alias(hass, monkeypatch):
@ -307,19 +307,19 @@ async def test_nogroup_alias(hass, monkeypatch):
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
assert hass.states.get(DOMAIN + ".test").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.test").state == STATE_CLOSED
# test sending group command to nogroup alias
event_callback({"id": "test_nogroup_0_0", "command": "allon"})
await hass.async_block_till_done()
# should not affect state
assert hass.states.get(DOMAIN + ".test").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.test").state == STATE_CLOSED
# test sending group command to nogroup alias
event_callback({"id": "test_nogroup_0_0", "command": "up"})
await hass.async_block_till_done()
# should affect state
assert hass.states.get(DOMAIN + ".test").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
async def test_nogroup_device_id(hass, monkeypatch):
@ -335,19 +335,19 @@ async def test_nogroup_device_id(hass, monkeypatch):
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
assert hass.states.get(DOMAIN + ".test").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.test").state == STATE_CLOSED
# test sending group command to nogroup
event_callback({"id": "test_nogroup_0_0", "command": "allon"})
await hass.async_block_till_done()
# should not affect state
assert hass.states.get(DOMAIN + ".test").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.test").state == STATE_CLOSED
# test sending group command to nogroup
event_callback({"id": "test_nogroup_0_0", "command": "up"})
await hass.async_block_till_done()
# should affect state
assert hass.states.get(DOMAIN + ".test").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
async def test_restore_state(hass, monkeypatch):
@ -366,7 +366,7 @@ async def test_restore_state(hass, monkeypatch):
}
mock_restore_cache(
hass, (State(DOMAIN + ".c1", STATE_OPEN), State(DOMAIN + ".c2", STATE_CLOSED))
hass, (State(f"{DOMAIN}.c1", STATE_OPEN), State(f"{DOMAIN}.c2", STATE_CLOSED))
)
hass.state = CoreState.starting
@ -374,20 +374,20 @@ async def test_restore_state(hass, monkeypatch):
# setup mocking rflink module
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
state = hass.states.get(DOMAIN + ".c1")
state = hass.states.get(f"{DOMAIN}.c1")
assert state
assert state.state == STATE_OPEN
state = hass.states.get(DOMAIN + ".c2")
state = hass.states.get(f"{DOMAIN}.c2")
assert state
assert state.state == STATE_CLOSED
state = hass.states.get(DOMAIN + ".c3")
state = hass.states.get(f"{DOMAIN}.c3")
assert state
assert state.state == STATE_CLOSED
# not cached cover must default values
state = hass.states.get(DOMAIN + ".c4")
state = hass.states.get(f"{DOMAIN}.c4")
assert state
assert state.state == STATE_CLOSED
assert state.attributes["assumed_state"]
@ -431,7 +431,7 @@ async def test_inverted_cover(hass, monkeypatch):
)
# test default state of cover loaded from config
standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_standard")
standard_cover = hass.states.get(f"{DOMAIN}.nonkaku_type_standard")
assert standard_cover.state == STATE_CLOSED
assert standard_cover.attributes["assumed_state"]
@ -439,7 +439,7 @@ async def test_inverted_cover(hass, monkeypatch):
event_callback({"id": "nonkaku_device_1", "command": "up"})
await hass.async_block_till_done()
standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_standard")
standard_cover = hass.states.get(f"{DOMAIN}.nonkaku_type_standard")
assert standard_cover.state == STATE_OPEN
assert standard_cover.attributes.get("assumed_state")
@ -447,7 +447,7 @@ async def test_inverted_cover(hass, monkeypatch):
event_callback({"id": "nonkaku_device_2", "command": "up"})
await hass.async_block_till_done()
standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_none")
standard_cover = hass.states.get(f"{DOMAIN}.nonkaku_type_none")
assert standard_cover.state == STATE_OPEN
assert standard_cover.attributes.get("assumed_state")
@ -456,7 +456,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".nonkaku_type_inverted")
inverted_cover = hass.states.get(f"{DOMAIN}.nonkaku_type_inverted")
assert inverted_cover.state == STATE_OPEN
assert inverted_cover.attributes.get("assumed_state")
@ -465,7 +465,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_standard")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_standard")
assert inverted_cover.state == STATE_OPEN
assert inverted_cover.attributes.get("assumed_state")
@ -474,7 +474,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_none")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_none")
assert inverted_cover.state == STATE_OPEN
assert inverted_cover.attributes.get("assumed_state")
@ -483,7 +483,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_inverted")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_inverted")
assert inverted_cover.state == STATE_OPEN
assert inverted_cover.attributes.get("assumed_state")
@ -492,7 +492,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_standard")
standard_cover = hass.states.get(f"{DOMAIN}.nonkaku_type_standard")
assert standard_cover.state == STATE_CLOSED
assert standard_cover.attributes.get("assumed_state")
@ -501,7 +501,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
standard_cover = hass.states.get(DOMAIN + ".nonkaku_type_none")
standard_cover = hass.states.get(f"{DOMAIN}.nonkaku_type_none")
assert standard_cover.state == STATE_CLOSED
assert standard_cover.attributes.get("assumed_state")
@ -510,7 +510,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".nonkaku_type_inverted")
inverted_cover = hass.states.get(f"{DOMAIN}.nonkaku_type_inverted")
assert inverted_cover.state == STATE_CLOSED
assert inverted_cover.attributes.get("assumed_state")
@ -519,7 +519,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_standard")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_standard")
assert inverted_cover.state == STATE_CLOSED
assert inverted_cover.attributes.get("assumed_state")
@ -528,7 +528,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_none")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_none")
assert inverted_cover.state == STATE_CLOSED
assert inverted_cover.attributes.get("assumed_state")
@ -537,7 +537,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_inverted")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_inverted")
assert inverted_cover.state == STATE_CLOSED
assert inverted_cover.attributes.get("assumed_state")
@ -549,7 +549,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".nonkaku_type_inverted")
inverted_cover = hass.states.get(f"{DOMAIN}.nonkaku_type_inverted")
assert inverted_cover.state == STATE_CLOSED
# should respond to group command
@ -557,7 +557,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".nonkaku_type_inverted")
inverted_cover = hass.states.get(f"{DOMAIN}.nonkaku_type_inverted")
assert inverted_cover.state == STATE_OPEN
# should respond to group command
@ -565,7 +565,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_standard")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_standard")
assert inverted_cover.state == STATE_CLOSED
# should respond to group command
@ -573,7 +573,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_standard")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_standard")
assert inverted_cover.state == STATE_OPEN
# should respond to group command
@ -581,7 +581,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_none")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_none")
assert inverted_cover.state == STATE_CLOSED
# should respond to group command
@ -589,7 +589,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_none")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_none")
assert inverted_cover.state == STATE_OPEN
# should respond to group command
@ -597,7 +597,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_inverted")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_inverted")
assert inverted_cover.state == STATE_CLOSED
# should respond to group command
@ -605,7 +605,7 @@ async def test_inverted_cover(hass, monkeypatch):
await hass.async_block_till_done()
inverted_cover = hass.states.get(DOMAIN + ".newkaku_type_inverted")
inverted_cover = hass.states.get(f"{DOMAIN}.newkaku_type_inverted")
assert inverted_cover.state == STATE_OPEN
# Sending the close command from HA should result
@ -615,13 +615,13 @@ async def test_inverted_cover(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_standard"},
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_standard"},
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".nonkaku_type_standard").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.nonkaku_type_standard").state == STATE_CLOSED
assert protocol.send_command_ack.call_args_list[0][0][0] == "nonkaku_device_1"
assert protocol.send_command_ack.call_args_list[0][0][1] == "DOWN"
@ -632,13 +632,13 @@ async def test_inverted_cover(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_standard"},
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_standard"},
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".nonkaku_type_standard").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.nonkaku_type_standard").state == STATE_OPEN
assert protocol.send_command_ack.call_args_list[1][0][0] == "nonkaku_device_1"
assert protocol.send_command_ack.call_args_list[1][0][1] == "UP"
@ -647,13 +647,13 @@ async def test_inverted_cover(hass, monkeypatch):
# that has its type not specified.
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_none"}
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_none"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".nonkaku_type_none").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.nonkaku_type_none").state == STATE_CLOSED
assert protocol.send_command_ack.call_args_list[2][0][0] == "nonkaku_device_2"
assert protocol.send_command_ack.call_args_list[2][0][1] == "DOWN"
@ -662,13 +662,13 @@ async def test_inverted_cover(hass, monkeypatch):
# that has its type not specified.
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_none"}
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_none"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".nonkaku_type_none").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.nonkaku_type_none").state == STATE_OPEN
assert protocol.send_command_ack.call_args_list[3][0][0] == "nonkaku_device_2"
assert protocol.send_command_ack.call_args_list[3][0][1] == "UP"
@ -679,13 +679,13 @@ async def test_inverted_cover(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_inverted"},
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_inverted"},
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".nonkaku_type_inverted").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.nonkaku_type_inverted").state == STATE_CLOSED
assert protocol.send_command_ack.call_args_list[4][0][0] == "nonkaku_device_3"
assert protocol.send_command_ack.call_args_list[4][0][1] == "UP"
@ -696,13 +696,13 @@ async def test_inverted_cover(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: DOMAIN + ".nonkaku_type_inverted"},
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_inverted"},
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".nonkaku_type_inverted").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.nonkaku_type_inverted").state == STATE_OPEN
assert protocol.send_command_ack.call_args_list[5][0][0] == "nonkaku_device_3"
assert protocol.send_command_ack.call_args_list[5][0][1] == "DOWN"
@ -713,13 +713,13 @@ async def test_inverted_cover(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_standard"},
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_standard"},
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".newkaku_type_standard").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.newkaku_type_standard").state == STATE_CLOSED
assert protocol.send_command_ack.call_args_list[6][0][0] == "newkaku_device_4"
assert protocol.send_command_ack.call_args_list[6][0][1] == "DOWN"
@ -730,13 +730,13 @@ async def test_inverted_cover(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_standard"},
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_standard"},
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".newkaku_type_standard").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.newkaku_type_standard").state == STATE_OPEN
assert protocol.send_command_ack.call_args_list[7][0][0] == "newkaku_device_4"
assert protocol.send_command_ack.call_args_list[7][0][1] == "UP"
@ -745,13 +745,13 @@ async def test_inverted_cover(hass, monkeypatch):
# that has its type not specified.
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_none"}
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_none"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".newkaku_type_none").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.newkaku_type_none").state == STATE_CLOSED
assert protocol.send_command_ack.call_args_list[8][0][0] == "newkaku_device_5"
assert protocol.send_command_ack.call_args_list[8][0][1] == "UP"
@ -760,13 +760,13 @@ async def test_inverted_cover(hass, monkeypatch):
# that has its type not specified.
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_none"}
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_none"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".newkaku_type_none").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.newkaku_type_none").state == STATE_OPEN
assert protocol.send_command_ack.call_args_list[9][0][0] == "newkaku_device_5"
assert protocol.send_command_ack.call_args_list[9][0][1] == "DOWN"
@ -777,13 +777,13 @@ async def test_inverted_cover(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_inverted"},
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_inverted"},
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".newkaku_type_inverted").state == STATE_CLOSED
assert hass.states.get(f"{DOMAIN}.newkaku_type_inverted").state == STATE_CLOSED
assert protocol.send_command_ack.call_args_list[10][0][0] == "newkaku_device_6"
assert protocol.send_command_ack.call_args_list[10][0][1] == "UP"
@ -794,12 +794,12 @@ async def test_inverted_cover(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: DOMAIN + ".newkaku_type_inverted"},
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_inverted"},
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".newkaku_type_inverted").state == STATE_OPEN
assert hass.states.get(f"{DOMAIN}.newkaku_type_inverted").state == STATE_OPEN
assert protocol.send_command_ack.call_args_list[11][0][0] == "newkaku_device_6"
assert protocol.send_command_ack.call_args_list[11][0][1] == "DOWN"

View File

@ -315,7 +315,7 @@ async def test_race_condition(hass, monkeypatch):
await hass.async_block_till_done()
# 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 == "off"
@ -325,7 +325,7 @@ async def test_race_condition(hass, monkeypatch):
assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_COMMAND]["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 == "on"

View File

@ -47,7 +47,7 @@ async def test_default_setup(hass, monkeypatch):
assert create.call_args_list[0][1]["ignore"]
# test default state of light loaded from config
light_initial = hass.states.get(DOMAIN + ".test")
light_initial = hass.states.get(f"{DOMAIN}.test")
assert light_initial.state == "off"
assert light_initial.attributes["assumed_state"]
@ -58,7 +58,7 @@ async def test_default_setup(hass, monkeypatch):
event_callback({"id": "protocol_0_0", "command": "on"})
await hass.async_block_till_done()
light_after_first_command = hass.states.get(DOMAIN + ".test")
light_after_first_command = hass.states.get(f"{DOMAIN}.test")
assert light_after_first_command.state == "on"
# also after receiving first command state not longer has to be assumed
assert not light_after_first_command.attributes.get("assumed_state")
@ -67,52 +67,52 @@ async def test_default_setup(hass, monkeypatch):
event_callback({"id": "protocol_0_0", "command": "off"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# should respond to group command
event_callback({"id": "protocol_0_0", "command": "allon"})
await hass.async_block_till_done()
light_after_first_command = hass.states.get(DOMAIN + ".test")
light_after_first_command = hass.states.get(f"{DOMAIN}.test")
assert light_after_first_command.state == "on"
# should respond to group command
event_callback({"id": "protocol_0_0", "command": "alloff"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test following aliases
# mock incoming command event for this device alias
event_callback({"id": "test_alias_0_0", "command": "on"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
# test event for new unconfigured sensor
event_callback({"id": "protocol2_0_1", "command": "on"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".protocol2_0_1").state == "on"
assert hass.states.get(f"{DOMAIN}.protocol2_0_1").state == "on"
# test changing state from HA propagates to RFLink
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
assert protocol.send_command_ack.call_args_list[0][0][0] == "protocol_0_0"
assert protocol.send_command_ack.call_args_list[0][0][1] == "off"
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
assert protocol.send_command_ack.call_args_list[1][0][1] == "on"
# protocols supporting dimming and on/off should create hybrid light entity
@ -120,7 +120,7 @@ async def test_default_setup(hass, monkeypatch):
await hass.async_block_till_done()
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: DOMAIN + ".newkaku_0_1"}
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_0_1"}
)
)
await hass.async_block_till_done()
@ -135,7 +135,7 @@ async def test_default_setup(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: DOMAIN + ".newkaku_0_1", ATTR_BRIGHTNESS: 128},
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_0_1", ATTR_BRIGHTNESS: 128},
)
)
await hass.async_block_till_done()
@ -146,7 +146,7 @@ async def test_default_setup(hass, monkeypatch):
hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: DOMAIN + ".dim_test", ATTR_BRIGHTNESS: 128},
{ATTR_ENTITY_ID: f"{DOMAIN}.dim_test", ATTR_BRIGHTNESS: 128},
)
)
await hass.async_block_till_done()
@ -186,7 +186,7 @@ async def test_firing_bus_event(hass, monkeypatch):
await hass.async_block_till_done()
await hass.async_block_till_done()
assert calls[0].data == {"state": "off", "entity_id": DOMAIN + ".test"}
assert calls[0].data == {"state": "off", "entity_id": f"{DOMAIN}.test"}
async def test_signal_repetitions(hass, monkeypatch):
@ -212,7 +212,7 @@ async def test_signal_repetitions(hass, monkeypatch):
# test if signal repetition is performed according to configuration
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
@ -224,7 +224,7 @@ async def test_signal_repetitions(hass, monkeypatch):
# test if default apply to configured devices
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: DOMAIN + ".test1"}
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
)
@ -241,7 +241,7 @@ async def test_signal_repetitions(hass, monkeypatch):
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: DOMAIN + ".protocol_0_2"}
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.protocol_0_2"}
)
)
@ -268,10 +268,10 @@ async def test_signal_repetitions_alternation(hass, monkeypatch):
_, _, protocol, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: DOMAIN + ".test1"}
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
await hass.async_block_till_done()
@ -296,11 +296,11 @@ async def test_signal_repetitions_cancelling(hass, monkeypatch):
_, _, protocol, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: DOMAIN + ".test"}, blocking=True
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}, blocking=True
)
assert [call[0][1] for call in protocol.send_command_ack.call_args_list] == [
@ -325,39 +325,39 @@ async def test_type_toggle(hass, monkeypatch):
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
# default value = 'off'
assert hass.states.get(DOMAIN + ".toggle_test").state == "off"
assert hass.states.get(f"{DOMAIN}.toggle_test").state == "off"
# test sending 'on' command, must set state = 'on'
event_callback({"id": "toggle_0_0", "command": "on"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".toggle_test").state == "on"
assert hass.states.get(f"{DOMAIN}.toggle_test").state == "on"
# test sending 'on' command again, must set state = 'off'
event_callback({"id": "toggle_0_0", "command": "on"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".toggle_test").state == "off"
assert hass.states.get(f"{DOMAIN}.toggle_test").state == "off"
# test async_turn_off, must set state = 'on' ('off' + toggle)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: DOMAIN + ".toggle_test"}
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.toggle_test"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".toggle_test").state == "on"
assert hass.states.get(f"{DOMAIN}.toggle_test").state == "on"
# test async_turn_on, must set state = 'off' (yes, sounds crazy)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: DOMAIN + ".toggle_test"}
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.toggle_test"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".toggle_test").state == "off"
assert hass.states.get(f"{DOMAIN}.toggle_test").state == "off"
async def test_group_alias(hass, monkeypatch):
@ -375,19 +375,19 @@ async def test_group_alias(hass, monkeypatch):
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to group alias
event_callback({"id": "test_group_0_0", "command": "allon"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
# test sending group command to group alias
event_callback({"id": "test_group_0_0", "command": "off"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
async def test_nogroup_alias(hass, monkeypatch):
@ -408,19 +408,19 @@ async def test_nogroup_alias(hass, monkeypatch):
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to nogroup alias
event_callback({"id": "test_nogroup_0_0", "command": "allon"})
await hass.async_block_till_done()
# should not affect state
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to nogroup alias
event_callback({"id": "test_nogroup_0_0", "command": "on"})
await hass.async_block_till_done()
# should affect state
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
async def test_nogroup_device_id(hass, monkeypatch):
@ -436,19 +436,19 @@ async def test_nogroup_device_id(hass, monkeypatch):
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to nogroup
event_callback({"id": "test_nogroup_0_0", "command": "allon"})
await hass.async_block_till_done()
# should not affect state
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to nogroup
event_callback({"id": "test_nogroup_0_0", "command": "on"})
await hass.async_block_till_done()
# should affect state
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
async def test_disable_automatic_add(hass, monkeypatch):
@ -466,7 +466,7 @@ async def test_disable_automatic_add(hass, monkeypatch):
await hass.async_block_till_done()
# make sure new device is not added
assert not hass.states.get(DOMAIN + ".protocol_0_0")
assert not hass.states.get(f"{DOMAIN}.protocol_0_0")
async def test_restore_state(hass, monkeypatch):
@ -488,10 +488,10 @@ async def test_restore_state(hass, monkeypatch):
mock_restore_cache(
hass,
(
State(DOMAIN + ".l1", STATE_ON, {ATTR_BRIGHTNESS: "123"}),
State(DOMAIN + ".l2", STATE_ON, {ATTR_BRIGHTNESS: "321"}),
State(DOMAIN + ".l3", STATE_OFF),
State(DOMAIN + ".l5", STATE_ON, {ATTR_BRIGHTNESS: "222"}),
State(f"{DOMAIN}.l1", STATE_ON, {ATTR_BRIGHTNESS: "123"}),
State(f"{DOMAIN}.l2", STATE_ON, {ATTR_BRIGHTNESS: "321"}),
State(f"{DOMAIN}.l3", STATE_OFF),
State(f"{DOMAIN}.l5", STATE_ON, {ATTR_BRIGHTNESS: "222"}),
),
)
@ -501,31 +501,31 @@ async def test_restore_state(hass, monkeypatch):
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
# hybrid light must restore brightness
state = hass.states.get(DOMAIN + ".l1")
state = hass.states.get(f"{DOMAIN}.l1")
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_BRIGHTNESS] == 123
# normal light do NOT must restore brightness
state = hass.states.get(DOMAIN + ".l2")
state = hass.states.get(f"{DOMAIN}.l2")
assert state
assert state.state == STATE_ON
assert not state.attributes.get(ATTR_BRIGHTNESS)
# OFF state also restores (or not)
state = hass.states.get(DOMAIN + ".l3")
state = hass.states.get(f"{DOMAIN}.l3")
assert state
assert state.state == STATE_OFF
# not cached light must default values
state = hass.states.get(DOMAIN + ".l4")
state = hass.states.get(f"{DOMAIN}.l4")
assert state
assert state.state == STATE_OFF
assert state.attributes[ATTR_BRIGHTNESS] == 255
assert state.attributes["assumed_state"]
# test coverage for dimmable light
state = hass.states.get(DOMAIN + ".l5")
state = hass.states.get(f"{DOMAIN}.l5")
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_BRIGHTNESS] == 222

View File

@ -78,21 +78,21 @@ async def test_default_setup(hass, monkeypatch):
# test changing state from HA propagates to Rflink
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
assert protocol.send_command_ack.call_args_list[0][0][0] == "protocol_0_0"
assert protocol.send_command_ack.call_args_list[0][0][1] == "off"
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: DOMAIN + ".test"}
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
assert protocol.send_command_ack.call_args_list[1][0][1] == "on"
@ -111,19 +111,19 @@ async def test_group_alias(hass, monkeypatch):
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to group alias
event_callback({"id": "test_group_0_0", "command": "allon"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
# test sending group command to group alias
event_callback({"id": "test_group_0_0", "command": "off"})
await hass.async_block_till_done()
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
async def test_nogroup_alias(hass, monkeypatch):
@ -144,19 +144,19 @@ async def test_nogroup_alias(hass, monkeypatch):
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to nogroup alias
event_callback({"id": "test_nogroup_0_0", "command": "allon"})
await hass.async_block_till_done()
# should not affect state
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to nogroup alias
event_callback({"id": "test_nogroup_0_0", "command": "on"})
await hass.async_block_till_done()
# should affect state
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
async def test_nogroup_device_id(hass, monkeypatch):
@ -172,19 +172,19 @@ async def test_nogroup_device_id(hass, monkeypatch):
# setup mocking rflink module
event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to nogroup
event_callback({"id": "test_nogroup_0_0", "command": "allon"})
await hass.async_block_till_done()
# should not affect state
assert hass.states.get(DOMAIN + ".test").state == "off"
assert hass.states.get(f"{DOMAIN}.test").state == "off"
# test sending group command to nogroup
event_callback({"id": "test_nogroup_0_0", "command": "on"})
await hass.async_block_till_done()
# should affect state
assert hass.states.get(DOMAIN + ".test").state == "on"
assert hass.states.get(f"{DOMAIN}.test").state == "on"
async def test_device_defaults(hass, monkeypatch):
@ -216,7 +216,7 @@ async def test_device_defaults(hass, monkeypatch):
await hass.async_block_till_done()
await hass.async_block_till_done()
assert calls[0].data == {"state": "off", "entity_id": DOMAIN + ".test"}
assert calls[0].data == {"state": "off", "entity_id": f"{DOMAIN}.test"}
async def test_not_firing_default(hass, monkeypatch):
@ -264,7 +264,7 @@ async def test_restore_state(hass, monkeypatch):
}
mock_restore_cache(
hass, (State(DOMAIN + ".s1", STATE_ON), State(DOMAIN + ".s2", STATE_OFF))
hass, (State(f"{DOMAIN}.s1", STATE_ON), State(f"{DOMAIN}.s2", STATE_OFF))
)
hass.state = CoreState.starting
@ -272,16 +272,16 @@ async def test_restore_state(hass, monkeypatch):
# setup mocking rflink module
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
state = hass.states.get(DOMAIN + ".s1")
state = hass.states.get(f"{DOMAIN}.s1")
assert state
assert state.state == STATE_ON
state = hass.states.get(DOMAIN + ".s2")
state = hass.states.get(f"{DOMAIN}.s2")
assert state
assert state.state == STATE_OFF
# not cached switch must default values
state = hass.states.get(DOMAIN + ".s3")
state = hass.states.get(f"{DOMAIN}.s3")
assert state
assert state.state == STATE_OFF
assert state.attributes["assumed_state"]

View File

@ -39,7 +39,7 @@ async def test_entity_state(hass, device_factory):
state = hass.states.get("sensor.sensor_1_battery")
assert state.state == "100"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UNIT_PERCENTAGE
assert state.attributes[ATTR_FRIENDLY_NAME] == device.label + " Battery"
assert state.attributes[ATTR_FRIENDLY_NAME] == f"{device.label} Battery"
async def test_entity_three_axis_state(hass, device_factory):
@ -50,13 +50,13 @@ async def test_entity_three_axis_state(hass, device_factory):
await setup_platform(hass, SENSOR_DOMAIN, devices=[device])
state = hass.states.get("sensor.three_axis_x_coordinate")
assert state.state == "100"
assert state.attributes[ATTR_FRIENDLY_NAME] == device.label + " X Coordinate"
assert state.attributes[ATTR_FRIENDLY_NAME] == f"{device.label} X Coordinate"
state = hass.states.get("sensor.three_axis_y_coordinate")
assert state.state == "75"
assert state.attributes[ATTR_FRIENDLY_NAME] == device.label + " Y Coordinate"
assert state.attributes[ATTR_FRIENDLY_NAME] == f"{device.label} Y Coordinate"
state = hass.states.get("sensor.three_axis_z_coordinate")
assert state.state == "25"
assert state.attributes[ATTR_FRIENDLY_NAME] == device.label + " Z Coordinate"
assert state.attributes[ATTR_FRIENDLY_NAME] == f"{device.label} Z Coordinate"
async def test_entity_three_axis_invalid_state(hass, device_factory):
@ -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 == 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

View File

@ -199,7 +199,7 @@ async def test_upgrade_token(
with requests_mock.mock() as rqmck:
rqmck.get(
re.compile(AbstractWithingsApi.URL + "/v2/user?.*action=getdevice(&.*|$)"),
re.compile(f"{AbstractWithingsApi.URL}/v2/user?.*action=getdevice(&.*|$)"),
status_code=200,
json=WITHINGS_GET_DEVICE_RESPONSE_EMPTY,
)
@ -255,7 +255,7 @@ async def test_auth_failure(
with requests_mock.mock() as rqmck:
rqmck.get(
re.compile(AbstractWithingsApi.URL + "/v2/user?.*action=getdevice(&.*|$)"),
re.compile(f"{AbstractWithingsApi.URL}/v2/user?.*action=getdevice(&.*|$)"),
status_code=200,
json={"status": 401, "body": {}},
)