Add deconz option to disable automatic addition of new devices (#40545)
* Allow disabling automatic additions of new devices from deconz * Fix black * Fix review comment * Remove assertion * Verify entity registry is empty
This commit is contained in:
parent
f3edec1191
commit
7e58bfe01d
8 changed files with 71 additions and 16 deletions
|
@ -14,9 +14,11 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
|||
from .const import (
|
||||
CONF_ALLOW_CLIP_SENSOR,
|
||||
CONF_ALLOW_DECONZ_GROUPS,
|
||||
CONF_ALLOW_NEW_DEVICES,
|
||||
CONF_MASTER_GATEWAY,
|
||||
DEFAULT_ALLOW_CLIP_SENSOR,
|
||||
DEFAULT_ALLOW_DECONZ_GROUPS,
|
||||
DEFAULT_ALLOW_NEW_DEVICES,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
NEW_GROUP,
|
||||
|
@ -78,6 +80,13 @@ class DeconzGateway:
|
|||
CONF_ALLOW_DECONZ_GROUPS, DEFAULT_ALLOW_DECONZ_GROUPS
|
||||
)
|
||||
|
||||
@property
|
||||
def option_allow_new_devices(self) -> bool:
|
||||
"""Allow automatic adding of new devices."""
|
||||
return self.config_entry.options.get(
|
||||
CONF_ALLOW_NEW_DEVICES, DEFAULT_ALLOW_NEW_DEVICES
|
||||
)
|
||||
|
||||
async def async_update_device_registry(self) -> None:
|
||||
"""Update device registry."""
|
||||
device_registry = await self.hass.helpers.device_registry.async_get_registry()
|
||||
|
@ -204,8 +213,12 @@ class DeconzGateway:
|
|||
@callback
|
||||
def async_add_device_callback(self, device_type, device) -> None:
|
||||
"""Handle event of new device creation in deCONZ."""
|
||||
if not self.option_allow_new_devices:
|
||||
return
|
||||
|
||||
if not isinstance(device, list):
|
||||
device = [device]
|
||||
|
||||
async_dispatcher_send(
|
||||
self.hass, self.async_signal_new_device(device_type), device
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue