From 17734d54abc0eb3ef85a72a24ce63cbcbce3400a Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sun, 30 Aug 2020 18:32:56 +0200 Subject: [PATCH] Update hue to use CoordinatorEntity (#39446) --- homeassistant/components/hue/light.py | 28 +++++++-------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/hue/light.py b/homeassistant/components/hue/light.py index 9d055ad6066..20066bd1be2 100644 --- a/homeassistant/components/hue/light.py +++ b/homeassistant/components/hue/light.py @@ -29,7 +29,11 @@ from homeassistant.components.light import ( from homeassistant.core import callback from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.debounce import Debouncer -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed +from homeassistant.helpers.update_coordinator import ( + CoordinatorEntity, + DataUpdateCoordinator, + UpdateFailed, +) from homeassistant.util import color from .const import DOMAIN as HUE_DOMAIN, REQUEST_REFRESH_DELAY @@ -194,13 +198,13 @@ def hass_to_hue_brightness(value): return max(1, round((value / 255) * 254)) -class HueLight(LightEntity): +class HueLight(CoordinatorEntity, LightEntity): """Representation of a Hue light.""" def __init__(self, coordinator, bridge, is_group, light, supported_features): """Initialize the light.""" + super().__init__(coordinator) self.light = light - self.coordinator = coordinator self.bridge = bridge self.is_group = is_group self._supported_features = supported_features @@ -236,11 +240,6 @@ class HueLight(LightEntity): """Return the unique ID of this Hue light.""" return self.light.uniqueid - @property - def should_poll(self): - """No polling required.""" - return False - @property def device_id(self): """Return the ID of this Hue light.""" @@ -371,12 +370,6 @@ class HueLight(LightEntity): "via_device": (HUE_DOMAIN, self.bridge.api.config.bridgeid), } - async def async_added_to_hass(self): - """When entity is added to hass.""" - self.async_on_remove( - self.coordinator.async_add_listener(self.async_write_ha_state) - ) - async def async_turn_on(self, **kwargs): """Turn the specified or all lights on.""" command = {"on": True} @@ -462,13 +455,6 @@ class HueLight(LightEntity): await self.coordinator.async_request_refresh() - async def async_update(self): - """Update the entity. - - Only used by the generic entity update service. - """ - await self.coordinator.async_request_refresh() - @property def device_state_attributes(self): """Return the device state attributes."""