diff --git a/tests/components/gree/common.py b/tests/components/gree/common.py index cd8a2d6ee28..aa88688486c 100644 --- a/tests/components/gree/common.py +++ b/tests/components/gree/common.py @@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, Mock from greeclimate.discovery import Listener from homeassistant.components.gree.const import DISCOVERY_TIMEOUT, DOMAIN as GREE_DOMAIN +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry @@ -90,8 +91,10 @@ def build_device_mock(name="fake-device-1", ipAddress="1.1.1.1", mac="aabbcc1122 return mock -async def async_setup_gree(hass): +async def async_setup_gree(hass: HomeAssistant) -> MockConfigEntry: """Set up the gree platform.""" - MockConfigEntry(domain=GREE_DOMAIN).add_to_hass(hass) + entry = MockConfigEntry(domain=GREE_DOMAIN) + entry.add_to_hass(hass) await async_setup_component(hass, GREE_DOMAIN, {GREE_DOMAIN: {"climate": {}}}) await hass.async_block_till_done() + return entry diff --git a/tests/components/gree/snapshots/test_climate.ambr b/tests/components/gree/snapshots/test_climate.ambr new file mode 100644 index 00000000000..f1479cad3d3 --- /dev/null +++ b/tests/components/gree/snapshots/test_climate.ambr @@ -0,0 +1,118 @@ +# serializer version: 1 +# name: test_entity_states + list([ + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'current_temperature': 25, + 'fan_mode': 'auto', + 'fan_modes': list([ + 'auto', + 'low', + 'medium low', + 'medium', + 'medium high', + 'high', + ]), + 'friendly_name': 'fake-device-1', + 'hvac_modes': list([ + , + , + , + , + , + , + ]), + 'max_temp': 30, + 'min_temp': 8, + 'preset_mode': 'none', + 'preset_modes': list([ + 'eco', + 'away', + 'boost', + 'none', + 'sleep', + ]), + 'supported_features': , + 'swing_mode': 'off', + 'swing_modes': list([ + 'off', + 'vertical', + 'horizontal', + 'both', + ]), + 'target_temp_step': 1, + 'temperature': 25, + }), + 'context': , + 'entity_id': 'climate.fake_device_1', + 'last_changed': , + 'last_updated': , + 'state': 'off', + }), + ]) +# --- +# name: test_registry_settings + list([ + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'fan_modes': list([ + 'auto', + 'low', + 'medium low', + 'medium', + 'medium high', + 'high', + ]), + 'hvac_modes': list([ + , + , + , + , + , + , + ]), + 'max_temp': 30, + 'min_temp': 8, + 'preset_modes': list([ + 'eco', + 'away', + 'boost', + 'none', + 'sleep', + ]), + 'swing_modes': list([ + 'off', + 'vertical', + 'horizontal', + 'both', + ]), + 'target_temp_step': 1, + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'climate', + 'entity_category': None, + 'entity_id': 'climate.fake_device_1', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'fake-device-1', + 'platform': 'gree', + 'supported_features': , + 'translation_key': None, + 'unique_id': 'aabbcc112233', + 'unit_of_measurement': None, + }), + ]) +# --- diff --git a/tests/components/gree/test_climate.py b/tests/components/gree/test_climate.py index 16b6d0cf3ad..afed01c1a08 100644 --- a/tests/components/gree/test_climate.py +++ b/tests/components/gree/test_climate.py @@ -5,6 +5,7 @@ from unittest.mock import DEFAULT as DEFAULT_MOCK, AsyncMock, patch from greeclimate.device import HorizontalSwing, VerticalSwing from greeclimate.exceptions import DeviceNotBoundError, DeviceTimeoutError import pytest +from syrupy.assertion import SnapshotAssertion from homeassistant.components.climate import ( ATTR_CURRENT_TEMPERATURE, @@ -31,15 +32,12 @@ from homeassistant.components.climate import ( SWING_HORIZONTAL, SWING_OFF, SWING_VERTICAL, - ClimateEntityFeature, HVACMode, ) from homeassistant.components.gree.climate import FAN_MODES_REVERSE, HVAC_MODES_REVERSE from homeassistant.components.gree.const import FAN_MEDIUM_HIGH, FAN_MEDIUM_LOW from homeassistant.const import ( ATTR_ENTITY_ID, - ATTR_FRIENDLY_NAME, - ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE, SERVICE_TURN_OFF, SERVICE_TURN_ON, @@ -47,6 +45,7 @@ from homeassistant.const import ( UnitOfTemperature, ) from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er import homeassistant.util.dt as dt_util from .common import async_setup_gree, build_device_mock @@ -797,22 +796,20 @@ async def test_update_swing_mode( assert state.attributes.get(ATTR_SWING_MODE) == swing_mode -async def test_name(hass: HomeAssistant, discovery, device) -> None: - """Test for name property.""" - await async_setup_gree(hass) - state = hass.states.get(ENTITY_ID) - assert state.attributes[ATTR_FRIENDLY_NAME] == "fake-device-1" - - -async def test_supported_features_with_turnon( - hass: HomeAssistant, discovery, device +@patch("homeassistant.components.gree.PLATFORMS", [DOMAIN]) +async def test_registry_settings( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion ) -> None: - """Test for supported_features property.""" + """Test for entity registry settings (unique_id).""" + entry = await async_setup_gree(hass) + + entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id) + assert entries == snapshot + + +@patch("homeassistant.components.gree.PLATFORMS", [DOMAIN]) +async def test_entity_states(hass: HomeAssistant, snapshot: SnapshotAssertion) -> None: + """Test for entity registry settings (unique_id).""" await async_setup_gree(hass) - state = hass.states.get(ENTITY_ID) - assert state.attributes[ATTR_SUPPORTED_FEATURES] == ( - ClimateEntityFeature.TARGET_TEMPERATURE - | ClimateEntityFeature.FAN_MODE - | ClimateEntityFeature.PRESET_MODE - | ClimateEntityFeature.SWING_MODE - ) + states = hass.states.async_all() + assert states == snapshot