Use websocket fixture in deCONZ climate tests (#47821)
Localize test data Improve asserts
This commit is contained in:
parent
fea0e39fa0
commit
2ab640aaef
1 changed files with 261 additions and 225 deletions
|
@ -1,6 +1,6 @@
|
||||||
"""deCONZ climate platform tests."""
|
"""deCONZ climate platform tests."""
|
||||||
|
|
||||||
from copy import deepcopy
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -27,14 +27,18 @@ from homeassistant.components.climate.const import (
|
||||||
HVAC_MODE_COOL,
|
HVAC_MODE_COOL,
|
||||||
HVAC_MODE_HEAT,
|
HVAC_MODE_HEAT,
|
||||||
HVAC_MODE_OFF,
|
HVAC_MODE_OFF,
|
||||||
|
PRESET_BOOST,
|
||||||
PRESET_COMFORT,
|
PRESET_COMFORT,
|
||||||
|
PRESET_ECO,
|
||||||
)
|
)
|
||||||
from homeassistant.components.deconz.climate import (
|
from homeassistant.components.deconz.climate import (
|
||||||
DECONZ_FAN_SMART,
|
DECONZ_FAN_SMART,
|
||||||
|
DECONZ_PRESET_AUTO,
|
||||||
|
DECONZ_PRESET_COMPLEX,
|
||||||
|
DECONZ_PRESET_HOLIDAY,
|
||||||
DECONZ_PRESET_MANUAL,
|
DECONZ_PRESET_MANUAL,
|
||||||
)
|
)
|
||||||
from homeassistant.components.deconz.const import CONF_ALLOW_CLIP_SENSOR
|
from homeassistant.components.deconz.const import CONF_ALLOW_CLIP_SENSOR
|
||||||
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
|
@ -48,31 +52,6 @@ from .test_gateway import (
|
||||||
setup_deconz_integration,
|
setup_deconz_integration,
|
||||||
)
|
)
|
||||||
|
|
||||||
SENSORS = {
|
|
||||||
"1": {
|
|
||||||
"id": "Thermostat id",
|
|
||||||
"name": "Thermostat",
|
|
||||||
"type": "ZHAThermostat",
|
|
||||||
"state": {"on": True, "temperature": 2260, "valve": 30},
|
|
||||||
"config": {
|
|
||||||
"battery": 100,
|
|
||||||
"heatsetpoint": 2200,
|
|
||||||
"mode": "auto",
|
|
||||||
"offset": 10,
|
|
||||||
"reachable": True,
|
|
||||||
},
|
|
||||||
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
|
||||||
},
|
|
||||||
"2": {
|
|
||||||
"id": "CLIP thermostat id",
|
|
||||||
"name": "CLIP thermostat",
|
|
||||||
"type": "CLIPThermostat",
|
|
||||||
"state": {"on": True, "temperature": 2260, "valve": 30},
|
|
||||||
"config": {"reachable": True},
|
|
||||||
"uniqueid": "00:00:00:00:00:00:00:02-00",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_no_sensors(hass, aioclient_mock):
|
async def test_no_sensors(hass, aioclient_mock):
|
||||||
"""Test that no sensors in deconz results in no climate entities."""
|
"""Test that no sensors in deconz results in no climate entities."""
|
||||||
|
@ -80,48 +59,47 @@ async def test_no_sensors(hass, aioclient_mock):
|
||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_simple_climate_device(hass, aioclient_mock):
|
async def test_simple_climate_device(hass, aioclient_mock, mock_deconz_websocket):
|
||||||
"""Test successful creation of climate entities.
|
"""Test successful creation of climate entities.
|
||||||
|
|
||||||
This is a simple water heater that only supports setting temperature and on and off.
|
This is a simple water heater that only supports setting temperature and on and off.
|
||||||
"""
|
"""
|
||||||
data = deepcopy(DECONZ_WEB_REQUEST)
|
data = {
|
||||||
data["sensors"] = {
|
"sensors": {
|
||||||
"0": {
|
"0": {
|
||||||
"config": {
|
"config": {
|
||||||
"battery": 59,
|
"battery": 59,
|
||||||
"displayflipped": None,
|
"displayflipped": None,
|
||||||
"heatsetpoint": 2100,
|
"heatsetpoint": 2100,
|
||||||
"locked": True,
|
"locked": True,
|
||||||
"mountingmode": None,
|
"mountingmode": None,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"on": True,
|
"on": True,
|
||||||
"reachable": True,
|
"reachable": True,
|
||||||
},
|
},
|
||||||
"ep": 1,
|
"ep": 1,
|
||||||
"etag": "6130553ac247174809bae47144ee23f8",
|
"etag": "6130553ac247174809bae47144ee23f8",
|
||||||
"lastseen": "2020-11-29T19:31Z",
|
"lastseen": "2020-11-29T19:31Z",
|
||||||
"manufacturername": "Danfoss",
|
"manufacturername": "Danfoss",
|
||||||
"modelid": "eTRV0100",
|
"modelid": "eTRV0100",
|
||||||
"name": "thermostat",
|
"name": "thermostat",
|
||||||
"state": {
|
"state": {
|
||||||
"errorcode": None,
|
"errorcode": None,
|
||||||
"lastupdated": "2020-11-29T19:28:40.665",
|
"lastupdated": "2020-11-29T19:28:40.665",
|
||||||
"mountingmodeactive": False,
|
"mountingmodeactive": False,
|
||||||
"on": True,
|
"on": True,
|
||||||
"temperature": 2102,
|
"temperature": 2102,
|
||||||
"valve": 24,
|
"valve": 24,
|
||||||
"windowopen": "Closed",
|
"windowopen": "Closed",
|
||||||
},
|
},
|
||||||
"swversion": "01.02.0008 01.02",
|
"swversion": "01.02.0008 01.02",
|
||||||
"type": "ZHAThermostat",
|
"type": "ZHAThermostat",
|
||||||
"uniqueid": "14:b4:57:ff:fe:d5:4e:77-01-0201",
|
"uniqueid": "14:b4:57:ff:fe:d5:4e:77-01-0201",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config_entry = await setup_deconz_integration(
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
hass, aioclient_mock, get_state_response=data
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
)
|
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 2
|
assert len(hass.states.async_all()) == 2
|
||||||
climate_thermostat = hass.states.get("climate.thermostat")
|
climate_thermostat = hass.states.get("climate.thermostat")
|
||||||
|
@ -137,28 +115,28 @@ async def test_simple_climate_device(hass, aioclient_mock):
|
||||||
|
|
||||||
# Event signals thermostat configured off
|
# Event signals thermostat configured off
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "0",
|
"id": "0",
|
||||||
"state": {"on": False},
|
"state": {"on": False},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.thermostat").state == STATE_OFF
|
assert hass.states.get("climate.thermostat").state == STATE_OFF
|
||||||
|
|
||||||
# Event signals thermostat state on
|
# Event signals thermostat state on
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "0",
|
"id": "0",
|
||||||
"state": {"on": True},
|
"state": {"on": True},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.thermostat").state == HVAC_MODE_HEAT
|
assert hass.states.get("climate.thermostat").state == HVAC_MODE_HEAT
|
||||||
|
@ -198,14 +176,29 @@ async def test_simple_climate_device(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_climate_device_without_cooling_support(hass, aioclient_mock):
|
async def test_climate_device_without_cooling_support(
|
||||||
|
hass, aioclient_mock, mock_deconz_websocket
|
||||||
|
):
|
||||||
"""Test successful creation of sensor entities."""
|
"""Test successful creation of sensor entities."""
|
||||||
data = deepcopy(DECONZ_WEB_REQUEST)
|
data = {
|
||||||
data["sensors"] = deepcopy(SENSORS)
|
"sensors": {
|
||||||
config_entry = await setup_deconz_integration(
|
"1": {
|
||||||
hass, aioclient_mock, get_state_response=data
|
"name": "Thermostat",
|
||||||
)
|
"type": "ZHAThermostat",
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
"state": {"on": True, "temperature": 2260, "valve": 30},
|
||||||
|
"config": {
|
||||||
|
"battery": 100,
|
||||||
|
"heatsetpoint": 2200,
|
||||||
|
"mode": "auto",
|
||||||
|
"offset": 10,
|
||||||
|
"reachable": True,
|
||||||
|
},
|
||||||
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 2
|
assert len(hass.states.async_all()) == 2
|
||||||
climate_thermostat = hass.states.get("climate.thermostat")
|
climate_thermostat = hass.states.get("climate.thermostat")
|
||||||
|
@ -224,21 +217,21 @@ async def test_climate_device_without_cooling_support(hass, aioclient_mock):
|
||||||
|
|
||||||
# Event signals thermostat configured off
|
# Event signals thermostat configured off
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"config": {"mode": "off"},
|
"config": {"mode": "off"},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.thermostat").state == STATE_OFF
|
assert hass.states.get("climate.thermostat").state == STATE_OFF
|
||||||
|
|
||||||
# Event signals thermostat state on
|
# Event signals thermostat state on
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
|
@ -246,21 +239,21 @@ async def test_climate_device_without_cooling_support(hass, aioclient_mock):
|
||||||
"config": {"mode": "other"},
|
"config": {"mode": "other"},
|
||||||
"state": {"on": True},
|
"state": {"on": True},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.thermostat").state == HVAC_MODE_HEAT
|
assert hass.states.get("climate.thermostat").state == HVAC_MODE_HEAT
|
||||||
|
|
||||||
# Event signals thermostat state off
|
# Event signals thermostat state off
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"state": {"on": False},
|
"state": {"on": False},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.thermostat").state == STATE_OFF
|
assert hass.states.get("climate.thermostat").state == STATE_OFF
|
||||||
|
@ -336,7 +329,7 @@ async def test_climate_device_without_cooling_support(hass, aioclient_mock):
|
||||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
await hass.config_entries.async_unload(config_entry.entry_id)
|
||||||
|
|
||||||
states = hass.states.async_all()
|
states = hass.states.async_all()
|
||||||
assert len(hass.states.async_all()) == 2
|
assert len(states) == 2
|
||||||
for state in states:
|
for state in states:
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
@ -345,40 +338,41 @@ async def test_climate_device_without_cooling_support(hass, aioclient_mock):
|
||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_climate_device_with_cooling_support(hass, aioclient_mock):
|
async def test_climate_device_with_cooling_support(
|
||||||
|
hass, aioclient_mock, mock_deconz_websocket
|
||||||
|
):
|
||||||
"""Test successful creation of sensor entities."""
|
"""Test successful creation of sensor entities."""
|
||||||
data = deepcopy(DECONZ_WEB_REQUEST)
|
data = {
|
||||||
data["sensors"] = {
|
"sensors": {
|
||||||
"0": {
|
"0": {
|
||||||
"config": {
|
"config": {
|
||||||
"battery": 25,
|
"battery": 25,
|
||||||
"coolsetpoint": None,
|
"coolsetpoint": None,
|
||||||
"fanmode": None,
|
"fanmode": None,
|
||||||
"heatsetpoint": 2222,
|
"heatsetpoint": 2222,
|
||||||
"mode": "heat",
|
"mode": "heat",
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"on": True,
|
"on": True,
|
||||||
"reachable": True,
|
"reachable": True,
|
||||||
},
|
},
|
||||||
"ep": 1,
|
"ep": 1,
|
||||||
"etag": "074549903686a77a12ef0f06c499b1ef",
|
"etag": "074549903686a77a12ef0f06c499b1ef",
|
||||||
"lastseen": "2020-11-27T13:45Z",
|
"lastseen": "2020-11-27T13:45Z",
|
||||||
"manufacturername": "Zen Within",
|
"manufacturername": "Zen Within",
|
||||||
"modelid": "Zen-01",
|
"modelid": "Zen-01",
|
||||||
"name": "Zen-01",
|
"name": "Zen-01",
|
||||||
"state": {
|
"state": {
|
||||||
"lastupdated": "2020-11-27T13:42:40.863",
|
"lastupdated": "2020-11-27T13:42:40.863",
|
||||||
"on": False,
|
"on": False,
|
||||||
"temperature": 2320,
|
"temperature": 2320,
|
||||||
},
|
},
|
||||||
"type": "ZHAThermostat",
|
"type": "ZHAThermostat",
|
||||||
"uniqueid": "00:24:46:00:00:11:6f:56-01-0201",
|
"uniqueid": "00:24:46:00:00:11:6f:56-01-0201",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config_entry = await setup_deconz_integration(
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
hass, aioclient_mock, get_state_response=data
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
)
|
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 2
|
assert len(hass.states.async_all()) == 2
|
||||||
climate_thermostat = hass.states.get("climate.zen_01")
|
climate_thermostat = hass.states.get("climate.zen_01")
|
||||||
|
@ -395,14 +389,14 @@ async def test_climate_device_with_cooling_support(hass, aioclient_mock):
|
||||||
|
|
||||||
# Event signals thermostat state cool
|
# Event signals thermostat state cool
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "0",
|
"id": "0",
|
||||||
"config": {"mode": "cool"},
|
"config": {"mode": "cool"},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.zen_01").state == HVAC_MODE_COOL
|
assert hass.states.get("climate.zen_01").state == HVAC_MODE_COOL
|
||||||
|
@ -422,40 +416,41 @@ async def test_climate_device_with_cooling_support(hass, aioclient_mock):
|
||||||
assert aioclient_mock.mock_calls[1][2] == {"coolsetpoint": 2000.0}
|
assert aioclient_mock.mock_calls[1][2] == {"coolsetpoint": 2000.0}
|
||||||
|
|
||||||
|
|
||||||
async def test_climate_device_with_fan_support(hass, aioclient_mock):
|
async def test_climate_device_with_fan_support(
|
||||||
|
hass, aioclient_mock, mock_deconz_websocket
|
||||||
|
):
|
||||||
"""Test successful creation of sensor entities."""
|
"""Test successful creation of sensor entities."""
|
||||||
data = deepcopy(DECONZ_WEB_REQUEST)
|
data = {
|
||||||
data["sensors"] = {
|
"sensors": {
|
||||||
"0": {
|
"0": {
|
||||||
"config": {
|
"config": {
|
||||||
"battery": 25,
|
"battery": 25,
|
||||||
"coolsetpoint": None,
|
"coolsetpoint": None,
|
||||||
"fanmode": "auto",
|
"fanmode": "auto",
|
||||||
"heatsetpoint": 2222,
|
"heatsetpoint": 2222,
|
||||||
"mode": "heat",
|
"mode": "heat",
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"on": True,
|
"on": True,
|
||||||
"reachable": True,
|
"reachable": True,
|
||||||
},
|
},
|
||||||
"ep": 1,
|
"ep": 1,
|
||||||
"etag": "074549903686a77a12ef0f06c499b1ef",
|
"etag": "074549903686a77a12ef0f06c499b1ef",
|
||||||
"lastseen": "2020-11-27T13:45Z",
|
"lastseen": "2020-11-27T13:45Z",
|
||||||
"manufacturername": "Zen Within",
|
"manufacturername": "Zen Within",
|
||||||
"modelid": "Zen-01",
|
"modelid": "Zen-01",
|
||||||
"name": "Zen-01",
|
"name": "Zen-01",
|
||||||
"state": {
|
"state": {
|
||||||
"lastupdated": "2020-11-27T13:42:40.863",
|
"lastupdated": "2020-11-27T13:42:40.863",
|
||||||
"on": False,
|
"on": False,
|
||||||
"temperature": 2320,
|
"temperature": 2320,
|
||||||
},
|
},
|
||||||
"type": "ZHAThermostat",
|
"type": "ZHAThermostat",
|
||||||
"uniqueid": "00:24:46:00:00:11:6f:56-01-0201",
|
"uniqueid": "00:24:46:00:00:11:6f:56-01-0201",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config_entry = await setup_deconz_integration(
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
hass, aioclient_mock, get_state_response=data
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
)
|
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 2
|
assert len(hass.states.async_all()) == 2
|
||||||
climate_thermostat = hass.states.get("climate.zen_01")
|
climate_thermostat = hass.states.get("climate.zen_01")
|
||||||
|
@ -473,21 +468,21 @@ async def test_climate_device_with_fan_support(hass, aioclient_mock):
|
||||||
|
|
||||||
# Event signals fan mode defaults to off
|
# Event signals fan mode defaults to off
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "0",
|
"id": "0",
|
||||||
"config": {"fanmode": "unsupported"},
|
"config": {"fanmode": "unsupported"},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_OFF
|
assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_OFF
|
||||||
|
|
||||||
# Event signals unsupported fan mode
|
# Event signals unsupported fan mode
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
|
@ -495,21 +490,21 @@ async def test_climate_device_with_fan_support(hass, aioclient_mock):
|
||||||
"config": {"fanmode": "unsupported"},
|
"config": {"fanmode": "unsupported"},
|
||||||
"state": {"on": True},
|
"state": {"on": True},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_ON
|
assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_ON
|
||||||
|
|
||||||
# Event signals unsupported fan mode
|
# Event signals unsupported fan mode
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "0",
|
"id": "0",
|
||||||
"config": {"fanmode": "unsupported"},
|
"config": {"fanmode": "unsupported"},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_ON
|
assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_ON
|
||||||
|
@ -549,41 +544,40 @@ async def test_climate_device_with_fan_support(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_climate_device_with_preset(hass, aioclient_mock):
|
async def test_climate_device_with_preset(hass, aioclient_mock, mock_deconz_websocket):
|
||||||
"""Test successful creation of sensor entities."""
|
"""Test successful creation of sensor entities."""
|
||||||
data = deepcopy(DECONZ_WEB_REQUEST)
|
data = {
|
||||||
data["sensors"] = {
|
"sensors": {
|
||||||
"0": {
|
"0": {
|
||||||
"config": {
|
"config": {
|
||||||
"battery": 25,
|
"battery": 25,
|
||||||
"coolsetpoint": None,
|
"coolsetpoint": None,
|
||||||
"fanmode": None,
|
"fanmode": None,
|
||||||
"heatsetpoint": 2222,
|
"heatsetpoint": 2222,
|
||||||
"mode": "heat",
|
"mode": "heat",
|
||||||
"preset": "auto",
|
"preset": "auto",
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"on": True,
|
"on": True,
|
||||||
"reachable": True,
|
"reachable": True,
|
||||||
},
|
},
|
||||||
"ep": 1,
|
"ep": 1,
|
||||||
"etag": "074549903686a77a12ef0f06c499b1ef",
|
"etag": "074549903686a77a12ef0f06c499b1ef",
|
||||||
"lastseen": "2020-11-27T13:45Z",
|
"lastseen": "2020-11-27T13:45Z",
|
||||||
"manufacturername": "Zen Within",
|
"manufacturername": "Zen Within",
|
||||||
"modelid": "Zen-01",
|
"modelid": "Zen-01",
|
||||||
"name": "Zen-01",
|
"name": "Zen-01",
|
||||||
"state": {
|
"state": {
|
||||||
"lastupdated": "2020-11-27T13:42:40.863",
|
"lastupdated": "2020-11-27T13:42:40.863",
|
||||||
"on": False,
|
"on": False,
|
||||||
"temperature": 2320,
|
"temperature": 2320,
|
||||||
},
|
},
|
||||||
"type": "ZHAThermostat",
|
"type": "ZHAThermostat",
|
||||||
"uniqueid": "00:24:46:00:00:11:6f:56-01-0201",
|
"uniqueid": "00:24:46:00:00:11:6f:56-01-0201",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config_entry = await setup_deconz_integration(
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
hass, aioclient_mock, get_state_response=data
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
)
|
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 2
|
assert len(hass.states.async_all()) == 2
|
||||||
|
|
||||||
|
@ -591,27 +585,27 @@ async def test_climate_device_with_preset(hass, aioclient_mock):
|
||||||
assert climate_zen_01.state == HVAC_MODE_HEAT
|
assert climate_zen_01.state == HVAC_MODE_HEAT
|
||||||
assert climate_zen_01.attributes["current_temperature"] == 23.2
|
assert climate_zen_01.attributes["current_temperature"] == 23.2
|
||||||
assert climate_zen_01.attributes["temperature"] == 22.2
|
assert climate_zen_01.attributes["temperature"] == 22.2
|
||||||
assert climate_zen_01.attributes["preset_mode"] == "auto"
|
assert climate_zen_01.attributes["preset_mode"] == DECONZ_PRESET_AUTO
|
||||||
assert climate_zen_01.attributes["preset_modes"] == [
|
assert climate_zen_01.attributes["preset_modes"] == [
|
||||||
"auto",
|
DECONZ_PRESET_AUTO,
|
||||||
"boost",
|
PRESET_BOOST,
|
||||||
"comfort",
|
PRESET_COMFORT,
|
||||||
"complex",
|
DECONZ_PRESET_COMPLEX,
|
||||||
"eco",
|
PRESET_ECO,
|
||||||
"holiday",
|
DECONZ_PRESET_HOLIDAY,
|
||||||
"manual",
|
DECONZ_PRESET_MANUAL,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Event signals deCONZ preset
|
# Event signals deCONZ preset
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "0",
|
"id": "0",
|
||||||
"config": {"preset": "manual"},
|
"config": {"preset": "manual"},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
|
@ -621,14 +615,14 @@ async def test_climate_device_with_preset(hass, aioclient_mock):
|
||||||
|
|
||||||
# Event signals unknown preset
|
# Event signals unknown preset
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "0",
|
"id": "0",
|
||||||
"config": {"preset": "unsupported"},
|
"config": {"preset": "unsupported"},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.zen_01").attributes["preset_mode"] is None
|
assert hass.states.get("climate.zen_01").attributes["preset_mode"] is None
|
||||||
|
@ -670,19 +664,36 @@ async def test_climate_device_with_preset(hass, aioclient_mock):
|
||||||
|
|
||||||
async def test_clip_climate_device(hass, aioclient_mock):
|
async def test_clip_climate_device(hass, aioclient_mock):
|
||||||
"""Test successful creation of sensor entities."""
|
"""Test successful creation of sensor entities."""
|
||||||
data = deepcopy(DECONZ_WEB_REQUEST)
|
data = {
|
||||||
data["sensors"] = deepcopy(SENSORS)
|
"sensors": {
|
||||||
config_entry = await setup_deconz_integration(
|
"1": {
|
||||||
hass,
|
"name": "Thermostat",
|
||||||
aioclient_mock,
|
"type": "ZHAThermostat",
|
||||||
options={CONF_ALLOW_CLIP_SENSOR: True},
|
"state": {"on": True, "temperature": 2260, "valve": 30},
|
||||||
get_state_response=data,
|
"config": {
|
||||||
)
|
"battery": 100,
|
||||||
|
"heatsetpoint": 2200,
|
||||||
|
"mode": "auto",
|
||||||
|
"offset": 10,
|
||||||
|
"reachable": True,
|
||||||
|
},
|
||||||
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||||
|
},
|
||||||
|
"2": {
|
||||||
|
"name": "CLIP thermostat",
|
||||||
|
"type": "CLIPThermostat",
|
||||||
|
"state": {"on": True, "temperature": 2260, "valve": 30},
|
||||||
|
"config": {"reachable": True},
|
||||||
|
"uniqueid": "00:00:00:00:00:00:00:02-00",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
|
config_entry = await setup_deconz_integration(
|
||||||
|
hass, aioclient_mock, options={CONF_ALLOW_CLIP_SENSOR: True}
|
||||||
|
)
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 3
|
assert len(hass.states.async_all()) == 3
|
||||||
assert hass.states.get("climate.thermostat").state == HVAC_MODE_AUTO
|
|
||||||
assert hass.states.get("sensor.thermostat") is None
|
|
||||||
assert hass.states.get("sensor.thermostat_battery_level").state == "100"
|
|
||||||
assert hass.states.get("climate.clip_thermostat").state == HVAC_MODE_HEAT
|
assert hass.states.get("climate.clip_thermostat").state == HVAC_MODE_HEAT
|
||||||
|
|
||||||
# Disallow clip sensors
|
# Disallow clip sensors
|
||||||
|
@ -693,7 +704,7 @@ async def test_clip_climate_device(hass, aioclient_mock):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 2
|
assert len(hass.states.async_all()) == 2
|
||||||
assert hass.states.get("climate.clip_thermostat") is None
|
assert not hass.states.get("climate.clip_thermostat")
|
||||||
|
|
||||||
# Allow clip sensors
|
# Allow clip sensors
|
||||||
|
|
||||||
|
@ -706,45 +717,70 @@ async def test_clip_climate_device(hass, aioclient_mock):
|
||||||
assert hass.states.get("climate.clip_thermostat").state == HVAC_MODE_HEAT
|
assert hass.states.get("climate.clip_thermostat").state == HVAC_MODE_HEAT
|
||||||
|
|
||||||
|
|
||||||
async def test_verify_state_update(hass, aioclient_mock):
|
async def test_verify_state_update(hass, aioclient_mock, mock_deconz_websocket):
|
||||||
"""Test that state update properly."""
|
"""Test that state update properly."""
|
||||||
data = deepcopy(DECONZ_WEB_REQUEST)
|
data = {
|
||||||
data["sensors"] = deepcopy(SENSORS)
|
"sensors": {
|
||||||
config_entry = await setup_deconz_integration(
|
"1": {
|
||||||
hass, aioclient_mock, get_state_response=data
|
"name": "Thermostat",
|
||||||
)
|
"type": "ZHAThermostat",
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
"state": {"on": True, "temperature": 2260, "valve": 30},
|
||||||
|
"config": {
|
||||||
|
"battery": 100,
|
||||||
|
"heatsetpoint": 2200,
|
||||||
|
"mode": "auto",
|
||||||
|
"offset": 10,
|
||||||
|
"reachable": True,
|
||||||
|
},
|
||||||
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
|
await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
assert hass.states.get("climate.thermostat").state == HVAC_MODE_AUTO
|
assert hass.states.get("climate.thermostat").state == HVAC_MODE_AUTO
|
||||||
|
|
||||||
state_changed_event = {
|
event_changed_sensor = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "changed",
|
"e": "changed",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"state": {"on": False},
|
"state": {"on": False},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_changed_event)
|
await mock_deconz_websocket(data=event_changed_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("climate.thermostat").state == HVAC_MODE_AUTO
|
assert hass.states.get("climate.thermostat").state == HVAC_MODE_AUTO
|
||||||
assert gateway.api.sensors["1"].changed_keys == {"state", "r", "t", "on", "e", "id"}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_add_new_climate_device(hass, aioclient_mock):
|
async def test_add_new_climate_device(hass, aioclient_mock, mock_deconz_websocket):
|
||||||
"""Test that adding a new climate device works."""
|
"""Test that adding a new climate device works."""
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
event_added_sensor = {
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
|
||||||
assert len(hass.states.async_all()) == 0
|
|
||||||
|
|
||||||
state_added_event = {
|
|
||||||
"t": "event",
|
"t": "event",
|
||||||
"e": "added",
|
"e": "added",
|
||||||
"r": "sensors",
|
"r": "sensors",
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"sensor": deepcopy(SENSORS["1"]),
|
"sensor": {
|
||||||
|
"id": "Thermostat id",
|
||||||
|
"name": "Thermostat",
|
||||||
|
"type": "ZHAThermostat",
|
||||||
|
"state": {"on": True, "temperature": 2260, "valve": 30},
|
||||||
|
"config": {
|
||||||
|
"battery": 100,
|
||||||
|
"heatsetpoint": 2200,
|
||||||
|
"mode": "auto",
|
||||||
|
"offset": 10,
|
||||||
|
"reachable": True,
|
||||||
|
},
|
||||||
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
gateway.api.event_handler(state_added_event)
|
|
||||||
|
await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
assert len(hass.states.async_all()) == 0
|
||||||
|
|
||||||
|
await mock_deconz_websocket(data=event_added_sensor)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 2
|
assert len(hass.states.async_all()) == 2
|
||||||
|
|
Loading…
Add table
Reference in a new issue