Library refactorization of deCONZ (#23725)
* Improved sensors * Lib update signalling * Replace reason with changed * Move imports to top of file * Add support for secondary temperature reported by some Xiaomi devices * Bump dependency to v59
This commit is contained in:
1 parent
0ba54ee9b7
commit
31b2f331db
19 files changed
+104
-83
No files matched your search
@@ -1,6 +1,8 @@
|
||||
"""deCONZ binary sensor platform tests."""
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import deconz
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
@@ -8,8 +10,6 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
import homeassistant.components.binary_sensor as binary_sensor
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
|
||||
SENSOR = {
|
||||
"1": {
|
||||
@@ -104,6 +104,7 @@ async def test_add_new_sensor(hass):
|
||||
sensor = Mock()
|
||||
sensor.name = 'name'
|
||||
sensor.type = 'ZHAPresence'
|
||||
sensor.BINARY = True
|
||||
sensor.register_async_callback = Mock()
|
||||
async_dispatcher_send(
|
||||
hass, gateway.async_event_new_device('sensor'), [sensor])
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""deCONZ climate platform tests."""
|
||||
from copy import deepcopy
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import asynctest
|
||||
@@ -18,9 +19,9 @@ SENSOR = {
|
||||
"id": "Climate 1 id",
|
||||
"name": "Climate 1 name",
|
||||
"type": "ZHAThermostat",
|
||||
"state": {"on": True, "temperature": 2260},
|
||||
"state": {"on": True, "temperature": 2260, "valve": 30},
|
||||
"config": {"battery": 100, "heatsetpoint": 2200, "mode": "auto",
|
||||
"offset": 10, "reachable": True, "valve": 30},
|
||||
"offset": 10, "reachable": True},
|
||||
"uniqueid": "00:00:00:00:00:00:00:00-00"
|
||||
},
|
||||
"2": {
|
||||
@@ -97,7 +98,7 @@ async def test_no_sensors(hass):
|
||||
|
||||
async def test_climate_devices(hass):
|
||||
"""Test successful creation of sensor entities."""
|
||||
gateway = await setup_gateway(hass, {"sensors": SENSOR})
|
||||
gateway = await setup_gateway(hass, {"sensors": deepcopy(SENSOR)})
|
||||
assert "climate.climate_1_name" in gateway.deconz_ids
|
||||
assert "sensor.sensor_2_name" not in gateway.deconz_ids
|
||||
assert len(hass.states.async_all()) == 1
|
||||
@@ -138,7 +139,7 @@ async def test_climate_devices(hass):
|
||||
|
||||
async def test_verify_state_update(hass):
|
||||
"""Test that state update properly."""
|
||||
gateway = await setup_gateway(hass, {"sensors": SENSOR})
|
||||
gateway = await setup_gateway(hass, {"sensors": deepcopy(SENSOR)})
|
||||
assert "climate.climate_1_name" in gateway.deconz_ids
|
||||
|
||||
thermostat = hass.states.get('climate.climate_1_name')
|
||||
@@ -149,7 +150,7 @@ async def test_verify_state_update(hass):
|
||||
"e": "changed",
|
||||
"r": "sensors",
|
||||
"id": "1",
|
||||
"config": {"on": False}
|
||||
"state": {"on": False}
|
||||
}
|
||||
gateway.api.async_event_handler(state_update)
|
||||
|
||||
@@ -158,6 +159,8 @@ async def test_verify_state_update(hass):
|
||||
|
||||
thermostat = hass.states.get('climate.climate_1_name')
|
||||
assert thermostat.state == 'off'
|
||||
assert gateway.api.sensors['1'].changed_keys == \
|
||||
{'state', 'r', 't', 'on', 'e', 'id'}
|
||||
|
||||
|
||||
async def test_add_new_climate_device(hass):
|
||||
|
||||
@@ -43,7 +43,7 @@ async def test_flow_works(hass, aioclient_mock):
|
||||
|
||||
async def test_user_step_bridge_discovery_fails(hass, aioclient_mock):
|
||||
"""Test config flow works when discovery fails."""
|
||||
with patch('pydeconz.utils.async_discovery',
|
||||
with patch('homeassistant.components.deconz.config_flow.async_discovery',
|
||||
side_effect=asyncio.TimeoutError):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
@@ -158,8 +158,9 @@ async def test_link_no_api_key(hass):
|
||||
config_flow.CONF_PORT: 80
|
||||
}
|
||||
|
||||
with patch('pydeconz.utils.async_get_api_key',
|
||||
side_effect=pydeconz.errors.ResponseError):
|
||||
with patch(
|
||||
'homeassistant.components.deconz.config_flow.async_get_api_key',
|
||||
side_effect=pydeconz.errors.ResponseError):
|
||||
result = await flow.async_step_link(user_input={})
|
||||
|
||||
assert result['type'] == 'form'
|
||||
@@ -275,8 +276,9 @@ async def test_create_entry_timeout(hass, aioclient_mock):
|
||||
config_flow.CONF_API_KEY: '1234567890ABCDEF'
|
||||
}
|
||||
|
||||
with patch('pydeconz.utils.async_get_bridgeid',
|
||||
side_effect=asyncio.TimeoutError):
|
||||
with patch(
|
||||
'homeassistant.components.deconz.config_flow.async_get_bridgeid',
|
||||
side_effect=asyncio.TimeoutError):
|
||||
result = await flow._create_entry()
|
||||
|
||||
assert result['type'] == 'abort'
|
||||
|
||||
@@ -223,7 +223,8 @@ async def test_update_event():
|
||||
remote.name = 'Name'
|
||||
|
||||
event = gateway.DeconzEvent(hass, remote)
|
||||
event.async_update_callback({'state': True})
|
||||
remote.changed_keys = {'state': True}
|
||||
event.async_update_callback()
|
||||
|
||||
assert len(hass.bus.async_fire.mock_calls) == 1
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""deCONZ sensor platform tests."""
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import deconz
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
@@ -8,8 +10,6 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
import homeassistant.components.sensor as sensor
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
|
||||
SENSOR = {
|
||||
"1": {
|
||||
@@ -142,6 +142,7 @@ async def test_add_new_sensor(hass):
|
||||
sensor = Mock()
|
||||
sensor.name = 'name'
|
||||
sensor.type = 'ZHATemperature'
|
||||
sensor.BINARY = False
|
||||
sensor.register_async_callback = Mock()
|
||||
async_dispatcher_send(
|
||||
hass, gateway.async_event_new_device('sensor'), [sensor])
|
||||
|
||||
Reference in new issue
Block a user