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 authored and GitHub committed 2020-09-29 11:07:19 +02:00
1 parent f3edec1191
commit 7e58bfe01d
8 files changed
+71 -16

No files matched your search

@@ -7,6 +7,7 @@ from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOTION,
DEVICE_CLASS_VIBRATION,
)
from homeassistant.helpers.entity_registry import async_entries_for_config_entry
from homeassistant.setup import async_setup_component
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
@@ -182,3 +183,34 @@ async def test_add_new_binary_sensor(hass):
presence_sensor = hass.states.get("binary_sensor.presence_sensor")
assert presence_sensor.state == "off"
async def test_add_new_binary_sensor_ignored(hass):
"""Test that adding a new binary sensor is not allowed."""
gateway = await setup_deconz_integration(
hass,
options={deconz.gateway.CONF_ALLOW_NEW_DEVICES: False},
)
assert len(hass.states.async_all()) == 0
state_added_event = {
"t": "event",
"e": "added",
"r": "sensors",
"id": "1",
"sensor": deepcopy(SENSORS["1"]),
}
gateway.api.event_handler(state_added_event)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0
entity_registry = await hass.helpers.entity_registry.async_get_registry()
assert (
len(
async_entries_for_config_entry(
entity_registry, gateway.config_entry.entry_id
)
)
== 0
)
+7 -1
View File
@@ -14,6 +14,7 @@ from homeassistant.components.deconz.config_flow import (
from homeassistant.components.deconz.const import (
CONF_ALLOW_CLIP_SENSOR,
CONF_ALLOW_DECONZ_GROUPS,
CONF_ALLOW_NEW_DEVICES,
CONF_MASTER_GATEWAY,
DOMAIN,
)
@@ -561,12 +562,17 @@ async def test_option_flow(hass):
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={CONF_ALLOW_CLIP_SENSOR: False, CONF_ALLOW_DECONZ_GROUPS: False},
user_input={
CONF_ALLOW_CLIP_SENSOR: False,
CONF_ALLOW_DECONZ_GROUPS: False,
CONF_ALLOW_NEW_DEVICES: False,
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"] == {
CONF_ALLOW_CLIP_SENSOR: False,
CONF_ALLOW_DECONZ_GROUPS: False,
CONF_ALLOW_NEW_DEVICES: False,
CONF_MASTER_GATEWAY: True,
}
+1
View File
@@ -81,6 +81,7 @@ async def test_gateway_setup(hass):
assert gateway.master is True
assert gateway.option_allow_clip_sensor is False
assert gateway.option_allow_deconz_groups is True
assert gateway.option_allow_new_devices is True
assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0