mirror of
https://github.com/home-assistant/core.git
synced 2026-03-02 07:29:28 +00:00
* working test_init * update fixtures to be compliant with new schema * test_storage is now working * all tests passing * bump client to 1.0.1b0 * test commit (working tests) * use only id (not e.g. zoneId), use StrEnums * mypy, lint * remove deprecated module * remove waffle * improve typing of asserts * broker is now coordinator * WIP - test failing * rename class * remove unneeded async_dispatcher_send() * restore missing code * harden test * bugfix failing test * don't capture blind except * shrink log messages * doctweak * rationalize asserts * remove unneeded listerner * refactor setup * bump client to 1.0.2b0 * bump client to 1.0.2b1 * refactor extended state attrs * pass UpdateFailed to _async_refresh() * Update homeassistant/components/evohome/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/evohome/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * not even lint * undo not even lint * remove unused logger * restore old namespace for e_s_a * minimize diff * doctweak * remove unused method * lint * DUC now working * restore old camelCase keynames * tweak * small tweak to _handle_coordinator_update() * Update homeassistant/components/evohome/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * add test of coordinator * bump client to 1.0.2 --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
391 lines
11 KiB
Python
391 lines
11 KiB
Python
"""The tests for the climate platform of evohome.
|
|
|
|
All evohome systems have controllers and at least one zone.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
from freezegun.api import FrozenDateTimeFactory
|
|
import pytest
|
|
from syrupy import SnapshotAssertion
|
|
|
|
from homeassistant.components.climate import (
|
|
ATTR_HVAC_MODE,
|
|
ATTR_PRESET_MODE,
|
|
SERVICE_SET_HVAC_MODE,
|
|
SERVICE_SET_PRESET_MODE,
|
|
SERVICE_SET_TEMPERATURE,
|
|
HVACMode,
|
|
)
|
|
from homeassistant.const import (
|
|
ATTR_ENTITY_ID,
|
|
ATTR_TEMPERATURE,
|
|
SERVICE_TURN_OFF,
|
|
SERVICE_TURN_ON,
|
|
Platform,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import HomeAssistantError
|
|
|
|
from .conftest import setup_evohome
|
|
from .const import TEST_INSTALLS
|
|
|
|
|
|
@pytest.mark.parametrize("install", [*TEST_INSTALLS, "botched"])
|
|
async def test_setup_platform(
|
|
hass: HomeAssistant,
|
|
config: dict[str, str],
|
|
install: str,
|
|
snapshot: SnapshotAssertion,
|
|
freezer: FrozenDateTimeFactory,
|
|
) -> None:
|
|
"""Test entities and their states after setup of evohome."""
|
|
|
|
# Cannot use the evohome fixture, as need to set dtm first
|
|
# - some extended state attrs are relative the current time
|
|
freezer.move_to("2024-07-10T12:00:00Z")
|
|
|
|
async for _ in setup_evohome(hass, config, install=install):
|
|
pass
|
|
|
|
for x in hass.states.async_all(Platform.CLIMATE):
|
|
assert x == snapshot(name=f"{x.entity_id}-state")
|
|
|
|
|
|
@pytest.mark.parametrize("install", TEST_INSTALLS)
|
|
async def test_ctl_set_hvac_mode(
|
|
hass: HomeAssistant,
|
|
ctl_id: str,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test SERVICE_SET_HVAC_MODE of an evohome controller."""
|
|
|
|
results = []
|
|
|
|
# SERVICE_SET_HVAC_MODE: HVACMode.OFF
|
|
with patch("evohomeasync2.control_system.ControlSystem.set_mode") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: ctl_id,
|
|
ATTR_HVAC_MODE: HVACMode.OFF,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
try:
|
|
mock_fcn.assert_awaited_once_with("HeatingOff", until=None)
|
|
except AssertionError:
|
|
mock_fcn.assert_awaited_once_with("Off", until=None)
|
|
|
|
results.append(mock_fcn.await_args.args) # type: ignore[union-attr]
|
|
|
|
# SERVICE_SET_HVAC_MODE: HVACMode.HEAT
|
|
with patch("evohomeasync2.control_system.ControlSystem.set_mode") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: ctl_id,
|
|
ATTR_HVAC_MODE: HVACMode.HEAT,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
try:
|
|
mock_fcn.assert_awaited_once_with("Auto", until=None)
|
|
except AssertionError:
|
|
mock_fcn.assert_awaited_once_with("Heat", until=None)
|
|
|
|
results.append(mock_fcn.await_args.args) # type: ignore[union-attr]
|
|
|
|
assert results == snapshot
|
|
|
|
|
|
@pytest.mark.parametrize("install", TEST_INSTALLS)
|
|
async def test_ctl_set_temperature(
|
|
hass: HomeAssistant,
|
|
ctl_id: str,
|
|
) -> None:
|
|
"""Test SERVICE_SET_TEMPERATURE of an evohome controller."""
|
|
|
|
# Entity climate.xxx does not support this service
|
|
with pytest.raises(HomeAssistantError):
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_SET_TEMPERATURE,
|
|
{
|
|
ATTR_ENTITY_ID: ctl_id,
|
|
ATTR_TEMPERATURE: 19.1,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("install", TEST_INSTALLS)
|
|
async def test_ctl_turn_off(
|
|
hass: HomeAssistant,
|
|
ctl_id: str,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test SERVICE_TURN_OFF of an evohome controller."""
|
|
|
|
results = []
|
|
|
|
# SERVICE_TURN_OFF
|
|
with patch("evohomeasync2.control_system.ControlSystem.set_mode") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_TURN_OFF,
|
|
{
|
|
ATTR_ENTITY_ID: ctl_id,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
try:
|
|
mock_fcn.assert_awaited_once_with("HeatingOff", until=None)
|
|
except AssertionError:
|
|
mock_fcn.assert_awaited_once_with("Off", until=None)
|
|
|
|
results.append(mock_fcn.await_args.args) # type: ignore[union-attr]
|
|
|
|
assert results == snapshot
|
|
|
|
|
|
@pytest.mark.parametrize("install", TEST_INSTALLS)
|
|
async def test_ctl_turn_on(
|
|
hass: HomeAssistant,
|
|
ctl_id: str,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test SERVICE_TURN_ON of an evohome controller."""
|
|
|
|
results = []
|
|
|
|
# SERVICE_TURN_ON
|
|
with patch("evohomeasync2.control_system.ControlSystem.set_mode") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_TURN_ON,
|
|
{
|
|
ATTR_ENTITY_ID: ctl_id,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
try:
|
|
mock_fcn.assert_awaited_once_with("Auto", until=None)
|
|
except AssertionError:
|
|
mock_fcn.assert_awaited_once_with("Heat", until=None)
|
|
|
|
results.append(mock_fcn.await_args.args) # type: ignore[union-attr]
|
|
|
|
assert results == snapshot
|
|
|
|
|
|
@pytest.mark.parametrize("install", TEST_INSTALLS)
|
|
async def test_zone_set_hvac_mode(
|
|
hass: HomeAssistant,
|
|
zone_id: str,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test SERVICE_SET_HVAC_MODE of an evohome heating zone."""
|
|
|
|
results = []
|
|
|
|
# SERVICE_SET_HVAC_MODE: HVACMode.HEAT
|
|
with patch("evohomeasync2.zone.Zone.reset") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: zone_id,
|
|
ATTR_HVAC_MODE: HVACMode.HEAT,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_fcn.assert_awaited_once_with()
|
|
|
|
# SERVICE_SET_HVAC_MODE: HVACMode.OFF
|
|
with patch("evohomeasync2.zone.Zone.set_temperature") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: zone_id,
|
|
ATTR_HVAC_MODE: HVACMode.OFF,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_fcn.assert_awaited_once()
|
|
|
|
assert mock_fcn.await_args is not None # mypy hint
|
|
assert mock_fcn.await_args.args != () # minimum target temp
|
|
assert mock_fcn.await_args.kwargs == {"until": None}
|
|
|
|
results.append(mock_fcn.await_args.args)
|
|
|
|
assert results == snapshot
|
|
|
|
|
|
@pytest.mark.parametrize("install", TEST_INSTALLS)
|
|
async def test_zone_set_preset_mode(
|
|
hass: HomeAssistant,
|
|
zone_id: str,
|
|
freezer: FrozenDateTimeFactory,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test SERVICE_SET_PRESET_MODE of an evohome heating zone."""
|
|
|
|
freezer.move_to("2024-07-10T12:00:00Z")
|
|
results = []
|
|
|
|
# SERVICE_SET_PRESET_MODE: none
|
|
with patch("evohomeasync2.zone.Zone.reset") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_SET_PRESET_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: zone_id,
|
|
ATTR_PRESET_MODE: "none",
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_fcn.assert_awaited_once_with()
|
|
|
|
# SERVICE_SET_PRESET_MODE: permanent
|
|
with patch("evohomeasync2.zone.Zone.set_temperature") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_SET_PRESET_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: zone_id,
|
|
ATTR_PRESET_MODE: "permanent",
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_fcn.assert_awaited_once()
|
|
|
|
assert mock_fcn.await_args is not None # mypy hint
|
|
assert mock_fcn.await_args.args != () # current target temp
|
|
assert mock_fcn.await_args.kwargs == {"until": None}
|
|
|
|
results.append(mock_fcn.await_args.args)
|
|
|
|
# SERVICE_SET_PRESET_MODE: temporary
|
|
with patch("evohomeasync2.zone.Zone.set_temperature") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_SET_PRESET_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: zone_id,
|
|
ATTR_PRESET_MODE: "temporary",
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_fcn.assert_awaited_once()
|
|
|
|
assert mock_fcn.await_args is not None # mypy hint
|
|
assert mock_fcn.await_args.args != () # current target temp
|
|
assert mock_fcn.await_args.kwargs != {} # next setpoint dtm
|
|
|
|
results.append(mock_fcn.await_args.args)
|
|
results.append(mock_fcn.await_args.kwargs)
|
|
|
|
assert results == snapshot
|
|
|
|
|
|
@pytest.mark.parametrize("install", TEST_INSTALLS)
|
|
async def test_zone_set_temperature(
|
|
hass: HomeAssistant,
|
|
zone_id: str,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test SERVICE_SET_TEMPERATURE of an evohome heating zone."""
|
|
|
|
results = []
|
|
|
|
# SERVICE_SET_TEMPERATURE: temperature
|
|
with patch("evohomeasync2.zone.Zone.set_temperature") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_SET_TEMPERATURE,
|
|
{
|
|
ATTR_ENTITY_ID: zone_id,
|
|
ATTR_TEMPERATURE: 19.1,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_fcn.assert_awaited_once()
|
|
|
|
assert mock_fcn.await_args is not None # mypy hint
|
|
assert mock_fcn.await_args.args == (19.1,)
|
|
assert mock_fcn.await_args.kwargs != {} # next setpoint dtm
|
|
|
|
results.append(mock_fcn.await_args.kwargs)
|
|
|
|
assert results == snapshot
|
|
|
|
|
|
@pytest.mark.parametrize("install", TEST_INSTALLS)
|
|
async def test_zone_turn_off(
|
|
hass: HomeAssistant,
|
|
zone_id: str,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test SERVICE_TURN_OFF of an evohome heating zone."""
|
|
|
|
results = []
|
|
|
|
# SERVICE_TURN_OFF
|
|
with patch("evohomeasync2.zone.Zone.set_temperature") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_TURN_OFF,
|
|
{
|
|
ATTR_ENTITY_ID: zone_id,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_fcn.assert_awaited_once()
|
|
|
|
assert mock_fcn.await_args is not None # mypy hint
|
|
assert mock_fcn.await_args.args != () # minimum target temp
|
|
assert mock_fcn.await_args.kwargs == {"until": None}
|
|
|
|
results.append(mock_fcn.await_args.args)
|
|
|
|
assert results == snapshot
|
|
|
|
|
|
@pytest.mark.parametrize("install", TEST_INSTALLS)
|
|
async def test_zone_turn_on(
|
|
hass: HomeAssistant,
|
|
zone_id: str,
|
|
) -> None:
|
|
"""Test SERVICE_TURN_ON of an evohome heating zone."""
|
|
|
|
# SERVICE_TURN_ON
|
|
with patch("evohomeasync2.zone.Zone.reset") as mock_fcn:
|
|
await hass.services.async_call(
|
|
Platform.CLIMATE,
|
|
SERVICE_TURN_ON,
|
|
{
|
|
ATTR_ENTITY_ID: zone_id,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_fcn.assert_awaited_once_with()
|