Import DOMAIN constants for Plugwise and implement (#120530)

This commit is contained in:
Bouwe Westerdijk 2024-06-26 12:17:17 +02:00 committed by GitHub
parent c49fce5541
commit d00fe1ce7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 49 deletions

View File

@ -6,7 +6,13 @@ from unittest.mock import MagicMock, patch
from plugwise.exceptions import PlugwiseError
import pytest
from homeassistant.components.climate import HVACMode
from homeassistant.components.climate import (
DOMAIN as CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
SERVICE_SET_PRESET_MODE,
SERVICE_SET_TEMPERATURE,
HVACMode,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util.dt import utcnow
@ -153,8 +159,8 @@ async def test_adam_climate_adjust_negative_testing(
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
"climate",
"set_temperature",
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{"entity_id": "climate.zone_lisa_wk", "temperature": 25},
blocking=True,
)
@ -165,8 +171,8 @@ async def test_adam_climate_entity_climate_changes(
) -> None:
"""Test handling of user requests in adam climate device environment."""
await hass.services.async_call(
"climate",
"set_temperature",
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{"entity_id": "climate.zone_lisa_wk", "temperature": 25},
blocking=True,
)
@ -176,8 +182,8 @@ async def test_adam_climate_entity_climate_changes(
)
await hass.services.async_call(
"climate",
"set_temperature",
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{
"entity_id": "climate.zone_lisa_wk",
"hvac_mode": "heat",
@ -192,15 +198,15 @@ async def test_adam_climate_entity_climate_changes(
with pytest.raises(ValueError):
await hass.services.async_call(
"climate",
"set_temperature",
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{"entity_id": "climate.zone_lisa_wk", "temperature": 150},
blocking=True,
)
await hass.services.async_call(
"climate",
"set_preset_mode",
CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE,
{"entity_id": "climate.zone_lisa_wk", "preset_mode": "away"},
blocking=True,
)
@ -210,8 +216,8 @@ async def test_adam_climate_entity_climate_changes(
)
await hass.services.async_call(
"climate",
"set_hvac_mode",
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{"entity_id": "climate.zone_lisa_wk", "hvac_mode": "heat"},
blocking=True,
)
@ -222,8 +228,8 @@ async def test_adam_climate_entity_climate_changes(
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
"climate",
"set_hvac_mode",
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{
"entity_id": "climate.zone_thermostat_jessie",
"hvac_mode": "dry",
@ -242,8 +248,8 @@ async def test_adam_climate_off_mode_change(
assert state
assert state.state == HVACMode.OFF
await hass.services.async_call(
"climate",
"set_hvac_mode",
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{
"entity_id": "climate.slaapkamer",
"hvac_mode": "heat",
@ -258,8 +264,8 @@ async def test_adam_climate_off_mode_change(
assert state
assert state.state == HVACMode.HEAT
await hass.services.async_call(
"climate",
"set_hvac_mode",
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{
"entity_id": "climate.kinderkamer",
"hvac_mode": "off",
@ -274,8 +280,8 @@ async def test_adam_climate_off_mode_change(
assert state
assert state.state == HVACMode.HEAT
await hass.services.async_call(
"climate",
"set_hvac_mode",
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{
"entity_id": "climate.logeerkamer",
"hvac_mode": "heat",
@ -353,8 +359,8 @@ async def test_anna_climate_entity_climate_changes(
) -> None:
"""Test handling of user requests in anna climate device environment."""
await hass.services.async_call(
"climate",
"set_temperature",
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{"entity_id": "climate.anna", "target_temp_high": 30, "target_temp_low": 20},
blocking=True,
)
@ -365,8 +371,8 @@ async def test_anna_climate_entity_climate_changes(
)
await hass.services.async_call(
"climate",
"set_preset_mode",
CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE,
{"entity_id": "climate.anna", "preset_mode": "away"},
blocking=True,
)
@ -376,8 +382,8 @@ async def test_anna_climate_entity_climate_changes(
)
await hass.services.async_call(
"climate",
"set_hvac_mode",
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{"entity_id": "climate.anna", "hvac_mode": "auto"},
blocking=True,
)
@ -385,8 +391,8 @@ async def test_anna_climate_entity_climate_changes(
assert mock_smile_anna.set_schedule_state.call_count == 0
await hass.services.async_call(
"climate",
"set_hvac_mode",
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{"entity_id": "climate.anna", "hvac_mode": "heat_cool"},
blocking=True,
)

View File

@ -7,6 +7,12 @@ import pytest
from homeassistant.components.plugwise.const import DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import (
SERVICE_TOGGLE,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er
@ -20,11 +26,11 @@ async def test_adam_climate_switch_entities(
"""Test creation of climate related switch entities."""
state = hass.states.get("switch.cv_pomp_relay")
assert state
assert state.state == "on"
assert state.state == STATE_ON
state = hass.states.get("switch.fibaro_hc2_relay")
assert state
assert state.state == "on"
assert state.state == STATE_ON
async def test_adam_climate_switch_negative_testing(
@ -35,8 +41,8 @@ async def test_adam_climate_switch_negative_testing(
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
"switch",
"turn_off",
SWITCH_DOMAIN,
SERVICE_TURN_OFF,
{"entity_id": "switch.cv_pomp_relay"},
blocking=True,
)
@ -48,8 +54,8 @@ async def test_adam_climate_switch_negative_testing(
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
"switch",
"turn_on",
SWITCH_DOMAIN,
SERVICE_TURN_ON,
{"entity_id": "switch.fibaro_hc2_relay"},
blocking=True,
)
@ -65,8 +71,8 @@ async def test_adam_climate_switch_changes(
) -> None:
"""Test changing of climate related switch entities."""
await hass.services.async_call(
"switch",
"turn_off",
SWITCH_DOMAIN,
SERVICE_TURN_OFF,
{"entity_id": "switch.cv_pomp_relay"},
blocking=True,
)
@ -77,8 +83,8 @@ async def test_adam_climate_switch_changes(
)
await hass.services.async_call(
"switch",
"toggle",
SWITCH_DOMAIN,
SERVICE_TOGGLE,
{"entity_id": "switch.fibaro_hc2_relay"},
blocking=True,
)
@ -89,8 +95,8 @@ async def test_adam_climate_switch_changes(
)
await hass.services.async_call(
"switch",
"turn_on",
SWITCH_DOMAIN,
SERVICE_TURN_ON,
{"entity_id": "switch.fibaro_hc2_relay"},
blocking=True,
)
@ -107,11 +113,11 @@ async def test_stretch_switch_entities(
"""Test creation of climate related switch entities."""
state = hass.states.get("switch.koelkast_92c4a_relay")
assert state
assert state.state == "on"
assert state.state == STATE_ON
state = hass.states.get("switch.droger_52559_relay")
assert state
assert state.state == "on"
assert state.state == STATE_ON
async def test_stretch_switch_changes(
@ -119,8 +125,8 @@ async def test_stretch_switch_changes(
) -> None:
"""Test changing of power related switch entities."""
await hass.services.async_call(
"switch",
"turn_off",
SWITCH_DOMAIN,
SERVICE_TURN_OFF,
{"entity_id": "switch.koelkast_92c4a_relay"},
blocking=True,
)
@ -130,8 +136,8 @@ async def test_stretch_switch_changes(
)
await hass.services.async_call(
"switch",
"toggle",
SWITCH_DOMAIN,
SERVICE_TOGGLE,
{"entity_id": "switch.droger_52559_relay"},
blocking=True,
)
@ -141,8 +147,8 @@ async def test_stretch_switch_changes(
)
await hass.services.async_call(
"switch",
"turn_on",
SWITCH_DOMAIN,
SERVICE_TURN_ON,
{"entity_id": "switch.droger_52559_relay"},
blocking=True,
)