diff --git a/tests/components/deconz/snapshots/test_button.ambr b/tests/components/deconz/snapshots/test_button.ambr new file mode 100644 index 00000000000..1ef5248ebc3 --- /dev/null +++ b/tests/components/deconz/snapshots/test_button.ambr @@ -0,0 +1,95 @@ +# serializer version: 1 +# name: test_button[deconz_payload0-expected0][button.light_group_scene_store_current_scene-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'button', + 'entity_category': , + 'entity_id': 'button.light_group_scene_store_current_scene', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': 'mdi:inbox-arrow-down', + 'original_name': 'Scene Store Current Scene', + 'platform': 'deconz', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '01234E56789A/groups/1/scenes/1-store', + 'unit_of_measurement': None, + }) +# --- +# name: test_button[deconz_payload0-expected0][button.light_group_scene_store_current_scene-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Light group Scene Store Current Scene', + 'icon': 'mdi:inbox-arrow-down', + }), + 'context': , + 'entity_id': 'button.light_group_scene_store_current_scene', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- +# name: test_button[deconz_payload1-expected1][button.aqara_fp1_reset_presence-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'button', + 'entity_category': , + 'entity_id': 'button.aqara_fp1_reset_presence', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Aqara FP1 Reset Presence', + 'platform': 'deconz', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'xx:xx:xx:xx:xx:xx:xx:xx-01-0406-reset_presence', + 'unit_of_measurement': None, + }) +# --- +# name: test_button[deconz_payload1-expected1][button.aqara_fp1_reset_presence-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'restart', + 'friendly_name': 'Aqara FP1 Reset Presence', + }), + 'context': , + 'entity_id': 'button.aqara_fp1_reset_presence', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- diff --git a/tests/components/deconz/test_button.py b/tests/components/deconz/test_button.py index 1ddcbd8f105..8acc3bbb819 100644 --- a/tests/components/deconz/test_button.py +++ b/tests/components/deconz/test_button.py @@ -1,15 +1,19 @@ """deCONZ button platform tests.""" from collections.abc import Callable +from typing import Any +from unittest.mock import patch import pytest +from syrupy import SnapshotAssertion from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, EntityCategory +from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.helpers import entity_registry as er +from tests.common import snapshot_platform from tests.test_util.aiohttp import AiohttpClientMocker TEST_DATA = [ @@ -28,15 +32,7 @@ TEST_DATA = [ } }, { - "entity_count": 2, - "device_count": 3, "entity_id": "button.light_group_scene_store_current_scene", - "unique_id": "01234E56789A/groups/1/scenes/1-store", - "entity_category": EntityCategory.CONFIG, - "attributes": { - "icon": "mdi:inbox-arrow-down", - "friendly_name": "Light group Scene Store Current Scene", - }, "request": "/groups/1/scenes/1/store", "request_data": {}, }, @@ -70,15 +66,7 @@ TEST_DATA = [ } }, { - "entity_count": 5, - "device_count": 3, "entity_id": "button.aqara_fp1_reset_presence", - "unique_id": "xx:xx:xx:xx:xx:xx:xx:xx-01-0406-reset_presence", - "entity_category": EntityCategory.CONFIG, - "attributes": { - "device_class": "restart", - "friendly_name": "Aqara FP1 Reset Presence", - }, "request": "/sensors/1/config", "request_data": {"resetpresence": True}, }, @@ -90,36 +78,16 @@ TEST_DATA = [ async def test_button( hass: HomeAssistant, entity_registry: er.EntityRegistry, - device_registry: dr.DeviceRegistry, aioclient_mock: AiohttpClientMocker, - config_entry_setup: ConfigEntry, + config_entry_factory: ConfigEntry, mock_put_request: Callable[[str, str], AiohttpClientMocker], - expected, + expected: dict[str, Any], + snapshot: SnapshotAssertion, ) -> None: """Test successful creation of button entities.""" - assert len(hass.states.async_all()) == expected["entity_count"] - - # Verify state data - - button = hass.states.get(expected["entity_id"]) - assert button.attributes == expected["attributes"] - - # Verify entity registry data - - ent_reg_entry = entity_registry.async_get(expected["entity_id"]) - assert ent_reg_entry.entity_category is expected["entity_category"] - assert ent_reg_entry.unique_id == expected["unique_id"] - - # Verify device registry data - - assert ( - len( - dr.async_entries_for_config_entry( - device_registry, config_entry_setup.entry_id - ) - ) - == expected["device_count"] - ) + with patch("homeassistant.components.deconz.PLATFORMS", [Platform.BUTTON]): + config_entry = await config_entry_factory() + await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id) # Verify button press @@ -135,11 +103,11 @@ async def test_button( # Unload entry - await hass.config_entries.async_unload(config_entry_setup.entry_id) + await hass.config_entries.async_unload(config_entry.entry_id) assert hass.states.get(expected["entity_id"]).state == STATE_UNAVAILABLE # Remove entry - await hass.config_entries.async_remove(config_entry_setup.entry_id) + await hass.config_entries.async_remove(config_entry.entry_id) await hass.async_block_till_done() assert len(hass.states.async_all()) == 0