Update Hue data fetching (#31338)
* Refactor Hue Lights to use DataCoordinator * Redo how Hue updates data * Address comments * Inherit from Entity and remove pylint disable * Add tests for debounce
This commit is contained in:
parent
ae76b5be5a
commit
166d770ddd
15 changed files with 549 additions and 355 deletions
|
@ -6,27 +6,18 @@ from homeassistant.components.binary_sensor import (
|
|||
DEVICE_CLASS_MOTION,
|
||||
BinarySensorDevice,
|
||||
)
|
||||
from homeassistant.components.hue.sensor_base import (
|
||||
GenericZLLSensor,
|
||||
SensorManager,
|
||||
async_setup_entry as shared_async_setup_entry,
|
||||
)
|
||||
|
||||
from .const import DOMAIN as HUE_DOMAIN
|
||||
from .sensor_base import SENSOR_CONFIG_MAP, GenericZLLSensor
|
||||
|
||||
PRESENCE_NAME_FORMAT = "{} motion"
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Defer binary sensor setup to the shared sensor module."""
|
||||
SensorManager.sensor_config_map.update(
|
||||
{
|
||||
TYPE_ZLL_PRESENCE: {
|
||||
"binary": True,
|
||||
"name_format": PRESENCE_NAME_FORMAT,
|
||||
"class": HuePresence,
|
||||
}
|
||||
}
|
||||
)
|
||||
await shared_async_setup_entry(hass, config_entry, async_add_entities, binary=True)
|
||||
await hass.data[HUE_DOMAIN][
|
||||
config_entry.entry_id
|
||||
].sensor_manager.async_register_component(True, async_add_entities)
|
||||
|
||||
|
||||
class HuePresence(GenericZLLSensor, BinarySensorDevice):
|
||||
|
@ -34,9 +25,6 @@ class HuePresence(GenericZLLSensor, BinarySensorDevice):
|
|||
|
||||
device_class = DEVICE_CLASS_MOTION
|
||||
|
||||
async def _async_update_ha_state(self, *args, **kwargs):
|
||||
await self.async_update_ha_state(self, *args, **kwargs)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if the binary sensor is on."""
|
||||
|
@ -51,3 +39,14 @@ class HuePresence(GenericZLLSensor, BinarySensorDevice):
|
|||
if "sensitivitymax" in self.sensor.config:
|
||||
attributes["sensitivity_max"] = self.sensor.config["sensitivitymax"]
|
||||
return attributes
|
||||
|
||||
|
||||
SENSOR_CONFIG_MAP.update(
|
||||
{
|
||||
TYPE_ZLL_PRESENCE: {
|
||||
"binary": True,
|
||||
"name_format": PRESENCE_NAME_FORMAT,
|
||||
"class": HuePresence,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue