Use snapshot_platform helper in atag climate tests (#181823)

This commit is contained in:
epenet
2026-09-10 10:27:39 +02:00
committed by GitHub
parent 3895d807ec
commit 5a0fe8e2d3
2 changed files with 106 additions and 10 deletions
@@ -0,0 +1,83 @@
# serializer version: 1
# name: test_all_entities[climate.atag_thermostat_atag-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
None,
]),
'area_id': None,
'capabilities': dict({
<ClimateEntityCapabilityAttribute.HVAC_MODES: 'hvac_modes'>: list([
<HVACMode.AUTO: 'auto'>,
<HVACMode.HEAT: 'heat'>,
]),
<ClimateEntityCapabilityAttribute.MAX_TEMP: 'max_temp'>: 35,
<ClimateEntityCapabilityAttribute.MIN_TEMP: 'min_temp'>: 7,
<ClimateEntityCapabilityAttribute.PRESET_MODES: 'preset_modes'>: list([
'Manual',
'Auto',
'Extend',
'away',
'boost',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.atag_thermostat_atag',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': 'Atag',
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Atag',
'platform': 'atag',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': <ClimateEntityFeature: 17>,
'translation_key': None,
'unique_id': 'xxxx-xxxx-xxxx_xx-xx-xxx-xxx-climate',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[climate.atag_thermostat_atag-state]
StateSnapshot({
'attributes': ReadOnlyDict({
<ClimateEntityStateAttribute.CURRENT_TEMPERATURE: 'current_temperature'>: 20,
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Atag Thermostat Atag',
<ClimateEntityStateAttribute.HVAC_ACTION: 'hvac_action'>: <HVACAction.IDLE: 'idle'>,
<ClimateEntityCapabilityAttribute.HVAC_MODES: 'hvac_modes'>: list([
<HVACMode.AUTO: 'auto'>,
<HVACMode.HEAT: 'heat'>,
]),
<ClimateEntityCapabilityAttribute.MAX_TEMP: 'max_temp'>: 35,
<ClimateEntityCapabilityAttribute.MIN_TEMP: 'min_temp'>: 7,
<ClimateEntityStateAttribute.PRESET_MODE: 'preset_mode'>: 'Manual',
<ClimateEntityCapabilityAttribute.PRESET_MODES: 'preset_modes'>: list([
'Manual',
'Auto',
'Extend',
'away',
'boost',
]),
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <ClimateEntityFeature: 17>,
<ClimateEntityStateAttribute.TARGET_TEMPERATURE: 'temperature'>: 12,
}),
'context': <ANY>,
'entity_id': 'climate.atag_thermostat_atag',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'heat',
})
# ---
+23 -10
View File
@@ -1,10 +1,13 @@
"""Tests for the Atag climate platform."""
from collections.abc import Generator
from unittest.mock import PropertyMock, patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.atag.climate import PRESET_MAP
from homeassistant.components.climate import (
ATTR_HVAC_ACTION,
ATTR_HVAC_MODE,
ATTR_PRESET_MODE,
DOMAIN as CLIMATE_DOMAIN,
@@ -12,34 +15,44 @@ from homeassistant.components.climate import (
SERVICE_SET_HVAC_MODE,
SERVICE_SET_PRESET_MODE,
SERVICE_SET_TEMPERATURE,
HVACAction,
HVACMode,
)
from homeassistant.components.homeassistant import DOMAIN as HA_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_UNKNOWN
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_TEMPERATURE,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
from . import UID, init_integration
from tests.common import snapshot_platform
from tests.test_util.aiohttp import AiohttpClientMocker
CLIMATE_ID = "climate.atag_thermostat_atag"
async def test_climate(
@pytest.fixture(autouse=True)
def override_platforms() -> Generator[None]:
"""Override PLATFORMS."""
with patch("homeassistant.components.atag.PLATFORMS", [Platform.CLIMATE]):
yield
async def test_all_entities(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test the creation and values of Atag climate device."""
await init_integration(hass, aioclient_mock)
"""Test all entities."""
entry = await init_integration(hass, aioclient_mock)
assert entity_registry.async_is_registered(CLIMATE_ID)
entity = entity_registry.async_get(CLIMATE_ID)
assert entity.unique_id == f"{UID}-climate"
assert hass.states.get(CLIMATE_ID).attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
async def test_setting_climate(