deCONZ add new device without restart (#14221)
* Add new device without restarting hass * Remove debug prints * Fix copy paste error * Fix comments from balloob Add tests to verify signalling with new added devices * Fix hound comments Add test to verify when new sensor is added * Fix tests * Unload entry should unsubscribe all deconz dispatchers * Make sure mock setup also creates unsub in hass data * Fix copy paste issue * Lint
This commit is contained in:
1 parent
af8cd63838
commit
8410b63d9c
11 files changed
+212
-48
No files matched your search
@@ -3,6 +3,7 @@ from unittest.mock import Mock, patch
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import deconz
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
@@ -14,6 +15,13 @@ SENSOR = {
|
||||
"type": "ZHAPresence",
|
||||
"state": {"presence": False},
|
||||
"config": {}
|
||||
},
|
||||
"2": {
|
||||
"id": "Sensor 2 id",
|
||||
"name": "Sensor 2 name",
|
||||
"type": "ZHATemperature",
|
||||
"state": {"temperature": False},
|
||||
"config": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +38,7 @@ async def setup_bridge(hass, data):
|
||||
return_value=mock_coro(data)):
|
||||
await bridge.async_load_parameters()
|
||||
hass.data[deconz.DOMAIN] = bridge
|
||||
hass.data[deconz.DATA_DECONZ_UNSUB] = []
|
||||
hass.data[deconz.DATA_DECONZ_ID] = {}
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
1, deconz.DOMAIN, 'Mock Title', {'host': 'mock-host'}, 'test')
|
||||
@@ -40,7 +49,7 @@ async def setup_bridge(hass, data):
|
||||
|
||||
|
||||
async def test_no_binary_sensors(hass):
|
||||
"""Test the update_lights function with some lights."""
|
||||
"""Test that no sensors in deconz results in no sensor entities."""
|
||||
data = {}
|
||||
await setup_bridge(hass, data)
|
||||
assert len(hass.data[deconz.DATA_DECONZ_ID]) == 0
|
||||
@@ -48,8 +57,23 @@ async def test_no_binary_sensors(hass):
|
||||
|
||||
|
||||
async def test_binary_sensors(hass):
|
||||
"""Test the update_lights function with some lights."""
|
||||
"""Test successful creation of binary sensor entities."""
|
||||
data = {"sensors": SENSOR}
|
||||
await setup_bridge(hass, data)
|
||||
assert "binary_sensor.sensor_1_name" in hass.data[deconz.DATA_DECONZ_ID]
|
||||
assert "binary_sensor.sensor_2_name" not in \
|
||||
hass.data[deconz.DATA_DECONZ_ID]
|
||||
assert len(hass.states.async_all()) == 1
|
||||
|
||||
|
||||
async def test_add_new_sensor(hass):
|
||||
"""Test successful creation of sensor entities."""
|
||||
data = {}
|
||||
await setup_bridge(hass, data)
|
||||
sensor = Mock()
|
||||
sensor.name = 'name'
|
||||
sensor.type = 'ZHAPresence'
|
||||
sensor.register_async_callback = Mock()
|
||||
async_dispatcher_send(hass, 'deconz_new_sensor', [sensor])
|
||||
await hass.async_block_till_done()
|
||||
assert "binary_sensor.name" in hass.data[deconz.DATA_DECONZ_ID]
|
||||
Reference in new issue
Block a user