Improve string formatting v7 (#33705)

This commit is contained in:
springstan authored and GitHub committed 2020-04-05 17:34:24 -05:00
1 parent 15f41c84f9
commit 67c3a4c970
7 files changed
+164 -164

No files matched your search

+48 -48
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