diff --git a/tests/components/gree/snapshots/test_switch.ambr b/tests/components/gree/snapshots/test_switch.ambr new file mode 100644 index 00000000000..73056fcc465 --- /dev/null +++ b/tests/components/gree/snapshots/test_switch.ambr @@ -0,0 +1,206 @@ +# serializer version: 1 +# name: test_entity_state + list([ + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'switch', + 'friendly_name': 'fake-device-1 Panel Light', + 'icon': 'mdi:lightbulb', + }), + 'context': , + 'entity_id': 'switch.fake_device_1_panel_light', + 'last_changed': , + 'last_updated': , + 'state': 'on', + }), + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'switch', + 'friendly_name': 'fake-device-1 Quiet', + }), + 'context': , + 'entity_id': 'switch.fake_device_1_quiet', + 'last_changed': , + 'last_updated': , + 'state': 'off', + }), + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'switch', + 'friendly_name': 'fake-device-1 Fresh Air', + }), + 'context': , + 'entity_id': 'switch.fake_device_1_fresh_air', + 'last_changed': , + 'last_updated': , + 'state': 'on', + }), + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'switch', + 'friendly_name': 'fake-device-1 XFan', + }), + 'context': , + 'entity_id': 'switch.fake_device_1_xfan', + 'last_changed': , + 'last_updated': , + 'state': 'on', + }), + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'switch', + 'friendly_name': 'fake-device-1 Health mode', + 'icon': 'mdi:pine-tree', + }), + 'context': , + 'entity_id': 'switch.fake_device_1_health_mode', + 'last_changed': , + 'last_updated': , + 'state': 'on', + }), + ]) +# --- +# name: test_registry_settings + list([ + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.fake_device_1_panel_light', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': 'mdi:lightbulb', + 'original_name': 'fake-device-1 Panel Light', + 'platform': 'gree', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'aabbcc112233_Panel Light', + 'unit_of_measurement': None, + }), + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.fake_device_1_quiet', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'fake-device-1 Quiet', + 'platform': 'gree', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'aabbcc112233_Quiet', + 'unit_of_measurement': None, + }), + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.fake_device_1_fresh_air', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'fake-device-1 Fresh Air', + 'platform': 'gree', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'aabbcc112233_Fresh Air', + 'unit_of_measurement': None, + }), + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.fake_device_1_xfan', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'fake-device-1 XFan', + 'platform': 'gree', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'aabbcc112233_XFan', + 'unit_of_measurement': None, + }), + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': , + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.fake_device_1_health_mode', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': 'mdi:pine-tree', + 'original_name': 'fake-device-1 Health mode', + 'platform': 'gree', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'aabbcc112233_Health mode', + 'unit_of_measurement': None, + }), + ]) +# --- diff --git a/tests/components/gree/test_switch.py b/tests/components/gree/test_switch.py index 58c740b8591..aee9c985e8c 100644 --- a/tests/components/gree/test_switch.py +++ b/tests/components/gree/test_switch.py @@ -1,13 +1,14 @@ """Tests for gree component.""" +from unittest.mock import patch from greeclimate.exceptions import DeviceTimeoutError import pytest +from syrupy.assertion import SnapshotAssertion from homeassistant.components.gree.const import DOMAIN as GREE_DOMAIN from homeassistant.components.switch import DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, - ATTR_FRIENDLY_NAME, SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON, @@ -27,21 +28,26 @@ ENTITY_ID_FRESH_AIR = f"{DOMAIN}.fake_device_1_fresh_air" ENTITY_ID_XFAN = f"{DOMAIN}.fake_device_1_xfan" -async def async_setup_gree(hass): +async def async_setup_gree(hass: HomeAssistant) -> MockConfigEntry: """Set up the gree switch 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: {DOMAIN: {}}}) await hass.async_block_till_done() + return entry -async def test_health_mode_disabled_by_default(hass): - """Test for making sure health mode is disabled on first load.""" - await async_setup_gree(hass) +@patch("homeassistant.components.gree.PLATFORMS", [DOMAIN]) +async def test_registry_settings( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test for entity registry settings (disabled_by, unique_id).""" + entry = await async_setup_gree(hass) - assert ( - er.async_get(hass).async_get(ENTITY_ID_HEALTH_MODE).disabled_by - == er.RegistryEntryDisabler.INTEGRATION - ) + state = er.async_entries_for_config_entry(entity_registry, entry.entry_id) + assert state == snapshot @pytest.mark.parametrize( @@ -183,20 +189,14 @@ async def test_send_switch_toggle( assert state.state == STATE_ON -@pytest.mark.parametrize( - ("entity", "name"), - [ - (ENTITY_ID_LIGHT_PANEL, "Panel Light"), - (ENTITY_ID_HEALTH_MODE, "Health mode"), - (ENTITY_ID_QUIET, "Quiet"), - (ENTITY_ID_FRESH_AIR, "Fresh Air"), - (ENTITY_ID_XFAN, "XFan"), - ], -) -async def test_entity_name( - hass: HomeAssistant, entity, name, entity_registry_enabled_by_default: None +@pytest.mark.usefixtures("entity_registry_enabled_by_default") +async def test_entity_state( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + snapshot: SnapshotAssertion, ) -> None: - """Test for name property.""" + """Test for entity registry settings (disabled_by, unique_id).""" await async_setup_gree(hass) - state = hass.states.get(entity) - assert state.attributes[ATTR_FRIENDLY_NAME] == f"fake-device-1 {name}" + + state = hass.states.async_all(DOMAIN) + assert state == snapshot