Improve fixture usage for light based deCONZ tests (#122209)

This commit is contained in:
Robert Svensson 2024-07-20 11:25:00 +02:00 committed by GitHub
parent 6f9e39cd3f
commit ecffae0b4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 268 additions and 362 deletions

View File

@ -119,6 +119,8 @@ def fixture_get_request(
data.setdefault("alarmsystems", alarm_system_payload) data.setdefault("alarmsystems", alarm_system_payload)
data.setdefault("config", config_payload) data.setdefault("config", config_payload)
data.setdefault("groups", group_payload) data.setdefault("groups", group_payload)
if "state" in light_payload:
light_payload = {"0": light_payload}
data.setdefault("lights", light_payload) data.setdefault("lights", light_payload)
data.setdefault("sensors", sensor_payload) data.setdefault("sensors", sensor_payload)
@ -172,16 +174,13 @@ def fixture_group_data() -> dict[str, Any]:
@pytest.fixture(name="light_payload") @pytest.fixture(name="light_payload")
def fixture_light_0_data(light_0_payload: dict[str, Any]) -> dict[str, Any]:
"""Light data."""
if light_0_payload:
return {"0": light_0_payload}
return {}
@pytest.fixture(name="light_0_payload")
def fixture_light_data() -> dict[str, Any]: def fixture_light_data() -> dict[str, Any]:
"""Light data.""" """Light data.
Should be
- one light data payload {"state": ...}
- multiple lights {"1": ..., "2": ...}
"""
return {} return {}

View File

@ -37,14 +37,14 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"light_payload", "light_payload",
[ [
{ {
"1": { "0": {
"name": "Window covering device", "name": "Window covering device",
"type": "Window covering device", "type": "Window covering device",
"state": {"lift": 100, "open": False, "reachable": True}, "state": {"lift": 100, "open": False, "reachable": True},
"modelid": "lumi.curtain", "modelid": "lumi.curtain",
"uniqueid": "00:00:00:00:00:00:00:01-00", "uniqueid": "00:00:00:00:00:00:00:01-00",
}, },
"2": { "1": {
"name": "Unsupported cover", "name": "Unsupported cover",
"type": "Not a cover", "type": "Not a cover",
"state": {"reachable": True}, "state": {"reachable": True},
@ -68,12 +68,7 @@ async def test_cover(
# Event signals cover is open # Event signals cover is open
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"lift": 0, "open": True}})
"r": "lights",
"id": "1",
"state": {"lift": 0, "open": True},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
cover = hass.states.get("cover.window_covering_device") cover = hass.states.get("cover.window_covering_device")
@ -82,7 +77,7 @@ async def test_cover(
# Verify service calls for cover # Verify service calls for cover
aioclient_mock = mock_put_request("/lights/1/state") aioclient_mock = mock_put_request("/lights/0/state")
# Service open cover # Service open cover
@ -140,7 +135,6 @@ async def test_cover(
"light_payload", "light_payload",
[ [
{ {
"0": {
"etag": "87269755b9b3a046485fdae8d96b252c", "etag": "87269755b9b3a046485fdae8d96b252c",
"lastannounced": None, "lastannounced": None,
"lastseen": "2020-08-01T16:22:05Z", "lastseen": "2020-08-01T16:22:05Z",
@ -159,7 +153,6 @@ async def test_cover(
"type": "Window covering device", "type": "Window covering device",
"uniqueid": "00:24:46:00:00:12:34:56-01", "uniqueid": "00:24:46:00:00:12:34:56-01",
} }
}
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
@ -221,7 +214,6 @@ async def test_tilt_cover(
"light_payload", "light_payload",
[ [
{ {
"0": {
"etag": "4cefc909134c8e99086b55273c2bde67", "etag": "4cefc909134c8e99086b55273c2bde67",
"hascolor": False, "hascolor": False,
"lastannounced": "2022-08-08T12:06:18Z", "lastannounced": "2022-08-08T12:06:18Z",
@ -240,7 +232,6 @@ async def test_tilt_cover(
"type": "Level controllable output", "type": "Level controllable output",
"uniqueid": "00:22:a3:00:00:00:00:00-01", "uniqueid": "00:22:a3:00:00:00:00:00-01",
} }
}
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")

View File

@ -24,7 +24,6 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"light_payload", "light_payload",
[ [
{ {
"1": {
"etag": "432f3de28965052961a99e3c5494daf4", "etag": "432f3de28965052961a99e3c5494daf4",
"hascolor": False, "hascolor": False,
"manufacturername": "King Of Fans, Inc.", "manufacturername": "King Of Fans, Inc.",
@ -41,7 +40,6 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"type": "Fan", "type": "Fan",
"uniqueid": "00:22:a3:00:00:27:8b:81-01", "uniqueid": "00:22:a3:00:00:27:8b:81-01",
} }
}
], ],
) )
async def test_fans( async def test_fans(
@ -58,56 +56,31 @@ async def test_fans(
# Test states # Test states
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"speed": 1}})
"r": "lights",
"id": "1",
"state": {"speed": 1},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON
assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 25 assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 25
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"speed": 2}})
"r": "lights",
"id": "1",
"state": {"speed": 2},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON
assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 50 assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 50
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"speed": 3}})
"r": "lights",
"id": "1",
"state": {"speed": 3},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON
assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 75 assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 75
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"speed": 4}})
"r": "lights",
"id": "1",
"state": {"speed": 4},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON
assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 100 assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 100
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"speed": 0}})
"r": "lights",
"id": "1",
"state": {"speed": 0},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_OFF assert hass.states.get("fan.ceiling_fan").state == STATE_OFF
@ -115,7 +88,7 @@ async def test_fans(
# Test service calls # Test service calls
aioclient_mock = mock_put_request("/lights/1/state") aioclient_mock = mock_put_request("/lights/0/state")
# Service turn on fan using saved default_on_speed # Service turn on fan using saved default_on_speed
@ -199,12 +172,7 @@ async def test_fans(
# Events with an unsupported speed does not get converted # Events with an unsupported speed does not get converted
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"speed": 5}})
"r": "lights",
"id": "1",
"state": {"speed": 5},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON

View File

@ -46,7 +46,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker
@pytest.mark.parametrize( @pytest.mark.parametrize(
("light_0_payload", "expected"), ("light_payload", "expected"),
[ [
( # RGB light in color temp color mode ( # RGB light in color temp color mode
{ {
@ -440,7 +440,6 @@ async def test_lights(
"light_payload", "light_payload",
[ [
{ {
"0": {
"colorcapabilities": 31, "colorcapabilities": 31,
"ctmax": 500, "ctmax": 500,
"ctmin": 153, "ctmin": 153,
@ -467,7 +466,6 @@ async def test_lights(
"type": "Extended color light", "type": "Extended color light",
"uniqueid": "00:17:88:01:01:23:45:67-00", "uniqueid": "00:17:88:01:01:23:45:67-00",
} }
}
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
@ -478,11 +476,7 @@ async def test_light_state_change(
"""Verify light can change state on websocket event.""" """Verify light can change state on websocket event."""
assert hass.states.get("light.hue_go").state == STATE_ON assert hass.states.get("light.hue_go").state == STATE_ON
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"on": False}})
"r": "lights",
"state": {"on": False},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("light.hue_go").state == STATE_OFF assert hass.states.get("light.hue_go").state == STATE_OFF
@ -635,8 +629,7 @@ async def test_light_service_calls(
expected: dict[str, Any], expected: dict[str, Any],
) -> None: ) -> None:
"""Verify light can change state on websocket event.""" """Verify light can change state on websocket event."""
light_payload |= { light_payload[0] = {
"0": {
"colorcapabilities": 31, "colorcapabilities": 31,
"ctmax": 500, "ctmax": 500,
"ctmin": 153, "ctmin": 153,
@ -663,7 +656,6 @@ async def test_light_service_calls(
"type": "Extended color light", "type": "Extended color light",
"uniqueid": "00:17:88:01:01:23:45:67-00", "uniqueid": "00:17:88:01:01:23:45:67-00",
} }
}
await config_entry_factory() await config_entry_factory()
aioclient_mock = mock_put_request("/lights/0/state") aioclient_mock = mock_put_request("/lights/0/state")
@ -684,7 +676,6 @@ async def test_light_service_calls(
"light_payload", "light_payload",
[ [
{ {
"0": {
"colorcapabilities": 0, "colorcapabilities": 0,
"ctmax": 65535, "ctmax": 65535,
"ctmin": 0, "ctmin": 0,
@ -707,7 +698,6 @@ async def test_light_service_calls(
"type": "Color temperature light", "type": "Color temperature light",
"uniqueid": "ec:1b:bd:ff:fe:ee:ed:dd-01", "uniqueid": "ec:1b:bd:ff:fe:ee:ed:dd-01",
} }
}
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
@ -754,7 +744,6 @@ async def test_ikea_default_transition_time(
"light_payload", "light_payload",
[ [
{ {
"0": {
"etag": "87a89542bf9b9d0aa8134919056844f8", "etag": "87a89542bf9b9d0aa8134919056844f8",
"hascolor": True, "hascolor": True,
"lastannounced": None, "lastannounced": None,
@ -775,7 +764,6 @@ async def test_ikea_default_transition_time(
"type": "Color dimmable light", "type": "Color dimmable light",
"uniqueid": "58:8e:81:ff:fe:db:7b:be-01", "uniqueid": "58:8e:81:ff:fe:db:7b:be-01",
} }
}
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
@ -803,7 +791,6 @@ async def test_lidl_christmas_light(
"light_payload", "light_payload",
[ [
{ {
"0": {
"etag": "26839cb118f5bf7ba1f2108256644010", "etag": "26839cb118f5bf7ba1f2108256644010",
"hascolor": False, "hascolor": False,
"lastannounced": None, "lastannounced": None,
@ -816,7 +803,6 @@ async def test_lidl_christmas_light(
"type": "Configuration tool", "type": "Configuration tool",
"uniqueid": "00:21:2e:ff:ff:05:a7:a3-01", "uniqueid": "00:21:2e:ff:ff:05:a7:a3-01",
} }
}
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
@ -1152,7 +1138,7 @@ async def test_empty_group(hass: HomeAssistant) -> None:
"state": {"all_on": False, "any_on": True}, "state": {"all_on": False, "any_on": True},
"action": {}, "action": {},
"scenes": [], "scenes": [],
"lights": ["1"], "lights": ["0"],
}, },
"2": { "2": {
"id": "Empty group id", "id": "Empty group id",
@ -1170,14 +1156,12 @@ async def test_empty_group(hass: HomeAssistant) -> None:
"light_payload", "light_payload",
[ [
{ {
"1": {
"ctmax": 454, "ctmax": 454,
"ctmin": 155, "ctmin": 155,
"name": "Tunable white light", "name": "Tunable white light",
"state": {"on": True, "colormode": "ct", "ct": 2500, "reachable": True}, "state": {"on": True, "colormode": "ct", "ct": 2500, "reachable": True},
"type": "Tunable white light", "type": "Tunable white light",
"uniqueid": "00:00:00:00:00:00:00:01-00", "uniqueid": "00:00:00:00:00:00:00:01-00",
},
} }
], ],
) )
@ -1425,7 +1409,7 @@ async def test_verify_group_supported_features(hass: HomeAssistant) -> None:
"devicemembership": [], "devicemembership": [],
"etag": "4548e982c4cfff942f7af80958abb2a0", "etag": "4548e982c4cfff942f7af80958abb2a0",
"id": "43", "id": "43",
"lights": ["13"], "lights": ["0"],
"name": "Opbergruimte", "name": "Opbergruimte",
"scenes": [ "scenes": [
{ {
@ -1463,7 +1447,6 @@ async def test_verify_group_supported_features(hass: HomeAssistant) -> None:
"light_payload", "light_payload",
[ [
{ {
"13": {
"capabilities": { "capabilities": {
"alerts": [ "alerts": [
"none", "none",
@ -1503,7 +1486,6 @@ async def test_verify_group_supported_features(hass: HomeAssistant) -> None:
"swversion": "1.104.2", "swversion": "1.104.2",
"type": "Dimmable light", "type": "Dimmable light",
"uniqueid": "00:17:88:01:08:11:22:33-01", "uniqueid": "00:17:88:01:08:11:22:33-01",
},
} }
], ],
) )
@ -1519,7 +1501,7 @@ async def test_verify_group_color_mode_fallback(
await mock_websocket_data( await mock_websocket_data(
{ {
"id": "13", "id": "0",
"r": "lights", "r": "lights",
"state": { "state": {
"alert": "none", "alert": "none",

View File

@ -27,7 +27,6 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"light_payload", "light_payload",
[ [
{ {
"1": {
"etag": "5c2ec06cde4bd654aef3a555fcd8ad12", "etag": "5c2ec06cde4bd654aef3a555fcd8ad12",
"hascolor": False, "hascolor": False,
"lastannounced": None, "lastannounced": None,
@ -40,7 +39,6 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"type": "Door Lock", "type": "Door Lock",
"uniqueid": "00:00:00:00:00:00:00:00-00", "uniqueid": "00:00:00:00:00:00:00:00-00",
} }
}
], ],
) )
async def test_lock_from_light( async def test_lock_from_light(
@ -53,19 +51,14 @@ async def test_lock_from_light(
assert len(hass.states.async_all()) == 1 assert len(hass.states.async_all()) == 1
assert hass.states.get("lock.door_lock").state == STATE_UNLOCKED assert hass.states.get("lock.door_lock").state == STATE_UNLOCKED
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"on": True}})
"r": "lights",
"id": "1",
"state": {"on": True},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("lock.door_lock").state == STATE_LOCKED assert hass.states.get("lock.door_lock").state == STATE_LOCKED
# Verify service calls # Verify service calls
aioclient_mock = mock_put_request("/lights/1/state") aioclient_mock = mock_put_request("/lights/0/state")
# Service lock door # Service lock door
@ -137,12 +130,12 @@ async def test_lock_from_sensor(
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
assert hass.states.get("lock.door_lock").state == STATE_UNLOCKED assert hass.states.get("lock.door_lock").state == STATE_UNLOCKED
event_changed_light = { event_changed_sensor = {
"r": "sensors", "r": "sensors",
"id": "1", "id": "1",
"state": {"lockstate": "locked"}, "state": {"lockstate": "locked"},
} }
await mock_websocket_data(event_changed_light) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("lock.door_lock").state == STATE_LOCKED assert hass.states.get("lock.door_lock").state == STATE_LOCKED

View File

@ -55,13 +55,11 @@ async def test_configure_service_with_field(
"light_payload", "light_payload",
[ [
{ {
"1": {
"name": "Test", "name": "Test",
"state": {"reachable": True}, "state": {"reachable": True},
"type": "Light", "type": "Light",
"uniqueid": "00:00:00:00:00:00:00:01-00", "uniqueid": "00:00:00:00:00:00:00:01-00",
} }
}
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
@ -74,7 +72,7 @@ async def test_configure_service_with_entity(
SERVICE_ENTITY: "light.test", SERVICE_ENTITY: "light.test",
SERVICE_DATA: {"on": True, "attr1": 10, "attr2": 20}, SERVICE_DATA: {"on": True, "attr1": 10, "attr2": 20},
} }
aioclient_mock = mock_put_request("/lights/1") aioclient_mock = mock_put_request("/lights/0")
await hass.services.async_call( await hass.services.async_call(
DECONZ_DOMAIN, SERVICE_CONFIGURE_DEVICE, service_data=data, blocking=True DECONZ_DOMAIN, SERVICE_CONFIGURE_DEVICE, service_data=data, blocking=True
@ -86,13 +84,11 @@ async def test_configure_service_with_entity(
"light_payload", "light_payload",
[ [
{ {
"1": {
"name": "Test", "name": "Test",
"state": {"reachable": True}, "state": {"reachable": True},
"type": "Light", "type": "Light",
"uniqueid": "00:00:00:00:00:00:00:01-00", "uniqueid": "00:00:00:00:00:00:00:01-00",
} }
}
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
@ -106,7 +102,7 @@ async def test_configure_service_with_entity_and_field(
SERVICE_FIELD: "/state", SERVICE_FIELD: "/state",
SERVICE_DATA: {"on": True, "attr1": 10, "attr2": 20}, SERVICE_DATA: {"on": True, "attr1": 10, "attr2": 20},
} }
aioclient_mock = mock_put_request("/lights/1/state") aioclient_mock = mock_put_request("/lights/0/state")
await hass.services.async_call( await hass.services.async_call(
DECONZ_DOMAIN, SERVICE_CONFIGURE_DEVICE, service_data=data, blocking=True DECONZ_DOMAIN, SERVICE_CONFIGURE_DEVICE, service_data=data, blocking=True
@ -312,13 +308,11 @@ async def test_service_refresh_devices_trigger_no_state_update(
"light_payload", "light_payload",
[ [
{ {
"1": { "name": "Light 0 name",
"name": "Light 1 name",
"state": {"reachable": True}, "state": {"reachable": True},
"type": "Light", "type": "Light",
"uniqueid": "00:00:00:00:00:00:00:01-00", "uniqueid": "00:00:00:00:00:00:00:01-00",
} }
}
], ],
) )
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -25,18 +25,10 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"light_payload", "light_payload",
[ [
{ {
"1": {
"name": "Warning device", "name": "Warning device",
"type": "Warning device", "type": "Warning device",
"state": {"alert": "lselect", "reachable": True}, "state": {"alert": "lselect", "reachable": True},
"uniqueid": "00:00:00:00:00:00:00:00-00", "uniqueid": "00:00:00:00:00:00:00:00-00",
},
"2": {
"name": "Unsupported siren",
"type": "Not a siren",
"state": {"reachable": True},
"uniqueid": "00:00:00:00:00:00:00:01-00",
},
} }
], ],
) )
@ -47,23 +39,17 @@ async def test_sirens(
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
) -> None: ) -> None:
"""Test that siren entities are created.""" """Test that siren entities are created."""
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 1
assert hass.states.get("siren.warning_device").state == STATE_ON assert hass.states.get("siren.warning_device").state == STATE_ON
assert not hass.states.get("siren.unsupported_siren")
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"alert": None}})
"r": "lights",
"id": "1",
"state": {"alert": None},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("siren.warning_device").state == STATE_OFF assert hass.states.get("siren.warning_device").state == STATE_OFF
# Verify service calls # Verify service calls
aioclient_mock = mock_put_request("/lights/1/state") aioclient_mock = mock_put_request("/lights/0/state")
# Service turn on siren # Service turn on siren
@ -98,7 +84,7 @@ async def test_sirens(
await hass.config_entries.async_unload(config_entry_setup.entry_id) await hass.config_entries.async_unload(config_entry_setup.entry_id)
states = hass.states.async_all() states = hass.states.async_all()
assert len(states) == 2 assert len(states) == 1
for state in states: for state in states:
assert state.state == STATE_UNAVAILABLE assert state.state == STATE_UNAVAILABLE

View File

@ -25,29 +25,29 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"light_payload", "light_payload",
[ [
{ {
"1": { "0": {
"name": "On off switch", "name": "On off switch",
"type": "On/Off plug-in unit", "type": "On/Off plug-in unit",
"state": {"on": True, "reachable": True}, "state": {"on": True, "reachable": True},
"uniqueid": "00:00:00:00:00:00:00:00-00", "uniqueid": "00:00:00:00:00:00:00:00-00",
}, },
"2": { "1": {
"name": "Smart plug", "name": "Smart plug",
"type": "Smart plug", "type": "Smart plug",
"state": {"on": False, "reachable": True}, "state": {"on": False, "reachable": True},
"uniqueid": "00:00:00:00:00:00:00:01-00", "uniqueid": "00:00:00:00:00:00:00:01-00",
}, },
"3": { "2": {
"name": "Unsupported switch", "name": "Unsupported switch",
"type": "Not a switch", "type": "Not a switch",
"state": {"reachable": True}, "state": {"reachable": True},
"uniqueid": "00:00:00:00:00:00:00:03-00", "uniqueid": "00:00:00:00:00:00:00:02-00",
}, },
"4": { "3": {
"name": "On off relay", "name": "On off relay",
"state": {"on": True, "reachable": True}, "state": {"on": True, "reachable": True},
"type": "On/Off light", "type": "On/Off light",
"uniqueid": "00:00:00:00:00:00:00:04-00", "uniqueid": "00:00:00:00:00:00:00:03-00",
}, },
} }
], ],
@ -65,19 +65,14 @@ async def test_power_plugs(
assert hass.states.get("switch.on_off_relay").state == STATE_ON assert hass.states.get("switch.on_off_relay").state == STATE_ON
assert hass.states.get("switch.unsupported_switch") is None assert hass.states.get("switch.unsupported_switch") is None
event_changed_light = { await mock_websocket_data({"r": "lights", "state": {"on": False}})
"r": "lights",
"id": "1",
"state": {"on": False},
}
await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("switch.on_off_switch").state == STATE_OFF assert hass.states.get("switch.on_off_switch").state == STATE_OFF
# Verify service calls # Verify service calls
aioclient_mock = mock_put_request("/lights/1/state") aioclient_mock = mock_put_request("/lights/0/state")
# Service turn on power plug # Service turn on power plug
@ -115,12 +110,10 @@ async def test_power_plugs(
"light_payload", "light_payload",
[ [
{ {
"1": {
"name": "On Off output device", "name": "On Off output device",
"type": "On/Off output", "type": "On/Off output",
"state": {"on": True, "reachable": True}, "state": {"on": True, "reachable": True},
"uniqueid": "00:00:00:00:00:00:00:00-00", "uniqueid": "00:00:00:00:00:00:00:00-00",
},
} }
], ],
) )