Use test snapshots for Shelly climate (#140582)

This commit is contained in:
Maciej Bieniek 2025-03-14 11:15:38 +01:00 committed by GitHub
parent 8726be31ff
commit 5ea7c113b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 295 additions and 14 deletions

View File

@ -502,6 +502,7 @@ def _mock_blu_rtv_device(version: str | None = None):
firmware_version="some fw string",
initialized=True,
connected=True,
xmod_info={},
)
type(device).name = PropertyMock(return_value="Test name")
return device

View File

@ -0,0 +1,276 @@
# serializer version: 1
# name: test_blu_trv_climate_set_temperature[climate.trv_name-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'hvac_modes': list([
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 30,
'min_temp': 4,
'target_temp_step': 0.1,
}),
'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.trv_name',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': None,
'platform': 'shelly',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 257>,
'translation_key': None,
'unique_id': 'f8:44:77:25:f0:dd-blutrv:200',
'unit_of_measurement': None,
})
# ---
# name: test_blu_trv_climate_set_temperature[climate.trv_name-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_temperature': 15.2,
'friendly_name': 'TRV-Name',
'hvac_action': <HVACAction.IDLE: 'idle'>,
'hvac_modes': list([
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 30,
'min_temp': 4,
'supported_features': <ClimateEntityFeature: 257>,
'target_temp_step': 0.1,
'temperature': 17.1,
}),
'context': <ANY>,
'entity_id': 'climate.trv_name',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'heat',
})
# ---
# name: test_climate_hvac_mode[climate.test_name-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'hvac_modes': list([
<HVACMode.OFF: 'off'>,
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 31,
'min_temp': 4,
'preset_modes': list([
'none',
'Profile1',
'Profile2',
]),
'target_temp_step': 0.5,
}),
'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.test_name',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Test name',
'platform': 'shelly',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 401>,
'translation_key': None,
'unique_id': '123456789ABC-sensor_0',
'unit_of_measurement': None,
})
# ---
# name: test_climate_hvac_mode[climate.test_name-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_temperature': 22.1,
'friendly_name': 'Test name',
'hvac_action': <HVACAction.OFF: 'off'>,
'hvac_modes': list([
<HVACMode.OFF: 'off'>,
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 31,
'min_temp': 4,
'preset_mode': 'none',
'preset_modes': list([
'none',
'Profile1',
'Profile2',
]),
'supported_features': <ClimateEntityFeature: 401>,
'target_temp_step': 0.5,
'temperature': 4,
}),
'context': <ANY>,
'entity_id': 'climate.test_name',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_rpc_climate_hvac_mode[climate.test_name_thermostat_0-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'hvac_modes': list([
<HVACMode.OFF: 'off'>,
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 35,
'min_temp': 5,
'target_temp_step': 0.5,
}),
'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.test_name_thermostat_0',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Test name Thermostat 0',
'platform': 'shelly',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 385>,
'translation_key': None,
'unique_id': '123456789ABC-thermostat:0',
'unit_of_measurement': None,
})
# ---
# name: test_rpc_climate_hvac_mode[climate.test_name_thermostat_0-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_humidity': 44.4,
'current_temperature': 12.3,
'friendly_name': 'Test name Thermostat 0',
'hvac_action': <HVACAction.HEATING: 'heating'>,
'hvac_modes': list([
<HVACMode.OFF: 'off'>,
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 35,
'min_temp': 5,
'supported_features': <ClimateEntityFeature: 385>,
'target_temp_step': 0.5,
'temperature': 23,
}),
'context': <ANY>,
'entity_id': 'climate.test_name_thermostat_0',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'heat',
})
# ---
# name: test_wall_display_thermostat_mode[climate.test_name_thermostat_0-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'hvac_modes': list([
<HVACMode.OFF: 'off'>,
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 35,
'min_temp': 5,
'target_temp_step': 0.5,
}),
'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.test_name_thermostat_0',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Test name Thermostat 0',
'platform': 'shelly',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 385>,
'translation_key': None,
'unique_id': '123456789ABC-thermostat:0',
'unit_of_measurement': None,
})
# ---
# name: test_wall_display_thermostat_mode[climate.test_name_thermostat_0-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_humidity': 44.4,
'current_temperature': 12.3,
'friendly_name': 'Test name Thermostat 0',
'hvac_action': <HVACAction.HEATING: 'heating'>,
'hvac_modes': list([
<HVACMode.OFF: 'off'>,
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 35,
'min_temp': 5,
'supported_features': <ClimateEntityFeature: 385>,
'target_temp_step': 0.5,
'temperature': 23,
}),
'context': <ANY>,
'entity_id': 'climate.test_name_thermostat_0',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'heat',
})
# ---

View File

@ -11,6 +11,7 @@ from aioshelly.const import (
)
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
import pytest
from syrupy import SnapshotAssertion
from homeassistant.components.climate import (
ATTR_CURRENT_HUMIDITY,
@ -65,6 +66,7 @@ async def test_climate_hvac_mode(
mock_block_device: Mock,
monkeypatch: pytest.MonkeyPatch,
entity_registry: EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test climate hvac mode service."""
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
@ -84,11 +86,10 @@ async def test_climate_hvac_mode(
# Test initial hvac mode - off
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.OFF
assert state == snapshot(name=f"{ENTITY_ID}-state")
entry = entity_registry.async_get(ENTITY_ID)
assert entry
assert entry.unique_id == "123456789ABC-sensor_0"
assert entry == snapshot(name=f"{ENTITY_ID}-entry")
# Test set hvac mode heat
await hass.services.async_call(
@ -603,6 +604,7 @@ async def test_rpc_climate_hvac_mode(
entity_registry: EntityRegistry,
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
snapshot: SnapshotAssertion,
) -> None:
"""Test climate hvac mode service."""
entity_id = "climate.test_name_thermostat_0"
@ -610,15 +612,10 @@ async def test_rpc_climate_hvac_mode(
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
state = hass.states.get(entity_id)
assert state.state == HVACMode.HEAT
assert state.attributes[ATTR_TEMPERATURE] == 23
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 12.3
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.HEATING
assert state.attributes[ATTR_CURRENT_HUMIDITY] == 44.4
assert state == snapshot(name=f"{entity_id}-state")
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "123456789ABC-thermostat:0"
assert entry == snapshot(name=f"{entity_id}-entry")
monkeypatch.setitem(mock_rpc_device.status["thermostat:0"], "output", False)
mock_rpc_device.mock_update()
@ -717,6 +714,7 @@ async def test_wall_display_thermostat_mode(
mock_rpc_device: Mock,
entity_registry: EntityRegistry,
monkeypatch: pytest.MonkeyPatch,
snapshot: SnapshotAssertion,
) -> None:
"""Test Wall Display in thermostat mode."""
climate_entity_id = "climate.test_name_thermostat_0"
@ -730,13 +728,11 @@ async def test_wall_display_thermostat_mode(
# the climate entity should be created
state = hass.states.get(climate_entity_id)
assert state
assert state.state == HVACMode.HEAT
assert state == snapshot(name=f"{climate_entity_id}-state")
assert len(hass.states.async_entity_ids(CLIMATE_DOMAIN)) == 1
entry = entity_registry.async_get(climate_entity_id)
assert entry
assert entry.unique_id == "123456789ABC-thermostat:0"
assert entry == snapshot(name=f"{climate_entity_id}-entry")
async def test_wall_display_thermostat_mode_external_actuator(
@ -776,7 +772,9 @@ async def test_wall_display_thermostat_mode_external_actuator(
async def test_blu_trv_climate_set_temperature(
hass: HomeAssistant,
mock_blu_trv: Mock,
entity_registry: EntityRegistry,
monkeypatch: pytest.MonkeyPatch,
snapshot: SnapshotAssertion,
) -> None:
"""Test BLU TRV set target temperature."""
@ -785,6 +783,12 @@ async def test_blu_trv_climate_set_temperature(
await init_integration(hass, 3, model=MODEL_BLU_GATEWAY_G3)
state = hass.states.get(entity_id)
assert state == snapshot(name=f"{entity_id}-state")
entry = entity_registry.async_get(entity_id)
assert entry == snapshot(name=f"{entity_id}-entry")
assert get_entity_attribute(hass, entity_id, ATTR_TEMPERATURE) == 17.1
monkeypatch.setitem(