2018-04-23 16:00:16 +00:00
|
|
|
"""deCONZ light platform tests."""
|
2020-10-17 16:20:06 +00:00
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
from copy import deepcopy
|
|
|
|
|
2021-01-22 21:40:22 +00:00
|
|
|
import pytest
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
from homeassistant.components.deconz.const import CONF_ALLOW_DECONZ_GROUPS
|
2020-10-06 21:25:57 +00:00
|
|
|
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
|
2020-10-17 16:20:06 +00:00
|
|
|
from homeassistant.components.light import (
|
|
|
|
ATTR_BRIGHTNESS,
|
|
|
|
ATTR_COLOR_TEMP,
|
|
|
|
ATTR_EFFECT,
|
|
|
|
ATTR_FLASH,
|
|
|
|
ATTR_HS_COLOR,
|
|
|
|
ATTR_MAX_MIREDS,
|
|
|
|
ATTR_MIN_MIREDS,
|
|
|
|
ATTR_TRANSITION,
|
|
|
|
DOMAIN as LIGHT_DOMAIN,
|
|
|
|
EFFECT_COLORLOOP,
|
|
|
|
FLASH_LONG,
|
|
|
|
FLASH_SHORT,
|
|
|
|
SERVICE_TURN_OFF,
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
)
|
|
|
|
from homeassistant.const import (
|
|
|
|
ATTR_ENTITY_ID,
|
|
|
|
ATTR_SUPPORTED_FEATURES,
|
|
|
|
STATE_OFF,
|
|
|
|
STATE_ON,
|
2021-02-08 09:45:46 +00:00
|
|
|
STATE_UNAVAILABLE,
|
2020-10-17 16:20:06 +00:00
|
|
|
)
|
2018-04-23 16:00:16 +00:00
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
from .test_gateway import (
|
|
|
|
DECONZ_WEB_REQUEST,
|
|
|
|
mock_deconz_put_request,
|
|
|
|
setup_deconz_integration,
|
|
|
|
)
|
2019-09-19 21:44:09 +00:00
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
GROUPS = {
|
2018-04-23 16:00:16 +00:00
|
|
|
"1": {
|
2019-09-18 10:47:26 +00:00
|
|
|
"id": "Light group id",
|
|
|
|
"name": "Light group",
|
2018-10-31 21:38:04 +00:00
|
|
|
"type": "LightGroup",
|
2019-09-18 10:47:26 +00:00
|
|
|
"state": {"all_on": False, "any_on": True},
|
2018-04-23 16:00:16 +00:00
|
|
|
"action": {},
|
|
|
|
"scenes": [],
|
2019-07-31 19:25:30 +00:00
|
|
|
"lights": ["1", "2"],
|
2018-04-23 16:00:16 +00:00
|
|
|
},
|
|
|
|
"2": {
|
2019-09-18 10:47:26 +00:00
|
|
|
"id": "Empty group id",
|
|
|
|
"name": "Empty group",
|
|
|
|
"type": "LightGroup",
|
2018-04-23 16:00:16 +00:00
|
|
|
"state": {},
|
|
|
|
"action": {},
|
2019-02-18 16:43:22 +00:00
|
|
|
"scenes": [],
|
|
|
|
"lights": [],
|
2018-04-23 16:00:16 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
LIGHTS = {
|
2018-08-01 09:03:08 +00:00
|
|
|
"1": {
|
2019-09-18 10:47:26 +00:00
|
|
|
"id": "RGB light id",
|
|
|
|
"name": "RGB light",
|
|
|
|
"state": {
|
|
|
|
"on": True,
|
|
|
|
"bri": 255,
|
|
|
|
"colormode": "xy",
|
|
|
|
"effect": "colorloop",
|
|
|
|
"xy": (500, 500),
|
|
|
|
"reachable": True,
|
|
|
|
},
|
|
|
|
"type": "Extended color light",
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
|
|
|
},
|
|
|
|
"2": {
|
2020-06-01 21:48:18 +00:00
|
|
|
"ctmax": 454,
|
|
|
|
"ctmin": 155,
|
2019-09-18 10:47:26 +00:00
|
|
|
"id": "Tunable white light id",
|
|
|
|
"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",
|
|
|
|
},
|
|
|
|
"3": {
|
|
|
|
"id": "On off switch id",
|
|
|
|
"name": "On off switch",
|
2018-08-01 09:03:08 +00:00
|
|
|
"type": "On/Off plug-in unit",
|
2019-09-18 10:47:26 +00:00
|
|
|
"state": {"reachable": True},
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:02-00",
|
|
|
|
},
|
2020-02-01 16:08:49 +00: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",
|
|
|
|
},
|
2020-09-13 14:31:39 +00:00
|
|
|
"5": {
|
|
|
|
"ctmax": 1000,
|
|
|
|
"ctmin": 0,
|
|
|
|
"id": "Tunable white light with bad maxmin values id",
|
|
|
|
"name": "Tunable white light with bad maxmin values",
|
|
|
|
"state": {"on": True, "colormode": "ct", "ct": 2500, "reachable": True},
|
|
|
|
"type": "Tunable white light",
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:04-00",
|
|
|
|
},
|
2018-08-01 09:03:08 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 16:00:16 +00:00
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
async def test_no_lights_or_groups(hass, aioclient_mock):
|
2018-05-05 14:11:00 +00:00
|
|
|
"""Test that no lights or groups entities are created."""
|
2021-02-09 07:31:29 +00:00
|
|
|
await setup_deconz_integration(hass, aioclient_mock)
|
2018-04-23 16:00:16 +00:00
|
|
|
assert len(hass.states.async_all()) == 0
|
|
|
|
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
async def test_lights_and_groups(hass, aioclient_mock):
|
2018-05-05 14:11:00 +00:00
|
|
|
"""Test that lights or groups entities are created."""
|
2019-09-18 10:47:26 +00:00
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
data["groups"] = deepcopy(GROUPS)
|
|
|
|
data["lights"] = deepcopy(LIGHTS)
|
2021-02-09 07:31:29 +00:00
|
|
|
config_entry = await setup_deconz_integration(
|
|
|
|
hass, aioclient_mock, get_state_response=data
|
|
|
|
)
|
2020-10-06 21:25:57 +00:00
|
|
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
2020-02-01 16:08:49 +00:00
|
|
|
|
2020-09-13 14:31:39 +00:00
|
|
|
assert len(hass.states.async_all()) == 6
|
2019-09-18 10:47:26 +00:00
|
|
|
|
|
|
|
rgb_light = hass.states.get("light.rgb_light")
|
2020-10-17 16:20:06 +00:00
|
|
|
assert rgb_light.state == STATE_ON
|
|
|
|
assert rgb_light.attributes[ATTR_BRIGHTNESS] == 255
|
|
|
|
assert rgb_light.attributes[ATTR_HS_COLOR] == (224.235, 100.0)
|
2019-09-18 10:47:26 +00:00
|
|
|
assert rgb_light.attributes["is_deconz_group"] is False
|
2020-10-17 16:20:06 +00:00
|
|
|
assert rgb_light.attributes[ATTR_SUPPORTED_FEATURES] == 61
|
2019-09-18 10:47:26 +00:00
|
|
|
|
|
|
|
tunable_white_light = hass.states.get("light.tunable_white_light")
|
2020-10-17 16:20:06 +00:00
|
|
|
assert tunable_white_light.state == STATE_ON
|
|
|
|
assert tunable_white_light.attributes[ATTR_COLOR_TEMP] == 2500
|
|
|
|
assert tunable_white_light.attributes[ATTR_MAX_MIREDS] == 454
|
|
|
|
assert tunable_white_light.attributes[ATTR_MIN_MIREDS] == 155
|
|
|
|
assert tunable_white_light.attributes[ATTR_SUPPORTED_FEATURES] == 2
|
2020-02-01 16:08:49 +00:00
|
|
|
|
2020-09-13 14:31:39 +00:00
|
|
|
tunable_white_light_bad_maxmin = hass.states.get(
|
|
|
|
"light.tunable_white_light_with_bad_maxmin_values"
|
|
|
|
)
|
2020-10-17 16:20:06 +00:00
|
|
|
assert tunable_white_light_bad_maxmin.state == STATE_ON
|
|
|
|
assert tunable_white_light_bad_maxmin.attributes[ATTR_COLOR_TEMP] == 2500
|
|
|
|
assert tunable_white_light_bad_maxmin.attributes[ATTR_MAX_MIREDS] == 650
|
|
|
|
assert tunable_white_light_bad_maxmin.attributes[ATTR_MIN_MIREDS] == 140
|
|
|
|
assert tunable_white_light_bad_maxmin.attributes[ATTR_SUPPORTED_FEATURES] == 2
|
2020-09-13 14:31:39 +00:00
|
|
|
|
2020-02-01 16:08:49 +00:00
|
|
|
on_off_light = hass.states.get("light.on_off_light")
|
2020-10-17 16:20:06 +00:00
|
|
|
assert on_off_light.state == STATE_ON
|
|
|
|
assert on_off_light.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
2019-09-18 10:47:26 +00:00
|
|
|
|
|
|
|
light_group = hass.states.get("light.light_group")
|
2020-10-17 16:20:06 +00:00
|
|
|
assert light_group.state == STATE_ON
|
2019-09-18 10:47:26 +00:00
|
|
|
assert light_group.attributes["all_on"] is False
|
|
|
|
|
|
|
|
empty_group = hass.states.get("light.empty_group")
|
|
|
|
assert empty_group is None
|
|
|
|
|
2019-12-08 15:53:34 +00:00
|
|
|
state_changed_event = {
|
|
|
|
"t": "event",
|
|
|
|
"e": "changed",
|
|
|
|
"r": "lights",
|
|
|
|
"id": "1",
|
|
|
|
"state": {"on": False},
|
|
|
|
}
|
2020-02-02 18:07:20 +00:00
|
|
|
gateway.api.event_handler(state_changed_event)
|
2018-05-05 14:11:00 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
rgb_light = hass.states.get("light.rgb_light")
|
2020-10-17 16:20:06 +00:00
|
|
|
assert rgb_light.state == STATE_OFF
|
2019-09-18 10:47:26 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Verify service calls
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
mock_deconz_put_request(aioclient_mock, config_entry.data, "/lights/1/state")
|
2019-12-08 15:53:34 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Service turn on light with short color loop
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
LIGHT_DOMAIN,
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
{
|
|
|
|
ATTR_ENTITY_ID: "light.rgb_light",
|
|
|
|
ATTR_COLOR_TEMP: 2500,
|
|
|
|
ATTR_BRIGHTNESS: 200,
|
|
|
|
ATTR_TRANSITION: 5,
|
|
|
|
ATTR_FLASH: FLASH_SHORT,
|
|
|
|
ATTR_EFFECT: EFFECT_COLORLOOP,
|
|
|
|
},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
assert aioclient_mock.mock_calls[1][2] == {
|
|
|
|
"ct": 2500,
|
|
|
|
"bri": 200,
|
|
|
|
"transitiontime": 50,
|
|
|
|
"alert": "select",
|
|
|
|
"effect": "colorloop",
|
|
|
|
}
|
2018-05-05 14:11:00 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Service turn on light disabling color loop with long flashing
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
LIGHT_DOMAIN,
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
{
|
|
|
|
ATTR_ENTITY_ID: "light.rgb_light",
|
|
|
|
ATTR_HS_COLOR: (20, 30),
|
|
|
|
ATTR_FLASH: FLASH_LONG,
|
|
|
|
ATTR_EFFECT: "None",
|
|
|
|
},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
assert aioclient_mock.mock_calls[2][2] == {
|
|
|
|
"xy": (0.411, 0.351),
|
|
|
|
"alert": "lselect",
|
|
|
|
"effect": "none",
|
|
|
|
}
|
|
|
|
|
|
|
|
# Service turn on light with short flashing not supported
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
LIGHT_DOMAIN,
|
|
|
|
SERVICE_TURN_OFF,
|
|
|
|
{
|
|
|
|
ATTR_ENTITY_ID: "light.rgb_light",
|
|
|
|
ATTR_TRANSITION: 5,
|
|
|
|
ATTR_FLASH: FLASH_SHORT,
|
|
|
|
},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
assert len(aioclient_mock.mock_calls) == 3 # Not called
|
2020-06-01 22:20:52 +00:00
|
|
|
|
|
|
|
state_changed_event = {
|
|
|
|
"t": "event",
|
|
|
|
"e": "changed",
|
|
|
|
"r": "lights",
|
|
|
|
"id": "1",
|
|
|
|
"state": {"on": True},
|
|
|
|
}
|
|
|
|
gateway.api.event_handler(state_changed_event)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Service turn off light with short flashing
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
LIGHT_DOMAIN,
|
|
|
|
SERVICE_TURN_OFF,
|
|
|
|
{
|
|
|
|
ATTR_ENTITY_ID: "light.rgb_light",
|
|
|
|
ATTR_TRANSITION: 5,
|
|
|
|
ATTR_FLASH: FLASH_SHORT,
|
|
|
|
},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
assert aioclient_mock.mock_calls[3][2] == {
|
|
|
|
"bri": 0,
|
|
|
|
"transitiontime": 50,
|
|
|
|
"alert": "select",
|
|
|
|
}
|
2018-06-15 18:31:22 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Service turn off light with long flashing
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
LIGHT_DOMAIN,
|
|
|
|
SERVICE_TURN_OFF,
|
|
|
|
{ATTR_ENTITY_ID: "light.rgb_light", ATTR_FLASH: FLASH_LONG},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
assert aioclient_mock.mock_calls[4][2] == {"alert": "lselect"}
|
2018-08-01 09:03:08 +00:00
|
|
|
|
2020-10-06 21:25:57 +00:00
|
|
|
await hass.config_entries.async_unload(config_entry.entry_id)
|
2019-09-19 21:44:09 +00:00
|
|
|
|
2021-02-08 09:45:46 +00:00
|
|
|
states = hass.states.async_all()
|
|
|
|
assert len(hass.states.async_all()) == 6
|
|
|
|
for state in states:
|
|
|
|
assert state.state == STATE_UNAVAILABLE
|
|
|
|
|
|
|
|
await hass.config_entries.async_remove(config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
2020-01-07 16:30:53 +00:00
|
|
|
assert len(hass.states.async_all()) == 0
|
2019-09-19 21:44:09 +00:00
|
|
|
|
2018-08-01 09:03:08 +00:00
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
async def test_disable_light_groups(hass, aioclient_mock):
|
2020-10-02 09:20:33 +00:00
|
|
|
"""Test disallowing light groups work."""
|
2019-09-18 10:47:26 +00:00
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
data["groups"] = deepcopy(GROUPS)
|
|
|
|
data["lights"] = deepcopy(LIGHTS)
|
2020-10-06 21:25:57 +00:00
|
|
|
config_entry = await setup_deconz_integration(
|
2019-09-18 10:47:26 +00:00
|
|
|
hass,
|
2021-02-09 07:31:29 +00:00
|
|
|
aioclient_mock,
|
2020-10-17 16:20:06 +00:00
|
|
|
options={CONF_ALLOW_DECONZ_GROUPS: False},
|
2019-09-18 10:47:26 +00:00
|
|
|
get_state_response=data,
|
|
|
|
)
|
2018-10-31 21:38:04 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
assert len(hass.states.async_all()) == 5
|
|
|
|
assert hass.states.get("light.rgb_light")
|
|
|
|
assert hass.states.get("light.tunable_white_light")
|
|
|
|
assert hass.states.get("light.light_group") is None
|
|
|
|
assert hass.states.get("light.empty_group") is None
|
2020-02-18 21:24:25 +00:00
|
|
|
|
|
|
|
hass.config_entries.async_update_entry(
|
2020-10-17 16:20:06 +00:00
|
|
|
config_entry, options={CONF_ALLOW_DECONZ_GROUPS: True}
|
2020-02-18 21:24:25 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-09-13 14:31:39 +00:00
|
|
|
assert len(hass.states.async_all()) == 6
|
2020-10-02 09:20:33 +00:00
|
|
|
assert hass.states.get("light.light_group")
|
2020-02-18 21:24:25 +00:00
|
|
|
|
|
|
|
hass.config_entries.async_update_entry(
|
2020-10-17 16:20:06 +00:00
|
|
|
config_entry, options={CONF_ALLOW_DECONZ_GROUPS: False}
|
2020-02-18 21:24:25 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-09-13 14:31:39 +00:00
|
|
|
assert len(hass.states.async_all()) == 5
|
2020-10-02 09:20:33 +00:00
|
|
|
assert hass.states.get("light.light_group") is None
|
2020-11-23 10:37:11 +00:00
|
|
|
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
async def test_configuration_tool(hass, aioclient_mock):
|
2020-11-23 10:37:11 +00:00
|
|
|
"""Test that lights or groups entities are created."""
|
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
data["lights"] = {
|
|
|
|
"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",
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 07:31:29 +00:00
|
|
|
await setup_deconz_integration(hass, aioclient_mock, get_state_response=data)
|
2020-11-23 10:37:11 +00:00
|
|
|
|
|
|
|
assert len(hass.states.async_all()) == 0
|
2020-12-09 18:02:44 +00:00
|
|
|
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
async def test_lidl_christmas_light(hass, aioclient_mock):
|
2020-12-09 18:02:44 +00:00
|
|
|
"""Test that lights or groups entities are created."""
|
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
data["lights"] = {
|
|
|
|
"0": {
|
|
|
|
"etag": "87a89542bf9b9d0aa8134919056844f8",
|
|
|
|
"hascolor": True,
|
|
|
|
"lastannounced": None,
|
|
|
|
"lastseen": "2020-12-05T22:57Z",
|
|
|
|
"manufacturername": "_TZE200_s8gkrkxk",
|
|
|
|
"modelid": "TS0601",
|
|
|
|
"name": "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",
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 07:31:29 +00:00
|
|
|
config_entry = await setup_deconz_integration(
|
|
|
|
hass, aioclient_mock, get_state_response=data
|
|
|
|
)
|
2020-12-09 18:02:44 +00:00
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
mock_deconz_put_request(aioclient_mock, config_entry.data, "/lights/0/state")
|
2020-12-09 18:02:44 +00:00
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
LIGHT_DOMAIN,
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
{
|
|
|
|
ATTR_ENTITY_ID: "light.xmas_light",
|
|
|
|
ATTR_HS_COLOR: (20, 30),
|
|
|
|
},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
assert aioclient_mock.mock_calls[1][2] == {"on": True, "hue": 3640, "sat": 76}
|
2020-12-09 18:02:44 +00:00
|
|
|
|
|
|
|
assert hass.states.get("light.xmas_light")
|
2021-01-22 21:40:22 +00:00
|
|
|
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
async def test_non_color_light_reports_color(hass, aioclient_mock):
|
2021-01-22 21:40:22 +00:00
|
|
|
"""Verify hs_color does not crash when a group gets updated with a bad color value.
|
|
|
|
|
|
|
|
After calling a scene color temp light of certain manufacturers
|
|
|
|
report color temp in color space.
|
|
|
|
"""
|
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
|
|
|
|
data["groups"] = {
|
|
|
|
"0": {
|
|
|
|
"action": {
|
|
|
|
"alert": "none",
|
|
|
|
"bri": 127,
|
|
|
|
"colormode": "hs",
|
|
|
|
"ct": 0,
|
|
|
|
"effect": "none",
|
|
|
|
"hue": 0,
|
|
|
|
"on": True,
|
|
|
|
"sat": 127,
|
|
|
|
"scene": None,
|
|
|
|
"xy": [0, 0],
|
|
|
|
},
|
|
|
|
"devicemembership": [],
|
|
|
|
"etag": "81e42cf1b47affb72fa72bc2e25ba8bf",
|
|
|
|
"id": "0",
|
|
|
|
"lights": ["0", "1"],
|
|
|
|
"name": "All",
|
|
|
|
"scenes": [],
|
|
|
|
"state": {"all_on": False, "any_on": True},
|
|
|
|
"type": "LightGroup",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data["lights"] = {
|
|
|
|
"0": {
|
|
|
|
"ctmax": 500,
|
|
|
|
"ctmin": 153,
|
|
|
|
"etag": "026bcfe544ad76c7534e5ca8ed39047c",
|
|
|
|
"hascolor": True,
|
|
|
|
"manufacturername": "dresden elektronik",
|
|
|
|
"modelid": "FLS-PP3",
|
|
|
|
"name": "Light 1",
|
|
|
|
"pointsymbol": {},
|
|
|
|
"state": {
|
|
|
|
"alert": None,
|
|
|
|
"bri": 111,
|
|
|
|
"colormode": "ct",
|
|
|
|
"ct": 307,
|
|
|
|
"effect": None,
|
|
|
|
"hascolor": True,
|
|
|
|
"hue": 7998,
|
|
|
|
"on": False,
|
|
|
|
"reachable": True,
|
|
|
|
"sat": 172,
|
|
|
|
"xy": [0.421253, 0.39921],
|
|
|
|
},
|
|
|
|
"swversion": "020C.201000A0",
|
|
|
|
"type": "Extended color light",
|
|
|
|
"uniqueid": "00:21:2E:FF:FF:EE:DD:CC-0A",
|
|
|
|
},
|
|
|
|
"1": {
|
|
|
|
"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": "Küchenlicht",
|
|
|
|
"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",
|
|
|
|
},
|
|
|
|
}
|
2021-02-09 07:31:29 +00:00
|
|
|
config_entry = await setup_deconz_integration(
|
|
|
|
hass, aioclient_mock, get_state_response=data
|
|
|
|
)
|
2021-01-22 21:40:22 +00:00
|
|
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
|
|
|
|
|
|
|
assert len(hass.states.async_all()) == 3
|
|
|
|
assert hass.states.get("light.all").attributes[ATTR_COLOR_TEMP] == 307
|
|
|
|
|
|
|
|
# Updating a scene will return a faulty color value for a non-color light causing an exception in hs_color
|
|
|
|
state_changed_event = {
|
|
|
|
"e": "changed",
|
|
|
|
"id": "1",
|
|
|
|
"r": "lights",
|
|
|
|
"state": {
|
|
|
|
"alert": None,
|
|
|
|
"bri": 216,
|
|
|
|
"colormode": "xy",
|
|
|
|
"ct": 410,
|
|
|
|
"on": True,
|
|
|
|
"reachable": True,
|
|
|
|
},
|
|
|
|
"t": "event",
|
|
|
|
"uniqueid": "ec:1b:bd:ff:fe:ee:ed:dd-01",
|
|
|
|
}
|
|
|
|
gateway.api.event_handler(state_changed_event)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
# Bug is fixed if we reach this point, but device won't have neither color temp nor color
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
assert hass.states.get("light.all").attributes[ATTR_COLOR_TEMP]
|
|
|
|
assert hass.states.get("light.all").attributes[ATTR_HS_COLOR]
|
2021-01-22 22:39:34 +00:00
|
|
|
|
|
|
|
|
2021-02-09 07:31:29 +00:00
|
|
|
async def test_verify_group_supported_features(hass, aioclient_mock):
|
2021-01-22 22:39:34 +00:00
|
|
|
"""Test that group supported features reflect what included lights support."""
|
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
data["groups"] = deepcopy(
|
|
|
|
{
|
|
|
|
"1": {
|
|
|
|
"id": "Group1",
|
|
|
|
"name": "group",
|
|
|
|
"type": "LightGroup",
|
|
|
|
"state": {"all_on": False, "any_on": True},
|
|
|
|
"action": {},
|
|
|
|
"scenes": [],
|
|
|
|
"lights": ["1", "2", "3"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
data["lights"] = deepcopy(
|
|
|
|
{
|
|
|
|
"1": {
|
|
|
|
"id": "light1",
|
|
|
|
"name": "Dimmable light",
|
|
|
|
"state": {"on": True, "bri": 255, "reachable": True},
|
|
|
|
"type": "Light",
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:01-00",
|
|
|
|
},
|
|
|
|
"2": {
|
|
|
|
"id": "light2",
|
|
|
|
"name": "Color light",
|
|
|
|
"state": {
|
|
|
|
"on": True,
|
|
|
|
"bri": 100,
|
|
|
|
"colormode": "xy",
|
|
|
|
"effect": "colorloop",
|
|
|
|
"xy": (500, 500),
|
|
|
|
"reachable": True,
|
|
|
|
},
|
|
|
|
"type": "Extended color light",
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:02-00",
|
|
|
|
},
|
|
|
|
"3": {
|
|
|
|
"ctmax": 454,
|
|
|
|
"ctmin": 155,
|
|
|
|
"id": "light3",
|
|
|
|
"name": "Tunable light",
|
|
|
|
"state": {"on": True, "colormode": "ct", "ct": 2500, "reachable": True},
|
|
|
|
"type": "Tunable white light",
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:03-00",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
2021-02-09 07:31:29 +00:00
|
|
|
await setup_deconz_integration(hass, aioclient_mock, get_state_response=data)
|
2021-01-22 22:39:34 +00:00
|
|
|
|
|
|
|
assert len(hass.states.async_all()) == 4
|
|
|
|
|
|
|
|
group = hass.states.get("light.group")
|
|
|
|
assert group.state == STATE_ON
|
|
|
|
assert group.attributes[ATTR_SUPPORTED_FEATURES] == 63
|