mirror of
https://github.com/home-assistant/core.git
synced 2025-12-27 06:28:31 +00:00
deCONZ - use entity registry disabled_by to control available entities (#26219)
* First draft * Support enabling disabled entities * Clean up * Move import * Local entity enabled replaced during rebase * Add option flow test * Mark options properties with option
This commit is contained in:
committed by
Paulus Schoutsen
parent
b1c2a5fa08
commit
518d2c31bb
@@ -14,21 +14,40 @@ class DeconzDevice(Entity):
|
||||
"""Set up device and add update callback to get data from websocket."""
|
||||
self._device = device
|
||||
self.gateway = gateway
|
||||
self.unsub_dispatcher = None
|
||||
self.listeners = []
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self):
|
||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||
if not self.gateway.option_allow_clip_sensor and self._device.type.startswith(
|
||||
"CLIP"
|
||||
):
|
||||
return False
|
||||
|
||||
if (
|
||||
not self.gateway.option_allow_deconz_groups
|
||||
and self._device.type == "LightGroup"
|
||||
):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to device events."""
|
||||
self._device.register_async_callback(self.async_update_callback)
|
||||
self.gateway.deconz_ids[self.entity_id] = self._device.deconz_id
|
||||
self.unsub_dispatcher = async_dispatcher_connect(
|
||||
self.hass, self.gateway.event_reachable, self.async_update_callback
|
||||
self.listeners.append(
|
||||
async_dispatcher_connect(
|
||||
self.hass, self.gateway.signal_reachable, self.async_update_callback
|
||||
)
|
||||
)
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Disconnect device object when removed."""
|
||||
self._device.remove_callback(self.async_update_callback)
|
||||
del self.gateway.deconz_ids[self.entity_id]
|
||||
self.unsub_dispatcher()
|
||||
for unsub_dispatcher in self.listeners:
|
||||
unsub_dispatcher()
|
||||
|
||||
@callback
|
||||
def async_update_callback(self, force_update=False):
|
||||
|
||||
Reference in New Issue
Block a user