From 7e94b9aa053575381feb03c61472b5f83a02b170 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 10 Sep 2026 19:43:22 +0200 Subject: [PATCH] Use snapshot_platform helper in adax climate tests (#181820) --- .../adax/snapshots/test_climate.ambr | 139 ++++++++++++++++++ tests/components/adax/test_climate.py | 105 +++++++------ 2 files changed, 202 insertions(+), 42 deletions(-) create mode 100644 tests/components/adax/snapshots/test_climate.ambr diff --git a/tests/components/adax/snapshots/test_climate.ambr b/tests/components/adax/snapshots/test_climate.ambr new file mode 100644 index 000000000000..b0898c1f64ee --- /dev/null +++ b/tests/components/adax/snapshots/test_climate.ambr @@ -0,0 +1,139 @@ +# serializer version: 1 +# name: test_all_entities_cloud[climate.room_1-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : list([ + , + , + ]), + : 35, + : 5, + : 1, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'climate', + 'entity_category': None, + 'entity_id': 'climate.room_1', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Room 1', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': 'mdi:radiator', + 'original_name': 'Room 1', + 'platform': 'adax', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': , + 'translation_key': None, + 'unique_id': '1_1', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities_cloud[climate.room_1-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 15, + : 'Room 1', + : list([ + , + , + ]), + : 'mdi:radiator', + : 35, + : 5, + : , + : 1, + : 20, + }), + 'context': , + 'entity_id': 'climate.room_1', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'heat', + }) +# --- +# name: test_all_entities_local[climate.mock_title-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : list([ + , + , + ]), + : 35, + : 5, + : 1, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'climate', + 'entity_category': None, + 'entity_id': 'climate.mock_title', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': 'mdi:radiator-off', + 'original_name': None, + 'platform': 'adax', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': , + 'translation_key': None, + 'unique_id': '11:22:33:44:55:66', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities_local[climate.mock_title-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 15, + : 'Mock Title', + : list([ + , + , + ]), + : 'mdi:radiator', + : 35, + : 5, + : , + : 1, + : 20, + }), + 'context': , + 'entity_id': 'climate.mock_title', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'heat', + }) +# --- diff --git a/tests/components/adax/test_climate.py b/tests/components/adax/test_climate.py index d93db72e722d..9e0105c9377b 100644 --- a/tests/components/adax/test_climate.py +++ b/tests/components/adax/test_climate.py @@ -1,24 +1,79 @@ """Test Adax climate entity.""" +from collections.abc import Generator +from unittest.mock import patch + +import pytest +from syrupy.assertion import SnapshotAssertion + from homeassistant.components.adax.const import SCAN_INTERVAL from homeassistant.components.climate import ( - ATTR_CURRENT_TEMPERATURE, ATTR_HVAC_MODE, DOMAIN as CLIMATE_DOMAIN, SERVICE_SET_HVAC_MODE, SERVICE_SET_TEMPERATURE, + ClimateEntityStateAttribute, HVACMode, ) -from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_UNAVAILABLE +from homeassistant.const import ( + ATTR_ENTITY_ID, + ATTR_TEMPERATURE, + STATE_UNAVAILABLE, + Platform, +) from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from . import setup_integration -from .conftest import CLOUD_DEVICE_DATA -from tests.common import AsyncMock, MockConfigEntry, async_fire_time_changed +from tests.common import ( + AsyncMock, + MockConfigEntry, + async_fire_time_changed, + snapshot_platform, +) from tests.test_setup import FrozenDateTimeFactory +@pytest.fixture(autouse=True) +def override_platforms() -> Generator[None]: + """Override PLATFORMS.""" + with patch("homeassistant.components.adax.PLATFORMS", [Platform.CLIMATE]): + yield + + +async def test_all_entities_cloud( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_cloud_config_entry: MockConfigEntry, + mock_adax_cloud: AsyncMock, + snapshot: SnapshotAssertion, +) -> None: + """Test all entities for a cloud connection.""" + await setup_integration(hass, mock_cloud_config_entry) + mock_adax_cloud.fetch_rooms_info.assert_called_once() + + await snapshot_platform( + hass, entity_registry, snapshot, mock_cloud_config_entry.entry_id + ) + + +async def test_all_entities_local( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_local_config_entry: MockConfigEntry, + mock_adax_local: AsyncMock, + snapshot: SnapshotAssertion, +) -> None: + """Test all entities for a local connection.""" + await setup_integration(hass, mock_local_config_entry) + mock_adax_local.get_status.assert_called_once() + + await snapshot_platform( + hass, entity_registry, snapshot, mock_local_config_entry.entry_id + ) + + async def test_climate_cloud( hass: HomeAssistant, freezer: FrozenDateTimeFactory, @@ -29,21 +84,8 @@ async def test_climate_cloud( await setup_integration(hass, mock_cloud_config_entry) mock_adax_cloud.fetch_rooms_info.assert_called_once() - assert len(hass.states.async_entity_ids(CLIMATE_DOMAIN)) == 1 entity_id = hass.states.async_entity_ids(CLIMATE_DOMAIN)[0] - state = hass.states.get(entity_id) - - assert state - assert state.state == HVACMode.HEAT - assert ( - state.attributes[ATTR_TEMPERATURE] == CLOUD_DEVICE_DATA[0]["targetTemperature"] - ) - assert ( - state.attributes[ATTR_CURRENT_TEMPERATURE] - == CLOUD_DEVICE_DATA[0]["temperature"] - ) - mock_adax_cloud.fetch_rooms_info.side_effect = Exception() freezer.tick(SCAN_INTERVAL) async_fire_time_changed(hass) @@ -64,7 +106,6 @@ async def test_climate_local( await setup_integration(hass, mock_local_config_entry) mock_adax_local.get_status.assert_called_once() - assert len(hass.states.async_entity_ids(CLIMATE_DOMAIN)) == 1 entity_id = hass.states.async_entity_ids(CLIMATE_DOMAIN)[0] freezer.tick(SCAN_INTERVAL) @@ -74,8 +115,6 @@ async def test_climate_local( state = hass.states.get(entity_id) assert state assert state.state == HVACMode.HEAT - assert state.attributes[ATTR_TEMPERATURE] == 20 - assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 15 mock_adax_local.get_status.side_effect = Exception() freezer.tick(SCAN_INTERVAL) @@ -87,24 +126,6 @@ async def test_climate_local( assert state.state == STATE_UNAVAILABLE -async def test_climate_local_initial_state_from_first_refresh( - hass: HomeAssistant, - mock_local_config_entry: MockConfigEntry, - mock_adax_local: AsyncMock, -) -> None: - """Test that local climate state is initialized from first refresh data.""" - await setup_integration(hass, mock_local_config_entry) - - assert len(hass.states.async_entity_ids(CLIMATE_DOMAIN)) == 1 - entity_id = hass.states.async_entity_ids(CLIMATE_DOMAIN)[0] - - state = hass.states.get(entity_id) - assert state - assert state.state == HVACMode.HEAT - assert state.attributes[ATTR_TEMPERATURE] == 20 - assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 15 - - async def test_climate_local_initial_state_off_from_first_refresh( hass: HomeAssistant, mock_local_config_entry: MockConfigEntry, @@ -121,8 +142,8 @@ async def test_climate_local_initial_state_off_from_first_refresh( state = hass.states.get(entity_id) assert state assert state.state == HVACMode.OFF - assert state.attributes[ATTR_TEMPERATURE] == 5 - assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 15 + assert state.attributes[ClimateEntityStateAttribute.TARGET_TEMPERATURE] == 5 + assert state.attributes[ClimateEntityStateAttribute.CURRENT_TEMPERATURE] == 15 async def test_climate_local_set_hvac_mode_updates_state_immediately( @@ -203,7 +224,7 @@ async def test_climate_local_set_temperature_when_off_does_not_change_hvac_mode( state = hass.states.get(entity_id) assert state assert state.state == HVACMode.OFF - assert state.attributes[ATTR_TEMPERATURE] == 23 + assert state.attributes[ClimateEntityStateAttribute.TARGET_TEMPERATURE] == 23 async def test_climate_local_set_temperature_when_heat_calls_device( @@ -233,4 +254,4 @@ async def test_climate_local_set_temperature_when_heat_calls_device( state = hass.states.get(entity_id) assert state assert state.state == HVACMode.HEAT - assert state.attributes[ATTR_TEMPERATURE] == 24 + assert state.attributes[ClimateEntityStateAttribute.TARGET_TEMPERATURE] == 24