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
@@ -1,8 +1,10 @@
|
||||
"""deCONZ sensor platform tests."""
|
||||
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
|
||||
|
||||
@@ -51,6 +53,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_EVENT] = []
|
||||
hass.data[deconz.DATA_DECONZ_ID] = {}
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
@@ -61,15 +64,15 @@ async def setup_bridge(hass, data):
|
||||
|
||||
|
||||
async def test_no_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
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
async def test_binary_sensors(hass):
|
||||
"""Test the update_lights function with some lights."""
|
||||
async def test_sensors(hass):
|
||||
"""Test successful creation of sensor entities."""
|
||||
data = {"sensors": SENSOR}
|
||||
await setup_bridge(hass, data)
|
||||
assert "sensor.sensor_1_name" in hass.data[deconz.DATA_DECONZ_ID]
|
||||
@@ -81,3 +84,16 @@ async def test_binary_sensors(hass):
|
||||
assert "sensor.sensor_4_name_battery_level" in \
|
||||
hass.data[deconz.DATA_DECONZ_ID]
|
||||
assert len(hass.states.async_all()) == 2
|
||||
|
||||
|
||||
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 = 'ZHATemperature'
|
||||
sensor.register_async_callback = Mock()
|
||||
async_dispatcher_send(hass, 'deconz_new_sensor', [sensor])
|
||||
await hass.async_block_till_done()
|
||||
assert "sensor.name" in hass.data[deconz.DATA_DECONZ_ID]
|
||||
Reference in new issue
Block a user