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,25 +135,23 @@ 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", "manufacturername": "AXIS",
"manufacturername": "AXIS", "modelid": "Gear",
"modelid": "Gear", "name": "Covering device",
"name": "Covering device", "state": {
"state": { "bri": 0,
"bri": 0, "lift": 0,
"lift": 0, "on": False,
"on": False, "open": True,
"open": True, "reachable": True,
"reachable": True, "tilt": 0,
"tilt": 0, },
}, "swversion": "100-5.3.5.1122",
"swversion": "100-5.3.5.1122", "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",
}
} }
], ],
) )
@ -221,25 +214,23 @@ 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", "lastseen": "2022-08-14T14:22Z",
"lastseen": "2022-08-14T14:22Z", "manufacturername": "Keen Home Inc",
"manufacturername": "Keen Home Inc", "modelid": "SV01-410-MP-1.0",
"modelid": "SV01-410-MP-1.0", "name": "Vent",
"name": "Vent", "state": {
"state": { "alert": "none",
"alert": "none", "bri": 242,
"bri": 242, "on": False,
"on": False, "reachable": True,
"reachable": True, "sat": 10,
"sat": 10, },
}, "swversion": "0x00000012",
"swversion": "0x00000012", "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",
}
} }
], ],
) )

View File

@ -24,23 +24,21 @@ 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.", "modelid": "HDC52EastwindFan",
"modelid": "HDC52EastwindFan", "name": "Ceiling fan",
"name": "Ceiling fan", "state": {
"state": { "alert": "none",
"alert": "none", "bri": 254,
"bri": 254, "on": False,
"on": False, "reachable": True,
"reachable": True, "speed": 4,
"speed": 4, },
}, "swversion": "0000000F",
"swversion": "0000000F", "type": "Fan",
"type": "Fan", "uniqueid": "00:22:a3:00:00:27:8b:81-01",
"uniqueid": "00:22:a3:00:00:27:8b:81-01",
}
} }
], ],
) )
@ -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,33 +440,31 @@ async def test_lights(
"light_payload", "light_payload",
[ [
{ {
"0": { "colorcapabilities": 31,
"colorcapabilities": 31, "ctmax": 500,
"ctmax": 500, "ctmin": 153,
"ctmin": 153, "etag": "055485a82553e654f156d41c9301b7cf",
"etag": "055485a82553e654f156d41c9301b7cf", "hascolor": True,
"hascolor": True, "lastannounced": None,
"lastannounced": None, "lastseen": "2021-06-10T20:25Z",
"lastseen": "2021-06-10T20:25Z", "manufacturername": "Philips",
"manufacturername": "Philips", "modelid": "LLC020",
"modelid": "LLC020", "name": "Hue Go",
"name": "Hue Go", "state": {
"state": { "alert": "none",
"alert": "none", "bri": 254,
"bri": 254, "colormode": "ct",
"colormode": "ct", "ct": 375,
"ct": 375, "effect": "none",
"effect": "none", "hue": 8348,
"hue": 8348, "on": True,
"on": True, "reachable": True,
"reachable": True, "sat": 147,
"sat": 147, "xy": [0.462, 0.4111],
"xy": [0.462, 0.4111], },
}, "swversion": "5.127.1.26420",
"swversion": "5.127.1.26420", "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",
}
} }
], ],
) )
@ -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,34 +629,32 @@ 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, "etag": "055485a82553e654f156d41c9301b7cf",
"etag": "055485a82553e654f156d41c9301b7cf", "hascolor": True,
"hascolor": True, "lastannounced": None,
"lastannounced": None, "lastseen": "2021-06-10T20:25Z",
"lastseen": "2021-06-10T20:25Z", "manufacturername": "Philips",
"manufacturername": "Philips", "modelid": "LLC020",
"modelid": "LLC020", "name": "Hue Go",
"name": "Hue Go", "state": {
"state": { "alert": "none",
"alert": "none", "bri": 254,
"bri": 254, "colormode": "ct",
"colormode": "ct", "ct": 375,
"ct": 375, "effect": "none",
"effect": "none", "hue": 8348,
"hue": 8348, "on": input["light_on"],
"on": input["light_on"], "reachable": True,
"reachable": True, "sat": 147,
"sat": 147, "xy": [0.462, 0.4111],
"xy": [0.462, 0.4111], },
}, "swversion": "5.127.1.26420",
"swversion": "5.127.1.26420", "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()
@ -684,29 +676,27 @@ async def test_light_service_calls(
"light_payload", "light_payload",
[ [
{ {
"0": { "colorcapabilities": 0,
"colorcapabilities": 0, "ctmax": 65535,
"ctmax": 65535, "ctmin": 0,
"ctmin": 0, "etag": "9dd510cd474791481f189d2a68a3c7f1",
"etag": "9dd510cd474791481f189d2a68a3c7f1", "hascolor": True,
"hascolor": True, "lastannounced": "2020-12-17T17:44:38Z",
"lastannounced": "2020-12-17T17:44:38Z", "lastseen": "2021-01-11T18:36Z",
"lastseen": "2021-01-11T18:36Z", "manufacturername": "IKEA of Sweden",
"manufacturername": "IKEA of Sweden", "modelid": "TRADFRI bulb E27 WS opal 1000lm",
"modelid": "TRADFRI bulb E27 WS opal 1000lm", "name": "IKEA light",
"name": "IKEA light", "state": {
"state": { "alert": "none",
"alert": "none", "bri": 156,
"bri": 156, "colormode": "ct",
"colormode": "ct", "ct": 250,
"ct": 250, "on": True,
"on": True, "reachable": True,
"reachable": True, },
}, "swversion": "2.0.022",
"swversion": "2.0.022", "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",
}
} }
], ],
) )
@ -754,27 +744,25 @@ async def test_ikea_default_transition_time(
"light_payload", "light_payload",
[ [
{ {
"0": { "etag": "87a89542bf9b9d0aa8134919056844f8",
"etag": "87a89542bf9b9d0aa8134919056844f8", "hascolor": True,
"hascolor": True, "lastannounced": None,
"lastannounced": None, "lastseen": "2020-12-05T22:57Z",
"lastseen": "2020-12-05T22:57Z", "manufacturername": "_TZE200_s8gkrkxk",
"manufacturername": "_TZE200_s8gkrkxk", "modelid": "TS0601",
"modelid": "TS0601", "name": "LIDL xmas light",
"name": "LIDL xmas light", "state": {
"state": { "bri": 25,
"bri": 25, "colormode": "hs",
"colormode": "hs", "effect": "none",
"effect": "none", "hue": 53691,
"hue": 53691, "on": True,
"on": True, "reachable": True,
"reachable": True, "sat": 141,
"sat": 141, },
}, "swversion": None,
"swversion": None, "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",
}
} }
], ],
) )
@ -803,19 +791,17 @@ async def test_lidl_christmas_light(
"light_payload", "light_payload",
[ [
{ {
"0": { "etag": "26839cb118f5bf7ba1f2108256644010",
"etag": "26839cb118f5bf7ba1f2108256644010", "hascolor": False,
"hascolor": False, "lastannounced": None,
"lastannounced": None, "lastseen": "2020-11-22T11:27Z",
"lastseen": "2020-11-22T11:27Z", "manufacturername": "dresden elektronik",
"manufacturername": "dresden elektronik", "modelid": "ConBee II",
"modelid": "ConBee II", "name": "Configuration tool 1",
"name": "Configuration tool 1", "state": {"reachable": True},
"state": {"reachable": True}, "swversion": "0x264a0700",
"swversion": "0x264a0700", "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",
}
} }
], ],
) )
@ -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,47 +1447,45 @@ async def test_verify_group_supported_features(hass: HomeAssistant) -> None:
"light_payload", "light_payload",
[ [
{ {
"13": { "capabilities": {
"capabilities": { "alerts": [
"alerts": [ "none",
"none", "select",
"select", "lselect",
"lselect", "blink",
"blink", "breathe",
"breathe", "okay",
"okay", "channelchange",
"channelchange", "finish",
"finish", "stop",
"stop", ],
], "bri": {"min_dim_level": 5},
"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",
}, },
"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( await mock_websocket_data(
{ {
"id": "13", "id": "0",
"r": "lights", "r": "lights",
"state": { "state": {
"alert": "none", "alert": "none",

View File

@ -27,19 +27,17 @@ from tests.test_util.aiohttp import AiohttpClientMocker
"light_payload", "light_payload",
[ [
{ {
"1": { "etag": "5c2ec06cde4bd654aef3a555fcd8ad12",
"etag": "5c2ec06cde4bd654aef3a555fcd8ad12", "hascolor": False,
"hascolor": False, "lastannounced": None,
"lastannounced": None, "lastseen": "2020-08-22T15:29:03Z",
"lastseen": "2020-08-22T15:29:03Z", "manufacturername": "Danalock",
"manufacturername": "Danalock", "modelid": "V3-BTZB",
"modelid": "V3-BTZB", "name": "Door lock",
"name": "Door lock", "state": {"alert": "none", "on": False, "reachable": True},
"state": {"alert": "none", "on": False, "reachable": True}, "swversion": "19042019",
"swversion": "19042019", "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",
}
} }
], ],
) )
@ -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,12 +55,10 @@ 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",
}
} }
], ],
) )
@ -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,12 +84,10 @@ 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",
}
} }
], ],
) )
@ -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,12 +308,10 @@ 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",
}
} }
], ],
) )

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",
},
} }
], ],
) )