Use snapshot in deCONZ scene tests (#122540)

This commit is contained in:
Robert Svensson 2024-07-24 17:32:57 +02:00 committed by GitHub
parent a8e60a6c53
commit 5bda072141
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 38 deletions

View File

@ -0,0 +1,47 @@
# serializer version: 1
# name: test_scenes[group_payload0-expected0][scene.light_group_scene-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'scene',
'entity_category': None,
'entity_id': 'scene.light_group_scene',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Scene',
'platform': 'deconz',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '01234E56789A/groups/1/scenes/1',
'unit_of_measurement': None,
})
# ---
# name: test_scenes[group_payload0-expected0][scene.light_group_scene-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Light group Scene',
}),
'context': <ANY>,
'entity_id': 'scene.light_group_scene',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---

View File

@ -2,17 +2,19 @@
from collections.abc import Callable
from typing import Any
from unittest.mock import patch
import pytest
from syrupy import SnapshotAssertion
from homeassistant.components.scene import DOMAIN as SCENE_DOMAIN, SERVICE_TURN_ON
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE
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 .conftest import WebsocketDataType
from .conftest import ConfigEntryFactoryType, WebsocketDataType
from tests.common import snapshot_platform
from tests.test_util.aiohttp import AiohttpClientMocker
TEST_DATA = [
@ -29,14 +31,7 @@ TEST_DATA = [
}
},
{
"entity_count": 2,
"device_count": 3,
"entity_id": "scene.light_group_scene",
"unique_id": "01234E56789A/groups/1/scenes/1",
"entity_category": None,
"attributes": {
"friendly_name": "Light group Scene",
},
"request": "/groups/1/scenes/1/recall",
},
),
@ -46,36 +41,16 @@ TEST_DATA = [
@pytest.mark.parametrize(("group_payload", "expected"), TEST_DATA)
async def test_scenes(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
config_entry_setup: ConfigEntry,
config_entry_factory: ConfigEntryFactoryType,
mock_put_request: Callable[[str, str], AiohttpClientMocker],
expected: dict[str, Any],
snapshot: SnapshotAssertion,
) -> None:
"""Test successful creation of scene entities."""
assert len(hass.states.async_all()) == expected["entity_count"]
# Verify state data
scene = hass.states.get(expected["entity_id"])
assert scene.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.SCENE]):
config_entry = await config_entry_factory()
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
# Verify button press
@ -91,12 +66,12 @@ async def test_scenes(
# 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