mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
deCONZ - Revert from using disabled_by when setting options (#31446)
* Revert from using disabled_by when setting options * Remove signalling for changed options * Evaluate allow group option earlier when adding a group
This commit is contained in:
parent
3801d5adf4
commit
fce9697591
@ -8,7 +8,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import ATTR_DARK, ATTR_ON, NEW_SENSOR
|
||||
from .deconz_device import DeconzDevice
|
||||
from .gateway import DeconzEntityHandler, get_gateway_from_config_entry
|
||||
from .gateway import get_gateway_from_config_entry
|
||||
|
||||
ATTR_ORIENTATION = "orientation"
|
||||
ATTR_TILTANGLE = "tiltangle"
|
||||
@ -23,8 +23,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the deCONZ binary sensor."""
|
||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||
|
||||
entity_handler = DeconzEntityHandler(gateway)
|
||||
|
||||
@callback
|
||||
def async_add_sensor(sensors, new=True):
|
||||
"""Add binary sensor from deCONZ."""
|
||||
@ -32,10 +30,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
||||
for sensor in sensors:
|
||||
|
||||
if new and sensor.BINARY:
|
||||
new_sensor = DeconzBinarySensor(sensor, gateway)
|
||||
entity_handler.add_entity(new_sensor)
|
||||
entities.append(new_sensor)
|
||||
if (
|
||||
new
|
||||
and sensor.BINARY
|
||||
and (
|
||||
gateway.option_allow_clip_sensor
|
||||
or not sensor.type.startswith("CLIP")
|
||||
)
|
||||
):
|
||||
entities.append(DeconzBinarySensor(sensor, gateway))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
@ -37,7 +37,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
||||
for sensor in sensors:
|
||||
|
||||
if new and sensor.type in Thermostat.ZHATYPE:
|
||||
if (
|
||||
new
|
||||
and sensor.type in Thermostat.ZHATYPE
|
||||
and (
|
||||
gateway.option_allow_clip_sensor
|
||||
or not sensor.type.startswith("CLIP")
|
||||
)
|
||||
):
|
||||
entities.append(DeconzThermostat(sensor, gateway))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
@ -63,17 +63,6 @@ class DeconzDevice(DeconzBase, Entity):
|
||||
|
||||
Daylight is a virtual sensor from deCONZ that should never be enabled by default.
|
||||
"""
|
||||
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
|
||||
|
||||
if self._device.type == "Daylight":
|
||||
return False
|
||||
|
||||
|
@ -9,14 +9,7 @@ from homeassistant.core import callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
)
|
||||
from homeassistant.helpers.entity_registry import (
|
||||
DISABLED_CONFIG_ENTRY,
|
||||
async_get_registry,
|
||||
)
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
from .const import (
|
||||
CONF_ALLOW_CLIP_SENSOR,
|
||||
@ -116,7 +109,6 @@ class DeconzGateway:
|
||||
self.api.start()
|
||||
|
||||
self.config_entry.add_update_listener(self.async_new_address)
|
||||
self.config_entry.add_update_listener(self.async_options_updated)
|
||||
|
||||
return True
|
||||
|
||||
@ -144,19 +136,6 @@ class DeconzGateway:
|
||||
self.available = available
|
||||
async_dispatcher_send(self.hass, self.signal_reachable, True)
|
||||
|
||||
@property
|
||||
def signal_options_update(self) -> str:
|
||||
"""Event specific per deCONZ entry to signal new options."""
|
||||
return f"deconz-options-{self.bridgeid}"
|
||||
|
||||
@staticmethod
|
||||
async def async_options_updated(hass, entry) -> None:
|
||||
"""Triggered by config entry options updates."""
|
||||
gateway = get_gateway_from_config_entry(hass, entry)
|
||||
|
||||
registry = await async_get_registry(hass)
|
||||
async_dispatcher_send(hass, gateway.signal_options_update, registry)
|
||||
|
||||
@callback
|
||||
def async_signal_new_device(self, device_type) -> str:
|
||||
"""Gateway specific event to signal new device."""
|
||||
@ -227,38 +206,3 @@ async def get_gateway(
|
||||
except (asyncio.TimeoutError, errors.RequestError):
|
||||
LOGGER.error("Error connecting to deCONZ gateway at %s", config[CONF_HOST])
|
||||
raise CannotConnect
|
||||
|
||||
|
||||
class DeconzEntityHandler:
|
||||
"""Platform entity handler to help with updating disabled by."""
|
||||
|
||||
def __init__(self, gateway) -> None:
|
||||
"""Create an entity handler."""
|
||||
self.gateway = gateway
|
||||
self._entities = []
|
||||
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(
|
||||
gateway.hass, gateway.signal_options_update, self.update_entity_registry
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def add_entity(self, entity) -> None:
|
||||
"""Add a new entity to handler."""
|
||||
self._entities.append(entity)
|
||||
|
||||
@callback
|
||||
def update_entity_registry(self, entity_registry) -> None:
|
||||
"""Update entity registry disabled by status."""
|
||||
for entity in self._entities:
|
||||
|
||||
if entity.entity_registry_enabled_default != entity.enabled:
|
||||
disabled_by = None
|
||||
|
||||
if entity.enabled:
|
||||
disabled_by = DISABLED_CONFIG_ENTRY
|
||||
|
||||
entity_registry.async_update_entity(
|
||||
entity.registry_entry.entity_id, disabled_by=disabled_by
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ from .const import (
|
||||
SWITCH_TYPES,
|
||||
)
|
||||
from .deconz_device import DeconzDevice
|
||||
from .gateway import DeconzEntityHandler, get_gateway_from_config_entry
|
||||
from .gateway import get_gateway_from_config_entry
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
@ -41,8 +41,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the deCONZ lights and groups from a config entry."""
|
||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||
|
||||
entity_handler = DeconzEntityHandler(gateway)
|
||||
|
||||
@callback
|
||||
def async_add_light(lights):
|
||||
"""Add light from deCONZ."""
|
||||
@ -63,13 +61,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
@callback
|
||||
def async_add_group(groups):
|
||||
"""Add group from deCONZ."""
|
||||
if not gateway.option_allow_deconz_groups:
|
||||
return
|
||||
|
||||
entities = []
|
||||
|
||||
for group in groups:
|
||||
if group.lights:
|
||||
new_group = DeconzGroup(group, gateway)
|
||||
entity_handler.add_entity(new_group)
|
||||
entities.append(new_group)
|
||||
entities.append(DeconzGroup(group, gateway))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
@ -19,7 +19,7 @@ from homeassistant.helpers.dispatcher import (
|
||||
from .const import ATTR_DARK, ATTR_ON, NEW_SENSOR
|
||||
from .deconz_device import DeconzDevice
|
||||
from .deconz_event import DeconzEvent
|
||||
from .gateway import DeconzEntityHandler, get_gateway_from_config_entry
|
||||
from .gateway import get_gateway_from_config_entry
|
||||
|
||||
ATTR_CURRENT = "current"
|
||||
ATTR_POWER = "power"
|
||||
@ -37,7 +37,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
||||
batteries = set()
|
||||
battery_handler = DeconzBatteryHandler(gateway)
|
||||
entity_handler = DeconzEntityHandler(gateway)
|
||||
|
||||
@callback
|
||||
def async_add_sensor(sensors, new=True):
|
||||
@ -65,11 +64,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
new
|
||||
and sensor.BINARY is False
|
||||
and sensor.type not in Battery.ZHATYPE + Thermostat.ZHATYPE
|
||||
and (
|
||||
gateway.option_allow_clip_sensor
|
||||
or not sensor.type.startswith("CLIP")
|
||||
)
|
||||
):
|
||||
|
||||
new_sensor = DeconzSensor(sensor, gateway)
|
||||
entity_handler.add_entity(new_sensor)
|
||||
entities.append(new_sensor)
|
||||
entities.append(DeconzSensor(sensor, gateway))
|
||||
|
||||
if sensor.battery is not None:
|
||||
new_battery = DeconzBattery(sensor, gateway)
|
||||
|
Loading…
x
Reference in New Issue
Block a user