mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Improve type hint in everlights light entity (#77139)
This commit is contained in:
parent
6c4290e418
commit
563c956539
@ -79,63 +79,35 @@ class EverLightsLight(LightEntity):
|
|||||||
_attr_supported_color_modes = {ColorMode.HS}
|
_attr_supported_color_modes = {ColorMode.HS}
|
||||||
_attr_supported_features = LightEntityFeature.EFFECT
|
_attr_supported_features = LightEntityFeature.EFFECT
|
||||||
|
|
||||||
def __init__(self, api, channel, status, effects):
|
def __init__(
|
||||||
|
self,
|
||||||
|
api: pyeverlights.EverLights,
|
||||||
|
channel: int,
|
||||||
|
status: dict[str, Any],
|
||||||
|
effects,
|
||||||
|
) -> None:
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self._api = api
|
self._api = api
|
||||||
self._channel = channel
|
self._channel = channel
|
||||||
self._status = status
|
self._status = status
|
||||||
self._effects = effects
|
self._attr_effect_list = effects
|
||||||
self._mac = status["mac"]
|
self._mac = status["mac"]
|
||||||
self._error_reported = False
|
self._error_reported = False
|
||||||
self._hs_color = [255, 255]
|
self._attr_hs_color = (255, 255)
|
||||||
self._brightness = 255
|
self._attr_brightness = 255
|
||||||
self._effect = None
|
|
||||||
self._available = True
|
self._attr_name = f"EverLights {self._mac} Zone {self._channel}"
|
||||||
|
self._attr_unique_id = f"{self._mac}-{self._channel}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def is_on(self) -> bool:
|
||||||
"""Return a unique ID."""
|
|
||||||
return f"{self._mac}-{self._channel}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self) -> bool:
|
|
||||||
"""Return True if entity is available."""
|
|
||||||
return self._available
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the device."""
|
|
||||||
return f"EverLights {self._mac} Zone {self._channel}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return self._status[f"ch{self._channel}Active"] == 1
|
return self._status[f"ch{self._channel}Active"] == 1
|
||||||
|
|
||||||
@property
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
def brightness(self):
|
|
||||||
"""Return the brightness of this light between 0..255."""
|
|
||||||
return self._brightness
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hs_color(self):
|
|
||||||
"""Return the color property."""
|
|
||||||
return self._hs_color
|
|
||||||
|
|
||||||
@property
|
|
||||||
def effect(self):
|
|
||||||
"""Return the effect property."""
|
|
||||||
return self._effect
|
|
||||||
|
|
||||||
@property
|
|
||||||
def effect_list(self):
|
|
||||||
"""Return the list of supported effects."""
|
|
||||||
return self._effects
|
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
|
||||||
"""Turn the light on."""
|
"""Turn the light on."""
|
||||||
hs_color = kwargs.get(ATTR_HS_COLOR, self._hs_color)
|
hs_color = kwargs.get(ATTR_HS_COLOR, self._attr_hs_color)
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS, self._brightness)
|
brightness = kwargs.get(ATTR_BRIGHTNESS, self._attr_brightness)
|
||||||
effect = kwargs.get(ATTR_EFFECT)
|
effect = kwargs.get(ATTR_EFFECT)
|
||||||
|
|
||||||
if effect is not None:
|
if effect is not None:
|
||||||
@ -147,14 +119,16 @@ class EverLightsLight(LightEntity):
|
|||||||
brightness = hsv[2] / 100 * 255
|
brightness = hsv[2] / 100 * 255
|
||||||
|
|
||||||
else:
|
else:
|
||||||
rgb = color_util.color_hsv_to_RGB(*hs_color, brightness / 255 * 100)
|
rgb = color_util.color_hsv_to_RGB(
|
||||||
|
hs_color[0], hs_color[1], brightness / 255 * 100
|
||||||
|
)
|
||||||
colors = [color_rgb_to_int(*rgb)]
|
colors = [color_rgb_to_int(*rgb)]
|
||||||
|
|
||||||
await self._api.set_pattern(self._channel, colors)
|
await self._api.set_pattern(self._channel, colors)
|
||||||
|
|
||||||
self._hs_color = hs_color
|
self._attr_hs_color = hs_color
|
||||||
self._brightness = brightness
|
self._attr_brightness = brightness
|
||||||
self._effect = effect
|
self._attr_effect = effect
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the light off."""
|
"""Turn the light off."""
|
||||||
@ -165,10 +139,10 @@ class EverLightsLight(LightEntity):
|
|||||||
try:
|
try:
|
||||||
self._status = await self._api.get_status()
|
self._status = await self._api.get_status()
|
||||||
except pyeverlights.ConnectionError:
|
except pyeverlights.ConnectionError:
|
||||||
if self._available:
|
if self.available:
|
||||||
_LOGGER.warning("EverLights control box connection lost")
|
_LOGGER.warning("EverLights control box connection lost")
|
||||||
self._available = False
|
self._attr_available = False
|
||||||
else:
|
else:
|
||||||
if not self._available:
|
if not self.available:
|
||||||
_LOGGER.warning("EverLights control box connection restored")
|
_LOGGER.warning("EverLights control box connection restored")
|
||||||
self._available = True
|
self._attr_available = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user