From cf2d3674b9fe16a11ab823fdcf52de41288cbf1c Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 4 Sep 2023 13:29:56 +0200 Subject: [PATCH] Use shorthand attributes in Kulersky (#99583) --- homeassistant/components/kulersky/light.py | 41 ++++++++-------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/kulersky/light.py b/homeassistant/components/kulersky/light.py index c68633ab639692..6636bfdba9f33c 100644 --- a/homeassistant/components/kulersky/light.py +++ b/homeassistant/components/kulersky/light.py @@ -66,13 +66,19 @@ class KulerskyLight(LightEntity): _attr_has_entity_name = True _attr_name = None + _attr_available = False + _attr_supported_color_modes = {ColorMode.RGBW} + _attr_color_mode = ColorMode.RGBW def __init__(self, light: pykulersky.Light) -> None: """Initialize a Kuler Sky light.""" self._light = light - self._available = False - self._attr_supported_color_modes = {ColorMode.RGBW} - self._attr_color_mode = ColorMode.RGBW + self._attr_unique_id = light.address + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, light.address)}, + manufacturer="Brightech", + name=light.name, + ) async def async_added_to_hass(self) -> None: """Run when entity about to be added to hass.""" @@ -91,30 +97,11 @@ async def async_will_remove_from_hass(self, *args) -> None: "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 def is_on(self): """Return true if light is on.""" 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: """Instruct the light to turn on.""" default_rgbw = (255,) * 4 if self.rgbw_color is None else self.rgbw_color @@ -140,18 +127,18 @@ async def async_turn_off(self, **kwargs: Any) -> None: async def async_update(self) -> None: """Fetch new state data for this light.""" try: - if not self._available: + if not self._attr_available: await self._light.connect() rgbw = await self._light.get_color() except pykulersky.PykulerskyException as exc: - if self._available: + if self._attr_available: _LOGGER.warning("Unable to connect to %s: %s", self._light.address, exc) - self._available = False + self._attr_available = False return - if self._available is False: + if self._attr_available is False: _LOGGER.info("Reconnected to %s", self._light.address) - self._available = True + self._attr_available = True brightness = max(rgbw) if not brightness: self._attr_rgbw_color = (0, 0, 0, 0)