mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +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 .const import ATTR_DARK, ATTR_ON, NEW_SENSOR
|
||||||
from .deconz_device import DeconzDevice
|
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_ORIENTATION = "orientation"
|
||||||
ATTR_TILTANGLE = "tiltangle"
|
ATTR_TILTANGLE = "tiltangle"
|
||||||
@ -23,8 +23,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
"""Set up the deCONZ binary sensor."""
|
"""Set up the deCONZ binary sensor."""
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||||
|
|
||||||
entity_handler = DeconzEntityHandler(gateway)
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_sensor(sensors, new=True):
|
def async_add_sensor(sensors, new=True):
|
||||||
"""Add binary sensor from deCONZ."""
|
"""Add binary sensor from deCONZ."""
|
||||||
@ -32,10 +30,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
|
|
||||||
for sensor in sensors:
|
for sensor in sensors:
|
||||||
|
|
||||||
if new and sensor.BINARY:
|
if (
|
||||||
new_sensor = DeconzBinarySensor(sensor, gateway)
|
new
|
||||||
entity_handler.add_entity(new_sensor)
|
and sensor.BINARY
|
||||||
entities.append(new_sensor)
|
and (
|
||||||
|
gateway.option_allow_clip_sensor
|
||||||
|
or not sensor.type.startswith("CLIP")
|
||||||
|
)
|
||||||
|
):
|
||||||
|
entities.append(DeconzBinarySensor(sensor, gateway))
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
|
@ -37,7 +37,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
|
|
||||||
for sensor in sensors:
|
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))
|
entities.append(DeconzThermostat(sensor, gateway))
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
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.
|
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":
|
if self._device.type == "Daylight":
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -9,14 +9,7 @@ from homeassistant.core import callback
|
|||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
async_dispatcher_connect,
|
|
||||||
async_dispatcher_send,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.entity_registry import (
|
|
||||||
DISABLED_CONFIG_ENTRY,
|
|
||||||
async_get_registry,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_ALLOW_CLIP_SENSOR,
|
CONF_ALLOW_CLIP_SENSOR,
|
||||||
@ -116,7 +109,6 @@ class DeconzGateway:
|
|||||||
self.api.start()
|
self.api.start()
|
||||||
|
|
||||||
self.config_entry.add_update_listener(self.async_new_address)
|
self.config_entry.add_update_listener(self.async_new_address)
|
||||||
self.config_entry.add_update_listener(self.async_options_updated)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -144,19 +136,6 @@ class DeconzGateway:
|
|||||||
self.available = available
|
self.available = available
|
||||||
async_dispatcher_send(self.hass, self.signal_reachable, True)
|
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
|
@callback
|
||||||
def async_signal_new_device(self, device_type) -> str:
|
def async_signal_new_device(self, device_type) -> str:
|
||||||
"""Gateway specific event to signal new device."""
|
"""Gateway specific event to signal new device."""
|
||||||
@ -227,38 +206,3 @@ async def get_gateway(
|
|||||||
except (asyncio.TimeoutError, errors.RequestError):
|
except (asyncio.TimeoutError, errors.RequestError):
|
||||||
LOGGER.error("Error connecting to deCONZ gateway at %s", config[CONF_HOST])
|
LOGGER.error("Error connecting to deCONZ gateway at %s", config[CONF_HOST])
|
||||||
raise CannotConnect
|
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,
|
SWITCH_TYPES,
|
||||||
)
|
)
|
||||||
from .deconz_device import DeconzDevice
|
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):
|
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."""
|
"""Set up the deCONZ lights and groups from a config entry."""
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||||
|
|
||||||
entity_handler = DeconzEntityHandler(gateway)
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_light(lights):
|
def async_add_light(lights):
|
||||||
"""Add light from deCONZ."""
|
"""Add light from deCONZ."""
|
||||||
@ -63,13 +61,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
@callback
|
@callback
|
||||||
def async_add_group(groups):
|
def async_add_group(groups):
|
||||||
"""Add group from deCONZ."""
|
"""Add group from deCONZ."""
|
||||||
|
if not gateway.option_allow_deconz_groups:
|
||||||
|
return
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for group in groups:
|
for group in groups:
|
||||||
if group.lights:
|
if group.lights:
|
||||||
new_group = DeconzGroup(group, gateway)
|
entities.append(DeconzGroup(group, gateway))
|
||||||
entity_handler.add_entity(new_group)
|
|
||||||
entities.append(new_group)
|
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ from homeassistant.helpers.dispatcher import (
|
|||||||
from .const import ATTR_DARK, ATTR_ON, NEW_SENSOR
|
from .const import ATTR_DARK, ATTR_ON, NEW_SENSOR
|
||||||
from .deconz_device import DeconzDevice
|
from .deconz_device import DeconzDevice
|
||||||
from .deconz_event import DeconzEvent
|
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_CURRENT = "current"
|
||||||
ATTR_POWER = "power"
|
ATTR_POWER = "power"
|
||||||
@ -37,7 +37,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
|
|
||||||
batteries = set()
|
batteries = set()
|
||||||
battery_handler = DeconzBatteryHandler(gateway)
|
battery_handler = DeconzBatteryHandler(gateway)
|
||||||
entity_handler = DeconzEntityHandler(gateway)
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_sensor(sensors, new=True):
|
def async_add_sensor(sensors, new=True):
|
||||||
@ -65,11 +64,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
new
|
new
|
||||||
and sensor.BINARY is False
|
and sensor.BINARY is False
|
||||||
and sensor.type not in Battery.ZHATYPE + Thermostat.ZHATYPE
|
and sensor.type not in Battery.ZHATYPE + Thermostat.ZHATYPE
|
||||||
|
and (
|
||||||
|
gateway.option_allow_clip_sensor
|
||||||
|
or not sensor.type.startswith("CLIP")
|
||||||
|
)
|
||||||
):
|
):
|
||||||
|
entities.append(DeconzSensor(sensor, gateway))
|
||||||
new_sensor = DeconzSensor(sensor, gateway)
|
|
||||||
entity_handler.add_entity(new_sensor)
|
|
||||||
entities.append(new_sensor)
|
|
||||||
|
|
||||||
if sensor.battery is not None:
|
if sensor.battery is not None:
|
||||||
new_battery = DeconzBattery(sensor, gateway)
|
new_battery = DeconzBattery(sensor, gateway)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user