mirror of
https://github.com/home-assistant/core.git
synced 2026-09-28 02:18:10 -04:00
Use fixtures for all entity IDs in Evohome tests (#167479)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
co-authored by
Joost Lekkerkerker
Copilot
Martin Hjelmare
parent
f6fb6f40dd
commit
298b9b962f
@@ -8,7 +8,7 @@ from http import HTTPMethod
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from evohomeasync2 import EvohomeClient
|
||||
from evohomeasync2 import EvohomeClient, HotWater
|
||||
from evohomeasync2.auth import AbstractTokenManager, Auth
|
||||
from evohomeasync2.control_system import ControlSystem
|
||||
from evohomeasync2.zone import Zone
|
||||
@@ -18,8 +18,9 @@ import pytest
|
||||
from homeassistant.components.evohome.const import DOMAIN
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util, slugify
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.json import JsonArrayType, JsonObjectType
|
||||
|
||||
from .const import ACCESS_TOKEN, REFRESH_TOKEN, SESSION_ID, USERNAME
|
||||
@@ -210,20 +211,52 @@ async def evohome(
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ctl_id(evohome: MagicMock) -> str:
|
||||
"""Return the entity_id of the evohome integration's controller."""
|
||||
def ctl_id(evohome: MagicMock, entity_id: Callable[[Platform, str], str]) -> str:
|
||||
"""Return the entity_id of evohome's controller (a Climate entity)."""
|
||||
|
||||
evo: EvohomeClient = evohome.return_value
|
||||
tcs: ControlSystem = evo.tcs
|
||||
|
||||
return entity_id(Platform.CLIMATE, tcs.id)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def zone_id(evohome: MagicMock, entity_id: Callable[[Platform, str], str]) -> str:
|
||||
"""Return the entity_id of evohome's first zone (a Climate entity)."""
|
||||
|
||||
evo: EvohomeClient = evohome.return_value
|
||||
ctl: ControlSystem = evo.tcs
|
||||
|
||||
return f"{Platform.CLIMATE}.{slugify(ctl.location.name)}"
|
||||
zone: Zone = evo.tcs.zones[0]
|
||||
|
||||
return entity_id(Platform.CLIMATE, f"{zone.id}z" if zone.id == ctl.id else zone.id)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def zone_id(evohome: MagicMock) -> str:
|
||||
"""Return the entity_id of the evohome integration's first zone."""
|
||||
def dhw_id(evohome: MagicMock, entity_id: Callable[[Platform, str], str]) -> str:
|
||||
"""Return the entity_id of Evohome's DHW controller (a WaterHeater entity)."""
|
||||
|
||||
evo: EvohomeClient = evohome.return_value
|
||||
zone: Zone = evo.tcs.zones[0]
|
||||
dhw: HotWater | None = evo.tcs.hotwater
|
||||
|
||||
return f"{Platform.CLIMATE}.{slugify(zone.name)}"
|
||||
assert dhw is not None, "Fixture has no DHW zone"
|
||||
|
||||
return entity_id(Platform.WATER_HEATER, dhw.id)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def entity_id(
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> Callable[[Platform, str], str]:
|
||||
"""Return a helper to lookup an entity_id from platform and unique_id."""
|
||||
|
||||
def get_entity_id(platform: Platform, unique_id: str) -> str:
|
||||
"""Return an entity_id from the entity registry."""
|
||||
|
||||
entity = entity_registry.async_get_entity_id(platform, DOMAIN, unique_id)
|
||||
assert entity is not None, (
|
||||
f"Entity not found for platform={platform}: {unique_id}"
|
||||
)
|
||||
return entity
|
||||
|
||||
return get_entity_id
|
||||
|
||||
@@ -24,8 +24,6 @@ from homeassistant.core import HomeAssistant
|
||||
from .conftest import setup_evohome
|
||||
from .const import TEST_INSTALLS_WITH_DHW
|
||||
|
||||
DHW_ENTITY_ID = "water_heater.domestic_hot_water"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("install", TEST_INSTALLS_WITH_DHW)
|
||||
async def test_setup_platform(
|
||||
@@ -49,9 +47,9 @@ async def test_setup_platform(
|
||||
|
||||
|
||||
@pytest.mark.parametrize("install", TEST_INSTALLS_WITH_DHW)
|
||||
@pytest.mark.usefixtures("evohome")
|
||||
async def test_set_operation_mode(
|
||||
hass: HomeAssistant,
|
||||
dhw_id: str,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
@@ -66,7 +64,7 @@ async def test_set_operation_mode(
|
||||
WATER_HEATER_DOMAIN,
|
||||
SERVICE_SET_OPERATION_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: DHW_ENTITY_ID,
|
||||
ATTR_ENTITY_ID: dhw_id,
|
||||
ATTR_OPERATION_MODE: "auto",
|
||||
},
|
||||
blocking=True,
|
||||
@@ -80,7 +78,7 @@ async def test_set_operation_mode(
|
||||
WATER_HEATER_DOMAIN,
|
||||
SERVICE_SET_OPERATION_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: DHW_ENTITY_ID,
|
||||
ATTR_ENTITY_ID: dhw_id,
|
||||
ATTR_OPERATION_MODE: "off",
|
||||
},
|
||||
blocking=True,
|
||||
@@ -100,7 +98,7 @@ async def test_set_operation_mode(
|
||||
WATER_HEATER_DOMAIN,
|
||||
SERVICE_SET_OPERATION_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: DHW_ENTITY_ID,
|
||||
ATTR_ENTITY_ID: dhw_id,
|
||||
ATTR_OPERATION_MODE: "on",
|
||||
},
|
||||
blocking=True,
|
||||
@@ -118,8 +116,7 @@ async def test_set_operation_mode(
|
||||
|
||||
|
||||
@pytest.mark.parametrize("install", TEST_INSTALLS_WITH_DHW)
|
||||
@pytest.mark.usefixtures("evohome")
|
||||
async def test_set_away_mode(hass: HomeAssistant) -> None:
|
||||
async def test_set_away_mode(hass: HomeAssistant, dhw_id: str) -> None:
|
||||
"""Test SERVICE_SET_AWAY_MODE of an evohome DHW zone."""
|
||||
|
||||
# set_away_mode: off
|
||||
@@ -128,7 +125,7 @@ async def test_set_away_mode(hass: HomeAssistant) -> None:
|
||||
WATER_HEATER_DOMAIN,
|
||||
SERVICE_SET_AWAY_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: DHW_ENTITY_ID,
|
||||
ATTR_ENTITY_ID: dhw_id,
|
||||
ATTR_AWAY_MODE: "off",
|
||||
},
|
||||
blocking=True,
|
||||
@@ -142,7 +139,7 @@ async def test_set_away_mode(hass: HomeAssistant) -> None:
|
||||
WATER_HEATER_DOMAIN,
|
||||
SERVICE_SET_AWAY_MODE,
|
||||
{
|
||||
ATTR_ENTITY_ID: DHW_ENTITY_ID,
|
||||
ATTR_ENTITY_ID: dhw_id,
|
||||
ATTR_AWAY_MODE: "on",
|
||||
},
|
||||
blocking=True,
|
||||
@@ -152,8 +149,7 @@ async def test_set_away_mode(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
@pytest.mark.parametrize("install", TEST_INSTALLS_WITH_DHW)
|
||||
@pytest.mark.usefixtures("evohome")
|
||||
async def test_turn_off(hass: HomeAssistant) -> None:
|
||||
async def test_turn_off(hass: HomeAssistant, dhw_id: str) -> None:
|
||||
"""Test SERVICE_TURN_OFF of an evohome DHW zone."""
|
||||
|
||||
# turn_off
|
||||
@@ -162,7 +158,7 @@ async def test_turn_off(hass: HomeAssistant) -> None:
|
||||
WATER_HEATER_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{
|
||||
ATTR_ENTITY_ID: DHW_ENTITY_ID,
|
||||
ATTR_ENTITY_ID: dhw_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -171,8 +167,7 @@ async def test_turn_off(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
@pytest.mark.parametrize("install", TEST_INSTALLS_WITH_DHW)
|
||||
@pytest.mark.usefixtures("evohome")
|
||||
async def test_turn_on(hass: HomeAssistant) -> None:
|
||||
async def test_turn_on(hass: HomeAssistant, dhw_id: str) -> None:
|
||||
"""Test SERVICE_TURN_ON of an evohome DHW zone."""
|
||||
|
||||
# turn_on
|
||||
@@ -181,7 +176,7 @@ async def test_turn_on(hass: HomeAssistant) -> None:
|
||||
WATER_HEATER_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{
|
||||
ATTR_ENTITY_ID: DHW_ENTITY_ID,
|
||||
ATTR_ENTITY_ID: dhw_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user