Fix deconz light service parameter handling (#62128)
* Only check presence of values, not their content
* Add tests
* Revert "Only check presence of values, not their content"
This reverts commit 046f0ed5fd
.
* Validate existence of keys, not their values
* Properly handle cases of missing keys
pull/62577/head
parent
3663e0af41
commit
f135d77a27
|
@ -199,7 +199,7 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
|||
"""Turn on light."""
|
||||
data: dict[str, bool | float | int | str | tuple[float, float]] = {"on": True}
|
||||
|
||||
if attr_brightness := kwargs.get(ATTR_BRIGHTNESS):
|
||||
if (attr_brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None:
|
||||
data["brightness"] = attr_brightness
|
||||
|
||||
if attr_color_temp := kwargs.get(ATTR_COLOR_TEMP):
|
||||
|
@ -215,16 +215,16 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
|||
if ATTR_XY_COLOR in kwargs:
|
||||
data["xy"] = kwargs[ATTR_XY_COLOR]
|
||||
|
||||
if attr_transition := kwargs.get(ATTR_TRANSITION):
|
||||
if (attr_transition := kwargs.get(ATTR_TRANSITION)) is not None:
|
||||
data["transition_time"] = int(attr_transition * 10)
|
||||
elif "IKEA" in self._device.manufacturer:
|
||||
data["transition_time"] = 0
|
||||
|
||||
if (alert := FLASH_TO_DECONZ.get(kwargs.get(ATTR_FLASH, ""))) is not None:
|
||||
if (alert := FLASH_TO_DECONZ.get(kwargs.get(ATTR_FLASH))) is not None:
|
||||
data["alert"] = alert
|
||||
del data["on"]
|
||||
|
||||
if (effect := EFFECT_TO_DECONZ.get(kwargs.get(ATTR_EFFECT, ""))) is not None:
|
||||
if (effect := EFFECT_TO_DECONZ.get(kwargs.get(ATTR_EFFECT))) is not None:
|
||||
data["effect"] = effect
|
||||
|
||||
await self._device.set_state(**data)
|
||||
|
@ -236,11 +236,11 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
|||
|
||||
data: dict[str, bool | int | str] = {"on": False}
|
||||
|
||||
if ATTR_TRANSITION in kwargs:
|
||||
if (attr_transition := kwargs.get(ATTR_TRANSITION)) is not None:
|
||||
data["brightness"] = 0
|
||||
data["transition_time"] = int(kwargs[ATTR_TRANSITION] * 10)
|
||||
data["transition_time"] = int(attr_transition * 10)
|
||||
|
||||
if (alert := FLASH_TO_DECONZ.get(kwargs.get(ATTR_FLASH, ""))) is not None:
|
||||
if (alert := FLASH_TO_DECONZ.get(kwargs.get(ATTR_FLASH))) is not None:
|
||||
data["alert"] = alert
|
||||
del data["on"]
|
||||
|
||||
|
|
|
@ -399,6 +399,20 @@ async def test_light_state_change(hass, aioclient_mock, mock_deconz_websocket):
|
|||
"xy": (0.411, 0.351),
|
||||
},
|
||||
),
|
||||
( # Turn on light without transition time
|
||||
{
|
||||
"light_on": True,
|
||||
"service": SERVICE_TURN_ON,
|
||||
"call": {
|
||||
ATTR_ENTITY_ID: "light.hue_go",
|
||||
ATTR_TRANSITION: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
"on": True,
|
||||
"transitiontime": 0,
|
||||
},
|
||||
),
|
||||
( # Turn on light with short color loop
|
||||
{
|
||||
"light_on": False,
|
||||
|
@ -453,6 +467,22 @@ async def test_light_state_change(hass, aioclient_mock, mock_deconz_websocket):
|
|||
"alert": "select",
|
||||
},
|
||||
),
|
||||
( # Turn off light without transition time
|
||||
{
|
||||
"light_on": True,
|
||||
"service": SERVICE_TURN_OFF,
|
||||
"call": {
|
||||
ATTR_ENTITY_ID: "light.hue_go",
|
||||
ATTR_TRANSITION: 0,
|
||||
ATTR_FLASH: FLASH_SHORT,
|
||||
},
|
||||
},
|
||||
{
|
||||
"bri": 0,
|
||||
"transitiontime": 0,
|
||||
"alert": "select",
|
||||
},
|
||||
),
|
||||
( # Turn off light with long flashing
|
||||
{
|
||||
"light_on": True,
|
||||
|
|
Loading…
Reference in New Issue