2020-09-08 08:37:44 +02:00
|
|
|
"""Tests for the Plugwise Climate integration."""
|
|
|
|
|
2020-11-21 03:43:20 +01:00
|
|
|
from plugwise.exceptions import PlugwiseException
|
2022-02-10 09:53:26 +01:00
|
|
|
import pytest
|
2020-11-21 03:43:20 +01:00
|
|
|
|
2022-02-08 11:13:05 +01:00
|
|
|
from homeassistant.components.climate.const import (
|
|
|
|
HVAC_MODE_AUTO,
|
2022-02-10 18:10:21 +01:00
|
|
|
HVAC_MODE_COOL,
|
2022-02-08 11:13:05 +01:00
|
|
|
HVAC_MODE_HEAT,
|
|
|
|
HVAC_MODE_OFF,
|
|
|
|
)
|
2021-05-20 20:19:20 +03:00
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
2022-02-10 09:53:26 +01:00
|
|
|
from homeassistant.exceptions import HomeAssistantError
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
from tests.components.plugwise.common import async_init_integration
|
|
|
|
|
|
|
|
|
|
|
|
async def test_adam_climate_entity_attributes(hass, mock_smile_adam):
|
|
|
|
"""Test creation of adam climate device environment."""
|
|
|
|
entry = await async_init_integration(hass, mock_smile_adam)
|
2021-05-20 20:19:20 +03:00
|
|
|
assert entry.state is ConfigEntryState.LOADED
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
state = hass.states.get("climate.zone_lisa_wk")
|
|
|
|
attrs = state.attributes
|
|
|
|
|
2022-02-10 18:10:21 +01:00
|
|
|
assert attrs["hvac_modes"] == [HVAC_MODE_HEAT, HVAC_MODE_OFF, HVAC_MODE_AUTO]
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
assert "preset_modes" in attrs
|
|
|
|
assert "no_frost" in attrs["preset_modes"]
|
|
|
|
assert "home" in attrs["preset_modes"]
|
|
|
|
|
|
|
|
assert attrs["current_temperature"] == 20.9
|
|
|
|
assert attrs["temperature"] == 21.5
|
|
|
|
|
|
|
|
assert attrs["preset_mode"] == "home"
|
|
|
|
|
|
|
|
assert attrs["supported_features"] == 17
|
|
|
|
|
|
|
|
state = hass.states.get("climate.zone_thermostat_jessie")
|
|
|
|
attrs = state.attributes
|
|
|
|
|
2022-02-10 18:10:21 +01:00
|
|
|
assert attrs["hvac_modes"] == [HVAC_MODE_HEAT, HVAC_MODE_OFF, HVAC_MODE_AUTO]
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
assert "preset_modes" in attrs
|
|
|
|
assert "no_frost" in attrs["preset_modes"]
|
|
|
|
assert "home" in attrs["preset_modes"]
|
|
|
|
|
|
|
|
assert attrs["current_temperature"] == 17.2
|
|
|
|
assert attrs["temperature"] == 15.0
|
|
|
|
|
|
|
|
assert attrs["preset_mode"] == "asleep"
|
|
|
|
|
|
|
|
|
2020-11-21 03:43:20 +01:00
|
|
|
async def test_adam_climate_adjust_negative_testing(hass, mock_smile_adam):
|
|
|
|
"""Test exceptions of climate entities."""
|
|
|
|
mock_smile_adam.set_preset.side_effect = PlugwiseException
|
|
|
|
mock_smile_adam.set_schedule_state.side_effect = PlugwiseException
|
|
|
|
mock_smile_adam.set_temperature.side_effect = PlugwiseException
|
|
|
|
entry = await async_init_integration(hass, mock_smile_adam)
|
2021-05-20 20:19:20 +03:00
|
|
|
assert entry.state is ConfigEntryState.LOADED
|
2020-11-21 03:43:20 +01:00
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
with pytest.raises(HomeAssistantError):
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_temperature",
|
|
|
|
{"entity_id": "climate.zone_lisa_wk", "temperature": 25},
|
|
|
|
blocking=True,
|
|
|
|
)
|
2020-11-21 03:43:20 +01:00
|
|
|
state = hass.states.get("climate.zone_lisa_wk")
|
|
|
|
attrs = state.attributes
|
|
|
|
assert attrs["temperature"] == 21.5
|
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
with pytest.raises(HomeAssistantError):
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_preset_mode",
|
|
|
|
{"entity_id": "climate.zone_thermostat_jessie", "preset_mode": "home"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
2020-11-21 03:43:20 +01:00
|
|
|
state = hass.states.get("climate.zone_thermostat_jessie")
|
|
|
|
attrs = state.attributes
|
|
|
|
assert attrs["preset_mode"] == "asleep"
|
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
with pytest.raises(HomeAssistantError):
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_hvac_mode",
|
|
|
|
{
|
|
|
|
"entity_id": "climate.zone_thermostat_jessie",
|
|
|
|
"hvac_mode": HVAC_MODE_AUTO,
|
|
|
|
},
|
|
|
|
blocking=True,
|
|
|
|
)
|
2020-11-21 03:43:20 +01:00
|
|
|
state = hass.states.get("climate.zone_thermostat_jessie")
|
|
|
|
attrs = state.attributes
|
|
|
|
|
|
|
|
|
2020-09-08 08:37:44 +02:00
|
|
|
async def test_adam_climate_entity_climate_changes(hass, mock_smile_adam):
|
|
|
|
"""Test handling of user requests in adam climate device environment."""
|
|
|
|
entry = await async_init_integration(hass, mock_smile_adam)
|
2021-05-20 20:19:20 +03:00
|
|
|
assert entry.state is ConfigEntryState.LOADED
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_temperature",
|
|
|
|
{"entity_id": "climate.zone_lisa_wk", "temperature": 25},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
assert mock_smile_adam.set_temperature.call_count == 1
|
|
|
|
mock_smile_adam.set_temperature.assert_called_with(
|
|
|
|
"c50f167537524366a5af7aa3942feb1e", 25.0
|
|
|
|
)
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_preset_mode",
|
|
|
|
{"entity_id": "climate.zone_lisa_wk", "preset_mode": "away"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
assert mock_smile_adam.set_preset.call_count == 1
|
|
|
|
mock_smile_adam.set_preset.assert_called_with(
|
|
|
|
"c50f167537524366a5af7aa3942feb1e", "away"
|
|
|
|
)
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_temperature",
|
|
|
|
{"entity_id": "climate.zone_thermostat_jessie", "temperature": 25},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
assert mock_smile_adam.set_temperature.call_count == 2
|
|
|
|
mock_smile_adam.set_temperature.assert_called_with(
|
|
|
|
"82fa13f017d240daa0d0ea1775420f24", 25.0
|
|
|
|
)
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_preset_mode",
|
|
|
|
{"entity_id": "climate.zone_thermostat_jessie", "preset_mode": "home"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
assert mock_smile_adam.set_preset.call_count == 2
|
|
|
|
mock_smile_adam.set_preset.assert_called_with(
|
|
|
|
"82fa13f017d240daa0d0ea1775420f24", "home"
|
|
|
|
)
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def test_anna_climate_entity_attributes(hass, mock_smile_anna):
|
|
|
|
"""Test creation of anna climate device environment."""
|
|
|
|
entry = await async_init_integration(hass, mock_smile_anna)
|
2021-05-20 20:19:20 +03:00
|
|
|
assert entry.state is ConfigEntryState.LOADED
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
state = hass.states.get("climate.anna")
|
|
|
|
attrs = state.attributes
|
|
|
|
|
|
|
|
assert "hvac_modes" in attrs
|
2022-02-10 18:10:21 +01:00
|
|
|
assert attrs["hvac_modes"] == [HVAC_MODE_HEAT, HVAC_MODE_OFF, HVAC_MODE_COOL]
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
assert "preset_modes" in attrs
|
|
|
|
assert "no_frost" in attrs["preset_modes"]
|
|
|
|
assert "home" in attrs["preset_modes"]
|
|
|
|
|
2022-02-08 11:13:05 +01:00
|
|
|
assert attrs["current_temperature"] == 19.3
|
2020-09-08 08:37:44 +02:00
|
|
|
assert attrs["temperature"] == 21.0
|
|
|
|
|
2022-02-08 11:13:05 +01:00
|
|
|
assert state.state == HVAC_MODE_HEAT
|
|
|
|
assert attrs["hvac_action"] == "heating"
|
2020-09-08 08:37:44 +02:00
|
|
|
assert attrs["preset_mode"] == "home"
|
|
|
|
|
|
|
|
assert attrs["supported_features"] == 17
|
|
|
|
|
|
|
|
|
|
|
|
async def test_anna_climate_entity_climate_changes(hass, mock_smile_anna):
|
|
|
|
"""Test handling of user requests in anna climate device environment."""
|
|
|
|
entry = await async_init_integration(hass, mock_smile_anna)
|
2021-05-20 20:19:20 +03:00
|
|
|
assert entry.state is ConfigEntryState.LOADED
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_temperature",
|
|
|
|
{"entity_id": "climate.anna", "temperature": 25},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
assert mock_smile_anna.set_temperature.call_count == 1
|
|
|
|
mock_smile_anna.set_temperature.assert_called_with(
|
|
|
|
"c784ee9fdab44e1395b8dee7d7a497d5", 25.0
|
|
|
|
)
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_preset_mode",
|
|
|
|
{"entity_id": "climate.anna", "preset_mode": "away"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
assert mock_smile_anna.set_preset.call_count == 1
|
|
|
|
mock_smile_anna.set_preset.assert_called_with(
|
|
|
|
"c784ee9fdab44e1395b8dee7d7a497d5", "away"
|
|
|
|
)
|
2020-09-08 08:37:44 +02:00
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_hvac_mode",
|
|
|
|
{"entity_id": "climate.anna", "hvac_mode": "heat_cool"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
|
2022-02-10 09:53:26 +01:00
|
|
|
assert mock_smile_anna.set_temperature.call_count == 1
|
|
|
|
assert mock_smile_anna.set_schedule_state.call_count == 1
|
|
|
|
mock_smile_anna.set_schedule_state.assert_called_with(
|
|
|
|
"c784ee9fdab44e1395b8dee7d7a497d5", None, "false"
|
|
|
|
)
|
2022-02-10 18:10:21 +01:00
|
|
|
|
|
|
|
# Auto mode is not available, no schedules
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
await hass.services.async_call(
|
|
|
|
"climate",
|
|
|
|
"set_hvac_mode",
|
|
|
|
{"entity_id": "climate.anna", "hvac_mode": "auto"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert mock_smile_anna.set_temperature.call_count == 1
|
|
|
|
assert mock_smile_anna.set_schedule_state.call_count == 1
|