Use shorthand attributes in Kulersky (#99583)
This commit is contained in:
parent
8ea3b877f6
commit
cf2d3674b9
1 changed files with 14 additions and 27 deletions
|
@ -66,13 +66,19 @@ class KulerskyLight(LightEntity):
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
_attr_available = False
|
||||||
|
_attr_supported_color_modes = {ColorMode.RGBW}
|
||||||
|
_attr_color_mode = ColorMode.RGBW
|
||||||
|
|
||||||
def __init__(self, light: pykulersky.Light) -> None:
|
def __init__(self, light: pykulersky.Light) -> None:
|
||||||
"""Initialize a Kuler Sky light."""
|
"""Initialize a Kuler Sky light."""
|
||||||
self._light = light
|
self._light = light
|
||||||
self._available = False
|
self._attr_unique_id = light.address
|
||||||
self._attr_supported_color_modes = {ColorMode.RGBW}
|
self._attr_device_info = DeviceInfo(
|
||||||
self._attr_color_mode = ColorMode.RGBW
|
identifiers={(DOMAIN, light.address)},
|
||||||
|
manufacturer="Brightech",
|
||||||
|
name=light.name,
|
||||||
|
)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Run when entity about to be added to hass."""
|
"""Run when entity about to be added to hass."""
|
||||||
|
@ -91,30 +97,11 @@ class KulerskyLight(LightEntity):
|
||||||
"Exception disconnected from %s", self._light.address, exc_info=True
|
"Exception disconnected from %s", self._light.address, exc_info=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return the ID of this light."""
|
|
||||||
return self._light.address
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Device info for this light."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self.unique_id)},
|
|
||||||
manufacturer="Brightech",
|
|
||||||
name=self._light.name,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if light is on."""
|
"""Return true if light is on."""
|
||||||
return self.brightness > 0
|
return self.brightness > 0
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self) -> bool:
|
|
||||||
"""Return True if entity is available."""
|
|
||||||
return self._available
|
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Instruct the light to turn on."""
|
"""Instruct the light to turn on."""
|
||||||
default_rgbw = (255,) * 4 if self.rgbw_color is None else self.rgbw_color
|
default_rgbw = (255,) * 4 if self.rgbw_color is None else self.rgbw_color
|
||||||
|
@ -140,18 +127,18 @@ class KulerskyLight(LightEntity):
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Fetch new state data for this light."""
|
"""Fetch new state data for this light."""
|
||||||
try:
|
try:
|
||||||
if not self._available:
|
if not self._attr_available:
|
||||||
await self._light.connect()
|
await self._light.connect()
|
||||||
rgbw = await self._light.get_color()
|
rgbw = await self._light.get_color()
|
||||||
except pykulersky.PykulerskyException as exc:
|
except pykulersky.PykulerskyException as exc:
|
||||||
if self._available:
|
if self._attr_available:
|
||||||
_LOGGER.warning("Unable to connect to %s: %s", self._light.address, exc)
|
_LOGGER.warning("Unable to connect to %s: %s", self._light.address, exc)
|
||||||
self._available = False
|
self._attr_available = False
|
||||||
return
|
return
|
||||||
if self._available is False:
|
if self._attr_available is False:
|
||||||
_LOGGER.info("Reconnected to %s", self._light.address)
|
_LOGGER.info("Reconnected to %s", self._light.address)
|
||||||
|
|
||||||
self._available = True
|
self._attr_available = True
|
||||||
brightness = max(rgbw)
|
brightness = max(rgbw)
|
||||||
if not brightness:
|
if not brightness:
|
||||||
self._attr_rgbw_color = (0, 0, 0, 0)
|
self._attr_rgbw_color = (0, 0, 0, 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue