deCONZ - Add support for new switch type (#31362)

This commit is contained in:
Robert Svensson 2020-02-01 17:08:49 +01:00 committed by Paulus Schoutsen
parent 11fcb2cc7f
commit 59a9ca71ce
4 changed files with 35 additions and 8 deletions

View File

@ -47,7 +47,7 @@ DAMPERS = ["Level controllable output"]
WINDOW_COVERS = ["Window covering device"] WINDOW_COVERS = ["Window covering device"]
COVER_TYPES = DAMPERS + WINDOW_COVERS COVER_TYPES = DAMPERS + WINDOW_COVERS
POWER_PLUGS = ["On/Off plug-in unit", "Smart plug"] POWER_PLUGS = ["On/Off light", "On/Off plug-in unit", "Smart plug"]
SIRENS = ["Warning device"] SIRENS = ["Warning device"]
SWITCH_TYPES = POWER_PLUGS + SIRENS SWITCH_TYPES = POWER_PLUGS + SIRENS

View File

@ -90,7 +90,10 @@ class DeconzLight(DeconzDevice, Light):
"""Set up light.""" """Set up light."""
super().__init__(device, gateway) super().__init__(device, gateway)
self._features = SUPPORT_BRIGHTNESS self._features = 0
if self._device.brightness is not None:
self._features |= SUPPORT_BRIGHTNESS
self._features |= SUPPORT_FLASH self._features |= SUPPORT_FLASH
self._features |= SUPPORT_TRANSITION self._features |= SUPPORT_TRANSITION

View File

@ -59,6 +59,12 @@ LIGHTS = {
"state": {"reachable": True}, "state": {"reachable": True},
"uniqueid": "00:00:00:00:00:00:00:02-00", "uniqueid": "00:00:00:00:00:00:00:02-00",
}, },
"4": {
"name": "On off light",
"state": {"on": True, "reachable": True},
"type": "On and Off light",
"uniqueid": "00:00:00:00:00:00:00:03-00",
},
} }
@ -91,18 +97,25 @@ async def test_lights_and_groups(hass):
assert "light.light_group" in gateway.deconz_ids assert "light.light_group" in gateway.deconz_ids
assert "light.empty_group" not in gateway.deconz_ids assert "light.empty_group" not in gateway.deconz_ids
assert "light.on_off_switch" not in gateway.deconz_ids assert "light.on_off_switch" not in gateway.deconz_ids
# 4 entities assert "light.on_off_light" in gateway.deconz_ids
assert len(hass.states.async_all()) == 4
assert len(hass.states.async_all()) == 5
rgb_light = hass.states.get("light.rgb_light") rgb_light = hass.states.get("light.rgb_light")
assert rgb_light.state == "on" assert rgb_light.state == "on"
assert rgb_light.attributes["brightness"] == 255 assert rgb_light.attributes["brightness"] == 255
assert rgb_light.attributes["hs_color"] == (224.235, 100.0) assert rgb_light.attributes["hs_color"] == (224.235, 100.0)
assert rgb_light.attributes["is_deconz_group"] is False assert rgb_light.attributes["is_deconz_group"] is False
assert rgb_light.attributes["supported_features"] == 61
tunable_white_light = hass.states.get("light.tunable_white_light") tunable_white_light = hass.states.get("light.tunable_white_light")
assert tunable_white_light.state == "on" assert tunable_white_light.state == "on"
assert tunable_white_light.attributes["color_temp"] == 2500 assert tunable_white_light.attributes["color_temp"] == 2500
assert tunable_white_light.attributes["supported_features"] == 2
on_off_light = hass.states.get("light.on_off_light")
assert on_off_light.state == "on"
assert on_off_light.attributes["supported_features"] == 0
light_group = hass.states.get("light.light_group") light_group = hass.states.get("light.light_group")
assert light_group.state == "on" assert light_group.state == "on"
@ -219,7 +232,7 @@ async def test_disable_light_groups(hass):
assert "light.empty_group" not in gateway.deconz_ids assert "light.empty_group" not in gateway.deconz_ids
assert "light.on_off_switch" not in gateway.deconz_ids assert "light.on_off_switch" not in gateway.deconz_ids
# 3 entities # 3 entities
assert len(hass.states.async_all()) == 3 assert len(hass.states.async_all()) == 4
rgb_light = hass.states.get("light.rgb_light") rgb_light = hass.states.get("light.rgb_light")
assert rgb_light is not None assert rgb_light is not None

View File

@ -38,6 +38,13 @@ SWITCHES = {
"state": {"reachable": True}, "state": {"reachable": True},
"uniqueid": "00:00:00:00:00:00:00:03-00", "uniqueid": "00:00:00:00:00:00:00:03-00",
}, },
"5": {
"id": "On off relay id",
"name": "On off relay",
"state": {"on": True, "reachable": True},
"type": "On/Off light",
"uniqueid": "00:00:00:00:00:00:00:04-00",
},
} }
@ -68,7 +75,8 @@ async def test_switches(hass):
assert "switch.smart_plug" in gateway.deconz_ids assert "switch.smart_plug" in gateway.deconz_ids
assert "switch.warning_device" in gateway.deconz_ids assert "switch.warning_device" in gateway.deconz_ids
assert "switch.unsupported_switch" not in gateway.deconz_ids assert "switch.unsupported_switch" not in gateway.deconz_ids
assert len(hass.states.async_all()) == 4 assert "switch.on_off_relay" in gateway.deconz_ids
assert len(hass.states.async_all()) == 5
on_off_switch = hass.states.get("switch.on_off_switch") on_off_switch = hass.states.get("switch.on_off_switch")
assert on_off_switch.state == "on" assert on_off_switch.state == "on"
@ -79,6 +87,9 @@ async def test_switches(hass):
warning_device = hass.states.get("switch.warning_device") warning_device = hass.states.get("switch.warning_device")
assert warning_device.state == "on" assert warning_device.state == "on"
on_off_relay = hass.states.get("switch.on_off_relay")
assert on_off_relay.state == "on"
state_changed_event = { state_changed_event = {
"t": "event", "t": "event",
"e": "changed", "e": "changed",