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:
Robert Svensson 2020-09-29 11:07:19 +02:00 committed by GitHub
parent f3edec1191
commit 7e58bfe01d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 71 additions and 16 deletions

View file

@ -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
)