mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Update hue to use CoordinatorEntity (#39446)
This commit is contained in:
parent
d3b845c01a
commit
17734d54ab
@ -29,7 +29,11 @@ from homeassistant.components.light import (
|
|||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
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 homeassistant.util import color
|
||||||
|
|
||||||
from .const import DOMAIN as HUE_DOMAIN, REQUEST_REFRESH_DELAY
|
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))
|
return max(1, round((value / 255) * 254))
|
||||||
|
|
||||||
|
|
||||||
class HueLight(LightEntity):
|
class HueLight(CoordinatorEntity, LightEntity):
|
||||||
"""Representation of a Hue light."""
|
"""Representation of a Hue light."""
|
||||||
|
|
||||||
def __init__(self, coordinator, bridge, is_group, light, supported_features):
|
def __init__(self, coordinator, bridge, is_group, light, supported_features):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
|
super().__init__(coordinator)
|
||||||
self.light = light
|
self.light = light
|
||||||
self.coordinator = coordinator
|
|
||||||
self.bridge = bridge
|
self.bridge = bridge
|
||||||
self.is_group = is_group
|
self.is_group = is_group
|
||||||
self._supported_features = supported_features
|
self._supported_features = supported_features
|
||||||
@ -236,11 +240,6 @@ class HueLight(LightEntity):
|
|||||||
"""Return the unique ID of this Hue light."""
|
"""Return the unique ID of this Hue light."""
|
||||||
return self.light.uniqueid
|
return self.light.uniqueid
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""No polling required."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_id(self):
|
def device_id(self):
|
||||||
"""Return the ID of this Hue light."""
|
"""Return the ID of this Hue light."""
|
||||||
@ -371,12 +370,6 @@ class HueLight(LightEntity):
|
|||||||
"via_device": (HUE_DOMAIN, self.bridge.api.config.bridgeid),
|
"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):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn the specified or all lights on."""
|
"""Turn the specified or all lights on."""
|
||||||
command = {"on": True}
|
command = {"on": True}
|
||||||
@ -462,13 +455,6 @@ class HueLight(LightEntity):
|
|||||||
|
|
||||||
await self.coordinator.async_request_refresh()
|
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
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the device state attributes."""
|
"""Return the device state attributes."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user