mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 17:04:04 -04:00
Use snapshot_platform helper in adax climate tests (#181820)
This commit is contained in:
@@ -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({
|
||||
<ClimateEntityCapabilityAttribute.HVAC_MODES: 'hvac_modes'>: list([
|
||||
<HVACMode.HEAT: 'heat'>,
|
||||
<HVACMode.OFF: 'off'>,
|
||||
]),
|
||||
<ClimateEntityCapabilityAttribute.MAX_TEMP: 'max_temp'>: 35,
|
||||
<ClimateEntityCapabilityAttribute.MIN_TEMP: 'min_temp'>: 5,
|
||||
<ClimateEntityCapabilityAttribute.TARGET_TEMP_STEP: 'target_temp_step'>: 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.room_1',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'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': <ClimateEntityFeature: 385>,
|
||||
'translation_key': None,
|
||||
'unique_id': '1_1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities_cloud[climate.room_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<ClimateEntityStateAttribute.CURRENT_TEMPERATURE: 'current_temperature'>: 15,
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Room 1',
|
||||
<ClimateEntityCapabilityAttribute.HVAC_MODES: 'hvac_modes'>: list([
|
||||
<HVACMode.HEAT: 'heat'>,
|
||||
<HVACMode.OFF: 'off'>,
|
||||
]),
|
||||
<EntityStateAttribute.ICON: 'icon'>: 'mdi:radiator',
|
||||
<ClimateEntityCapabilityAttribute.MAX_TEMP: 'max_temp'>: 35,
|
||||
<ClimateEntityCapabilityAttribute.MIN_TEMP: 'min_temp'>: 5,
|
||||
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <ClimateEntityFeature: 385>,
|
||||
<ClimateEntityCapabilityAttribute.TARGET_TEMP_STEP: 'target_temp_step'>: 1,
|
||||
<ClimateEntityStateAttribute.TARGET_TEMPERATURE: 'temperature'>: 20,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'climate.room_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'heat',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities_local[climate.mock_title-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
<ClimateEntityCapabilityAttribute.HVAC_MODES: 'hvac_modes'>: list([
|
||||
<HVACMode.HEAT: 'heat'>,
|
||||
<HVACMode.OFF: 'off'>,
|
||||
]),
|
||||
<ClimateEntityCapabilityAttribute.MAX_TEMP: 'max_temp'>: 35,
|
||||
<ClimateEntityCapabilityAttribute.MIN_TEMP: 'min_temp'>: 5,
|
||||
<ClimateEntityCapabilityAttribute.TARGET_TEMP_STEP: 'target_temp_step'>: 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.mock_title',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'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': <ClimateEntityFeature: 385>,
|
||||
'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({
|
||||
<ClimateEntityStateAttribute.CURRENT_TEMPERATURE: 'current_temperature'>: 15,
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Mock Title',
|
||||
<ClimateEntityCapabilityAttribute.HVAC_MODES: 'hvac_modes'>: list([
|
||||
<HVACMode.HEAT: 'heat'>,
|
||||
<HVACMode.OFF: 'off'>,
|
||||
]),
|
||||
<EntityStateAttribute.ICON: 'icon'>: 'mdi:radiator',
|
||||
<ClimateEntityCapabilityAttribute.MAX_TEMP: 'max_temp'>: 35,
|
||||
<ClimateEntityCapabilityAttribute.MIN_TEMP: 'min_temp'>: 5,
|
||||
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <ClimateEntityFeature: 385>,
|
||||
<ClimateEntityCapabilityAttribute.TARGET_TEMP_STEP: 'target_temp_step'>: 1,
|
||||
<ClimateEntityStateAttribute.TARGET_TEMPERATURE: 'temperature'>: 20,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'climate.mock_title',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'heat',
|
||||
})
|
||||
# ---
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user