mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 15:27:08 +00:00
Minor improvements to deCONZ light platform (#56953)
Use library constnats for flash and effect Use attr_effect_list to specify supported effects Use isinstance to identify if it is light or group
This commit is contained in:
parent
946a265c9e
commit
1d643d6da7
@ -2,7 +2,14 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pydeconz.light import Light
|
from pydeconz.group import DeconzGroup as Group
|
||||||
|
from pydeconz.light import (
|
||||||
|
ALERT_LONG,
|
||||||
|
ALERT_SHORT,
|
||||||
|
EFFECT_COLOR_LOOP,
|
||||||
|
EFFECT_NONE,
|
||||||
|
Light,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
@ -35,6 +42,8 @@ from .deconz_device import DeconzDevice
|
|||||||
from .gateway import get_gateway_from_config_entry
|
from .gateway import get_gateway_from_config_entry
|
||||||
|
|
||||||
DECONZ_GROUP = "is_deconz_group"
|
DECONZ_GROUP = "is_deconz_group"
|
||||||
|
EFFECT_TO_DECONZ = {EFFECT_COLORLOOP: EFFECT_COLOR_LOOP, "None": EFFECT_NONE}
|
||||||
|
FLASH_TO_DECONZ = {FLASH_SHORT: ALERT_SHORT, FLASH_LONG: ALERT_LONG}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
@ -126,6 +135,7 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
|||||||
|
|
||||||
if device.effect is not None:
|
if device.effect is not None:
|
||||||
self._attr_supported_features |= SUPPORT_EFFECT
|
self._attr_supported_features |= SUPPORT_EFFECT
|
||||||
|
self._attr_effect_list = [EFFECT_COLORLOOP]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_mode(self) -> str:
|
def color_mode(self) -> str:
|
||||||
@ -147,11 +157,6 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
|||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
return self._device.brightness
|
return self._device.brightness
|
||||||
|
|
||||||
@property
|
|
||||||
def effect_list(self):
|
|
||||||
"""Return the list of supported effects."""
|
|
||||||
return [EFFECT_COLORLOOP]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp(self):
|
def color_temp(self):
|
||||||
"""Return the CT color value."""
|
"""Return the CT color value."""
|
||||||
@ -197,19 +202,12 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
|||||||
elif "IKEA" in self._device.manufacturer:
|
elif "IKEA" in self._device.manufacturer:
|
||||||
data["transition_time"] = 0
|
data["transition_time"] = 0
|
||||||
|
|
||||||
if ATTR_FLASH in kwargs:
|
if (alert := FLASH_TO_DECONZ.get(kwargs.get(ATTR_FLASH))) is not None:
|
||||||
if kwargs[ATTR_FLASH] == FLASH_SHORT:
|
data["alert"] = alert
|
||||||
data["alert"] = "select"
|
|
||||||
del data["on"]
|
|
||||||
elif kwargs[ATTR_FLASH] == FLASH_LONG:
|
|
||||||
data["alert"] = "lselect"
|
|
||||||
del data["on"]
|
del data["on"]
|
||||||
|
|
||||||
if ATTR_EFFECT in kwargs:
|
if (effect := EFFECT_TO_DECONZ.get(kwargs.get(ATTR_EFFECT))) is not None:
|
||||||
if kwargs[ATTR_EFFECT] == EFFECT_COLORLOOP:
|
data["effect"] = effect
|
||||||
data["effect"] = "colorloop"
|
|
||||||
else:
|
|
||||||
data["effect"] = "none"
|
|
||||||
|
|
||||||
await self._device.set_state(**data)
|
await self._device.set_state(**data)
|
||||||
|
|
||||||
@ -224,12 +222,8 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
|||||||
data["brightness"] = 0
|
data["brightness"] = 0
|
||||||
data["transition_time"] = int(kwargs[ATTR_TRANSITION] * 10)
|
data["transition_time"] = int(kwargs[ATTR_TRANSITION] * 10)
|
||||||
|
|
||||||
if ATTR_FLASH in kwargs:
|
if (alert := FLASH_TO_DECONZ.get(kwargs.get(ATTR_FLASH))) is not None:
|
||||||
if kwargs[ATTR_FLASH] == FLASH_SHORT:
|
data["alert"] = alert
|
||||||
data["alert"] = "select"
|
|
||||||
del data["on"]
|
|
||||||
elif kwargs[ATTR_FLASH] == FLASH_LONG:
|
|
||||||
data["alert"] = "lselect"
|
|
||||||
del data["on"]
|
del data["on"]
|
||||||
|
|
||||||
await self._device.set_state(**data)
|
await self._device.set_state(**data)
|
||||||
@ -237,7 +231,7 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
|||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the device state attributes."""
|
"""Return the device state attributes."""
|
||||||
return {DECONZ_GROUP: self._device.type == "LightGroup"}
|
return {DECONZ_GROUP: isinstance(self._device, Group)}
|
||||||
|
|
||||||
|
|
||||||
class DeconzLight(DeconzBaseLight):
|
class DeconzLight(DeconzBaseLight):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user