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("config", config_payload)
data.setdefault("groups", group_payload)
if "state" in light_payload:
light_payload = {"0": light_payload}
data.setdefault("lights", light_payload)
data.setdefault("sensors", sensor_payload)
@ -172,16 +174,13 @@ def fixture_group_data() -> dict[str, Any]:
@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]:
"""Light data."""
"""Light data.
Should be
- one light data payload {"state": ...}
- multiple lights {"1": ..., "2": ...}
"""
return {}

View File

@ -37,14 +37,14 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"light_payload",
[
{
"1": {
"0": {
"name": "Window covering device",
"type": "Window covering device",
"state": {"lift": 100, "open": False, "reachable": True},
"modelid": "lumi.curtain",
"uniqueid": "00:00:00:00:00:00:00:01-00",
},
"2": {
"1": {
"name": "Unsupported cover",
"type": "Not a cover",
"state": {"reachable": True},
@ -68,12 +68,7 @@ async def test_cover(
# Event signals cover is open
event_changed_light = {
"r": "lights",
"id": "1",
"state": {"lift": 0, "open": True},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data({"r": "lights", "state": {"lift": 0, "open": True}})
await hass.async_block_till_done()
cover = hass.states.get("cover.window_covering_device")
@ -82,7 +77,7 @@ async def test_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
@ -140,25 +135,23 @@ async def test_cover(
"light_payload",
[
{
"0": {
"etag": "87269755b9b3a046485fdae8d96b252c",
"lastannounced": None,
"lastseen": "2020-08-01T16:22:05Z",
"manufacturername": "AXIS",
"modelid": "Gear",
"name": "Covering device",
"state": {
"bri": 0,
"lift": 0,
"on": False,
"open": True,
"reachable": True,
"tilt": 0,
},
"swversion": "100-5.3.5.1122",
"type": "Window covering device",
"uniqueid": "00:24:46:00:00:12:34:56-01",
}
"etag": "87269755b9b3a046485fdae8d96b252c",
"lastannounced": None,
"lastseen": "2020-08-01T16:22:05Z",
"manufacturername": "AXIS",
"modelid": "Gear",
"name": "Covering device",
"state": {
"bri": 0,
"lift": 0,
"on": False,
"open": True,
"reachable": True,
"tilt": 0,
},
"swversion": "100-5.3.5.1122",
"type": "Window covering device",
"uniqueid": "00:24:46:00:00:12:34:56-01",
}
],
)
@ -221,25 +214,23 @@ async def test_tilt_cover(
"light_payload",
[
{
"0": {
"etag": "4cefc909134c8e99086b55273c2bde67",
"hascolor": False,
"lastannounced": "2022-08-08T12:06:18Z",
"lastseen": "2022-08-14T14:22Z",
"manufacturername": "Keen Home Inc",
"modelid": "SV01-410-MP-1.0",
"name": "Vent",
"state": {
"alert": "none",
"bri": 242,
"on": False,
"reachable": True,
"sat": 10,
},
"swversion": "0x00000012",
"type": "Level controllable output",
"uniqueid": "00:22:a3:00:00:00:00:00-01",
}
"etag": "4cefc909134c8e99086b55273c2bde67",
"hascolor": False,
"lastannounced": "2022-08-08T12:06:18Z",
"lastseen": "2022-08-14T14:22Z",
"manufacturername": "Keen Home Inc",
"modelid": "SV01-410-MP-1.0",
"name": "Vent",
"state": {
"alert": "none",
"bri": 242,
"on": False,
"reachable": True,
"sat": 10,
},
"swversion": "0x00000012",
"type": "Level controllable output",
"uniqueid": "00:22:a3:00:00:00:00:00-01",
}
],
)

View File

@ -24,23 +24,21 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"light_payload",
[
{
"1": {
"etag": "432f3de28965052961a99e3c5494daf4",
"hascolor": False,
"manufacturername": "King Of Fans, Inc.",
"modelid": "HDC52EastwindFan",
"name": "Ceiling fan",
"state": {
"alert": "none",
"bri": 254,
"on": False,
"reachable": True,
"speed": 4,
},
"swversion": "0000000F",
"type": "Fan",
"uniqueid": "00:22:a3:00:00:27:8b:81-01",
}
"etag": "432f3de28965052961a99e3c5494daf4",
"hascolor": False,
"manufacturername": "King Of Fans, Inc.",
"modelid": "HDC52EastwindFan",
"name": "Ceiling fan",
"state": {
"alert": "none",
"bri": 254,
"on": False,
"reachable": True,
"speed": 4,
},
"swversion": "0000000F",
"type": "Fan",
"uniqueid": "00:22:a3:00:00:27:8b:81-01",
}
],
)
@ -58,56 +56,31 @@ async def test_fans(
# Test states
event_changed_light = {
"r": "lights",
"id": "1",
"state": {"speed": 1},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data({"r": "lights", "state": {"speed": 1}})
await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON
assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 25
event_changed_light = {
"r": "lights",
"id": "1",
"state": {"speed": 2},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data({"r": "lights", "state": {"speed": 2}})
await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON
assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 50
event_changed_light = {
"r": "lights",
"id": "1",
"state": {"speed": 3},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data({"r": "lights", "state": {"speed": 3}})
await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON
assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 75
event_changed_light = {
"r": "lights",
"id": "1",
"state": {"speed": 4},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data({"r": "lights", "state": {"speed": 4}})
await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON
assert hass.states.get("fan.ceiling_fan").attributes[ATTR_PERCENTAGE] == 100
event_changed_light = {
"r": "lights",
"id": "1",
"state": {"speed": 0},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data({"r": "lights", "state": {"speed": 0}})
await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_OFF
@ -115,7 +88,7 @@ async def test_fans(
# 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
@ -199,12 +172,7 @@ async def test_fans(
# Events with an unsupported speed does not get converted
event_changed_light = {
"r": "lights",
"id": "1",
"state": {"speed": 5},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data({"r": "lights", "state": {"speed": 5}})
await hass.async_block_till_done()
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(
("light_0_payload", "expected"),
("light_payload", "expected"),
[
( # RGB light in color temp color mode
{
@ -440,33 +440,31 @@ async def test_lights(
"light_payload",
[
{
"0": {
"colorcapabilities": 31,
"ctmax": 500,
"ctmin": 153,
"etag": "055485a82553e654f156d41c9301b7cf",
"hascolor": True,
"lastannounced": None,
"lastseen": "2021-06-10T20:25Z",
"manufacturername": "Philips",
"modelid": "LLC020",
"name": "Hue Go",
"state": {
"alert": "none",
"bri": 254,
"colormode": "ct",
"ct": 375,
"effect": "none",
"hue": 8348,
"on": True,
"reachable": True,
"sat": 147,
"xy": [0.462, 0.4111],
},
"swversion": "5.127.1.26420",
"type": "Extended color light",
"uniqueid": "00:17:88:01:01:23:45:67-00",
}
"colorcapabilities": 31,
"ctmax": 500,
"ctmin": 153,
"etag": "055485a82553e654f156d41c9301b7cf",
"hascolor": True,
"lastannounced": None,
"lastseen": "2021-06-10T20:25Z",
"manufacturername": "Philips",
"modelid": "LLC020",
"name": "Hue Go",
"state": {
"alert": "none",
"bri": 254,
"colormode": "ct",
"ct": 375,
"effect": "none",
"hue": 8348,
"on": True,
"reachable": True,
"sat": 147,
"xy": [0.462, 0.4111],
},
"swversion": "5.127.1.26420",
"type": "Extended color light",
"uniqueid": "00:17:88:01:01:23:45:67-00",
}
],
)
@ -478,11 +476,7 @@ async def test_light_state_change(
"""Verify light can change state on websocket event."""
assert hass.states.get("light.hue_go").state == STATE_ON
event_changed_light = {
"r": "lights",
"state": {"on": False},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data({"r": "lights", "state": {"on": False}})
await hass.async_block_till_done()
assert hass.states.get("light.hue_go").state == STATE_OFF
@ -635,34 +629,32 @@ async def test_light_service_calls(
expected: dict[str, Any],
) -> None:
"""Verify light can change state on websocket event."""
light_payload |= {
"0": {
"colorcapabilities": 31,
"ctmax": 500,
"ctmin": 153,
"etag": "055485a82553e654f156d41c9301b7cf",
"hascolor": True,
"lastannounced": None,
"lastseen": "2021-06-10T20:25Z",
"manufacturername": "Philips",
"modelid": "LLC020",
"name": "Hue Go",
"state": {
"alert": "none",
"bri": 254,
"colormode": "ct",
"ct": 375,
"effect": "none",
"hue": 8348,
"on": input["light_on"],
"reachable": True,
"sat": 147,
"xy": [0.462, 0.4111],
},
"swversion": "5.127.1.26420",
"type": "Extended color light",
"uniqueid": "00:17:88:01:01:23:45:67-00",
}
light_payload[0] = {
"colorcapabilities": 31,
"ctmax": 500,
"ctmin": 153,
"etag": "055485a82553e654f156d41c9301b7cf",
"hascolor": True,
"lastannounced": None,
"lastseen": "2021-06-10T20:25Z",
"manufacturername": "Philips",
"modelid": "LLC020",
"name": "Hue Go",
"state": {
"alert": "none",
"bri": 254,
"colormode": "ct",
"ct": 375,
"effect": "none",
"hue": 8348,
"on": input["light_on"],
"reachable": True,
"sat": 147,
"xy": [0.462, 0.4111],
},
"swversion": "5.127.1.26420",
"type": "Extended color light",
"uniqueid": "00:17:88:01:01:23:45:67-00",
}
await config_entry_factory()
@ -684,29 +676,27 @@ async def test_light_service_calls(
"light_payload",
[
{
"0": {
"colorcapabilities": 0,
"ctmax": 65535,
"ctmin": 0,
"etag": "9dd510cd474791481f189d2a68a3c7f1",
"hascolor": True,
"lastannounced": "2020-12-17T17:44:38Z",
"lastseen": "2021-01-11T18:36Z",
"manufacturername": "IKEA of Sweden",
"modelid": "TRADFRI bulb E27 WS opal 1000lm",
"name": "IKEA light",
"state": {
"alert": "none",
"bri": 156,
"colormode": "ct",
"ct": 250,
"on": True,
"reachable": True,
},
"swversion": "2.0.022",
"type": "Color temperature light",
"uniqueid": "ec:1b:bd:ff:fe:ee:ed:dd-01",
}
"colorcapabilities": 0,
"ctmax": 65535,
"ctmin": 0,
"etag": "9dd510cd474791481f189d2a68a3c7f1",
"hascolor": True,
"lastannounced": "2020-12-17T17:44:38Z",
"lastseen": "2021-01-11T18:36Z",
"manufacturername": "IKEA of Sweden",
"modelid": "TRADFRI bulb E27 WS opal 1000lm",
"name": "IKEA light",
"state": {
"alert": "none",
"bri": 156,
"colormode": "ct",
"ct": 250,
"on": True,
"reachable": True,
},
"swversion": "2.0.022",
"type": "Color temperature light",
"uniqueid": "ec:1b:bd:ff:fe:ee:ed:dd-01",
}
],
)
@ -754,27 +744,25 @@ async def test_ikea_default_transition_time(
"light_payload",
[
{
"0": {
"etag": "87a89542bf9b9d0aa8134919056844f8",
"hascolor": True,
"lastannounced": None,
"lastseen": "2020-12-05T22:57Z",
"manufacturername": "_TZE200_s8gkrkxk",
"modelid": "TS0601",
"name": "LIDL xmas light",
"state": {
"bri": 25,
"colormode": "hs",
"effect": "none",
"hue": 53691,
"on": True,
"reachable": True,
"sat": 141,
},
"swversion": None,
"type": "Color dimmable light",
"uniqueid": "58:8e:81:ff:fe:db:7b:be-01",
}
"etag": "87a89542bf9b9d0aa8134919056844f8",
"hascolor": True,
"lastannounced": None,
"lastseen": "2020-12-05T22:57Z",
"manufacturername": "_TZE200_s8gkrkxk",
"modelid": "TS0601",
"name": "LIDL xmas light",
"state": {
"bri": 25,
"colormode": "hs",
"effect": "none",
"hue": 53691,
"on": True,
"reachable": True,
"sat": 141,
},
"swversion": None,
"type": "Color dimmable light",
"uniqueid": "58:8e:81:ff:fe:db:7b:be-01",
}
],
)
@ -803,19 +791,17 @@ async def test_lidl_christmas_light(
"light_payload",
[
{
"0": {
"etag": "26839cb118f5bf7ba1f2108256644010",
"hascolor": False,
"lastannounced": None,
"lastseen": "2020-11-22T11:27Z",
"manufacturername": "dresden elektronik",
"modelid": "ConBee II",
"name": "Configuration tool 1",
"state": {"reachable": True},
"swversion": "0x264a0700",
"type": "Configuration tool",
"uniqueid": "00:21:2e:ff:ff:05:a7:a3-01",
}
"etag": "26839cb118f5bf7ba1f2108256644010",
"hascolor": False,
"lastannounced": None,
"lastseen": "2020-11-22T11:27Z",
"manufacturername": "dresden elektronik",
"modelid": "ConBee II",
"name": "Configuration tool 1",
"state": {"reachable": True},
"swversion": "0x264a0700",
"type": "Configuration tool",
"uniqueid": "00:21:2e:ff:ff:05:a7:a3-01",
}
],
)
@ -1152,7 +1138,7 @@ async def test_empty_group(hass: HomeAssistant) -> None:
"state": {"all_on": False, "any_on": True},
"action": {},
"scenes": [],
"lights": ["1"],
"lights": ["0"],
},
"2": {
"id": "Empty group id",
@ -1170,14 +1156,12 @@ async def test_empty_group(hass: HomeAssistant) -> None:
"light_payload",
[
{
"1": {
"ctmax": 454,
"ctmin": 155,
"name": "Tunable white light",
"state": {"on": True, "colormode": "ct", "ct": 2500, "reachable": True},
"type": "Tunable white light",
"uniqueid": "00:00:00:00:00:00:00:01-00",
},
"ctmax": 454,
"ctmin": 155,
"name": "Tunable white light",
"state": {"on": True, "colormode": "ct", "ct": 2500, "reachable": True},
"type": "Tunable white light",
"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": [],
"etag": "4548e982c4cfff942f7af80958abb2a0",
"id": "43",
"lights": ["13"],
"lights": ["0"],
"name": "Opbergruimte",
"scenes": [
{
@ -1463,47 +1447,45 @@ async def test_verify_group_supported_features(hass: HomeAssistant) -> None:
"light_payload",
[
{
"13": {
"capabilities": {
"alerts": [
"none",
"select",
"lselect",
"blink",
"breathe",
"okay",
"channelchange",
"finish",
"stop",
],
"bri": {"min_dim_level": 5},
},
"config": {
"bri": {"execute_if_off": True, "startup": "previous"},
"groups": ["43"],
"on": {"startup": "previous"},
},
"etag": "ca0ed7763eca37f5e6b24f6d46f8a518",
"hascolor": False,
"lastannounced": None,
"lastseen": "2024-03-02T20:08Z",
"manufacturername": "Signify Netherlands B.V.",
"modelid": "LWA001",
"name": "Opbergruimte Lamp Plafond",
"productid": "Philips-LWA001-1-A19DLv5",
"productname": "Hue white lamp",
"state": {
"alert": "none",
"bri": 76,
"effect": "none",
"on": False,
"reachable": True,
},
"swconfigid": "87169548",
"swversion": "1.104.2",
"type": "Dimmable light",
"uniqueid": "00:17:88:01:08:11:22:33-01",
"capabilities": {
"alerts": [
"none",
"select",
"lselect",
"blink",
"breathe",
"okay",
"channelchange",
"finish",
"stop",
],
"bri": {"min_dim_level": 5},
},
"config": {
"bri": {"execute_if_off": True, "startup": "previous"},
"groups": ["43"],
"on": {"startup": "previous"},
},
"etag": "ca0ed7763eca37f5e6b24f6d46f8a518",
"hascolor": False,
"lastannounced": None,
"lastseen": "2024-03-02T20:08Z",
"manufacturername": "Signify Netherlands B.V.",
"modelid": "LWA001",
"name": "Opbergruimte Lamp Plafond",
"productid": "Philips-LWA001-1-A19DLv5",
"productname": "Hue white lamp",
"state": {
"alert": "none",
"bri": 76,
"effect": "none",
"on": False,
"reachable": True,
},
"swconfigid": "87169548",
"swversion": "1.104.2",
"type": "Dimmable light",
"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(
{
"id": "13",
"id": "0",
"r": "lights",
"state": {
"alert": "none",

View File

@ -27,19 +27,17 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"light_payload",
[
{
"1": {
"etag": "5c2ec06cde4bd654aef3a555fcd8ad12",
"hascolor": False,
"lastannounced": None,
"lastseen": "2020-08-22T15:29:03Z",
"manufacturername": "Danalock",
"modelid": "V3-BTZB",
"name": "Door lock",
"state": {"alert": "none", "on": False, "reachable": True},
"swversion": "19042019",
"type": "Door Lock",
"uniqueid": "00:00:00:00:00:00:00:00-00",
}
"etag": "5c2ec06cde4bd654aef3a555fcd8ad12",
"hascolor": False,
"lastannounced": None,
"lastseen": "2020-08-22T15:29:03Z",
"manufacturername": "Danalock",
"modelid": "V3-BTZB",
"name": "Door lock",
"state": {"alert": "none", "on": False, "reachable": True},
"swversion": "19042019",
"type": "Door Lock",
"uniqueid": "00:00:00:00:00:00:00:00-00",
}
],
)
@ -53,19 +51,14 @@ async def test_lock_from_light(
assert len(hass.states.async_all()) == 1
assert hass.states.get("lock.door_lock").state == STATE_UNLOCKED
event_changed_light = {
"r": "lights",
"id": "1",
"state": {"on": True},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data({"r": "lights", "state": {"on": True}})
await hass.async_block_till_done()
assert hass.states.get("lock.door_lock").state == STATE_LOCKED
# Verify service calls
aioclient_mock = mock_put_request("/lights/1/state")
aioclient_mock = mock_put_request("/lights/0/state")
# Service lock door
@ -137,12 +130,12 @@ async def test_lock_from_sensor(
assert len(hass.states.async_all()) == 2
assert hass.states.get("lock.door_lock").state == STATE_UNLOCKED
event_changed_light = {
event_changed_sensor = {
"r": "sensors",
"id": "1",
"state": {"lockstate": "locked"},
}
await mock_websocket_data(event_changed_light)
await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done()
assert hass.states.get("lock.door_lock").state == STATE_LOCKED

View File

@ -55,12 +55,10 @@ async def test_configure_service_with_field(
"light_payload",
[
{
"1": {
"name": "Test",
"state": {"reachable": True},
"type": "Light",
"uniqueid": "00:00:00:00:00:00:00:01-00",
}
"name": "Test",
"state": {"reachable": True},
"type": "Light",
"uniqueid": "00:00:00:00:00:00:00:01-00",
}
],
)
@ -74,7 +72,7 @@ async def test_configure_service_with_entity(
SERVICE_ENTITY: "light.test",
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(
DECONZ_DOMAIN, SERVICE_CONFIGURE_DEVICE, service_data=data, blocking=True
@ -86,12 +84,10 @@ async def test_configure_service_with_entity(
"light_payload",
[
{
"1": {
"name": "Test",
"state": {"reachable": True},
"type": "Light",
"uniqueid": "00:00:00:00:00:00:00:01-00",
}
"name": "Test",
"state": {"reachable": True},
"type": "Light",
"uniqueid": "00:00:00:00:00:00:00:01-00",
}
],
)
@ -106,7 +102,7 @@ async def test_configure_service_with_entity_and_field(
SERVICE_FIELD: "/state",
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(
DECONZ_DOMAIN, SERVICE_CONFIGURE_DEVICE, service_data=data, blocking=True
@ -312,12 +308,10 @@ async def test_service_refresh_devices_trigger_no_state_update(
"light_payload",
[
{
"1": {
"name": "Light 1 name",
"state": {"reachable": True},
"type": "Light",
"uniqueid": "00:00:00:00:00:00:00:01-00",
}
"name": "Light 0 name",
"state": {"reachable": True},
"type": "Light",
"uniqueid": "00:00:00:00:00:00:00:01-00",
}
],
)

View File

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

View File

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