Use snapshot in deCONZ cover tests (#122537)

This commit is contained in:
Robert Svensson 2024-07-24 17:14:40 +02:00 committed by GitHub
parent 6393f1f02d
commit c5f9ff6ac5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 181 additions and 30 deletions

View File

@ -0,0 +1,150 @@
# serializer version: 1
# name: test_cover[light_payload0][cover.window_covering_device-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'cover',
'entity_category': None,
'entity_id': 'cover.window_covering_device',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <CoverDeviceClass.SHADE: 'shade'>,
'original_icon': None,
'original_name': 'Window covering device',
'platform': 'deconz',
'previous_unique_id': None,
'supported_features': <CoverEntityFeature: 15>,
'translation_key': None,
'unique_id': '00:00:00:00:00:00:00:01-00',
'unit_of_measurement': None,
})
# ---
# name: test_cover[light_payload0][cover.window_covering_device-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_position': 0,
'device_class': 'shade',
'friendly_name': 'Window covering device',
'supported_features': <CoverEntityFeature: 15>,
}),
'context': <ANY>,
'entity_id': 'cover.window_covering_device',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'closed',
})
# ---
# name: test_level_controllable_output_cover[light_payload0][cover.vent-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'cover',
'entity_category': None,
'entity_id': 'cover.vent',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <CoverDeviceClass.DAMPER: 'damper'>,
'original_icon': None,
'original_name': 'Vent',
'platform': 'deconz',
'previous_unique_id': None,
'supported_features': <CoverEntityFeature: 255>,
'translation_key': None,
'unique_id': '00:22:a3:00:00:00:00:00-01',
'unit_of_measurement': None,
})
# ---
# name: test_level_controllable_output_cover[light_payload0][cover.vent-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_position': 5,
'current_tilt_position': 97,
'device_class': 'damper',
'friendly_name': 'Vent',
'supported_features': <CoverEntityFeature: 255>,
}),
'context': <ANY>,
'entity_id': 'cover.vent',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'open',
})
# ---
# name: test_tilt_cover[light_payload0][cover.covering_device-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'cover',
'entity_category': None,
'entity_id': 'cover.covering_device',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <CoverDeviceClass.SHADE: 'shade'>,
'original_icon': None,
'original_name': 'Covering device',
'platform': 'deconz',
'previous_unique_id': None,
'supported_features': <CoverEntityFeature: 255>,
'translation_key': None,
'unique_id': '00:24:46:00:00:12:34:56-01',
'unit_of_measurement': None,
})
# ---
# name: test_tilt_cover[light_payload0][cover.covering_device-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_position': 100,
'current_tilt_position': 100,
'device_class': 'shade',
'friendly_name': 'Covering device',
'supported_features': <CoverEntityFeature: 255>,
}),
'context': <ANY>,
'entity_id': 'cover.covering_device',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'open',
})
# ---

View File

@ -1,12 +1,13 @@
"""deCONZ cover platform tests.""" """deCONZ cover platform tests."""
from collections.abc import Callable from collections.abc import Callable
from unittest.mock import patch
import pytest import pytest
from syrupy import SnapshotAssertion
from homeassistant.components.cover import ( from homeassistant.components.cover import (
ATTR_CURRENT_POSITION, ATTR_CURRENT_POSITION,
ATTR_CURRENT_TILT_POSITION,
ATTR_POSITION, ATTR_POSITION,
ATTR_TILT_POSITION, ATTR_TILT_POSITION,
DOMAIN as COVER_DOMAIN, DOMAIN as COVER_DOMAIN,
@ -19,17 +20,13 @@ from homeassistant.components.cover import (
SERVICE_STOP_COVER, SERVICE_STOP_COVER,
SERVICE_STOP_COVER_TILT, SERVICE_STOP_COVER_TILT,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_ENTITY_ID, STATE_OPEN, STATE_UNAVAILABLE, Platform
from homeassistant.const import (
ATTR_ENTITY_ID,
STATE_CLOSED,
STATE_OPEN,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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 from tests.test_util.aiohttp import AiohttpClientMocker
@ -55,16 +52,16 @@ from tests.test_util.aiohttp import AiohttpClientMocker
) )
async def test_cover( async def test_cover(
hass: HomeAssistant, hass: HomeAssistant,
config_entry_setup: ConfigEntry, entity_registry: er.EntityRegistry,
config_entry_factory: ConfigEntryFactoryType,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
light_ws_data: WebsocketDataType, light_ws_data: WebsocketDataType,
snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test that all supported cover entities are created.""" """Test that all supported cover entities are created."""
assert len(hass.states.async_all()) == 2 with patch("homeassistant.components.deconz.PLATFORMS", [Platform.COVER]):
cover = hass.states.get("cover.window_covering_device") config_entry = await config_entry_factory()
assert cover.state == STATE_CLOSED await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
assert cover.attributes[ATTR_CURRENT_POSITION] == 0
assert not hass.states.get("cover.unsupported_cover")
# Event signals cover is open # Event signals cover is open
@ -117,14 +114,14 @@ async def test_cover(
) )
assert aioclient_mock.mock_calls[4][2] == {"stop": True} assert aioclient_mock.mock_calls[4][2] == {"stop": True}
await hass.config_entries.async_unload(config_entry_setup.entry_id) await hass.config_entries.async_unload(config_entry.entry_id)
states = hass.states.async_all() states = hass.states.async_all()
assert len(states) == 2 assert len(states) == 1
for state in states: for state in states:
assert state.state == STATE_UNAVAILABLE assert state.state == STATE_UNAVAILABLE
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() await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
@ -153,15 +150,17 @@ async def test_cover(
} }
], ],
) )
@pytest.mark.usefixtures("config_entry_setup")
async def test_tilt_cover( async def test_tilt_cover(
hass: HomeAssistant, mock_put_request: Callable[[str, str], AiohttpClientMocker] hass: HomeAssistant,
entity_registry: er.EntityRegistry,
config_entry_factory: ConfigEntryFactoryType,
mock_put_request: Callable[[str, str], AiohttpClientMocker],
snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test that tilting a cover works.""" """Test that tilting a cover works."""
assert len(hass.states.async_all()) == 1 with patch("homeassistant.components.deconz.PLATFORMS", [Platform.COVER]):
covering_device = hass.states.get("cover.covering_device") config_entry = await config_entry_factory()
assert covering_device.state == STATE_OPEN await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
assert covering_device.attributes[ATTR_CURRENT_TILT_POSITION] == 100
# Verify service calls for tilting cover # Verify service calls for tilting cover
@ -232,15 +231,17 @@ async def test_tilt_cover(
} }
], ],
) )
@pytest.mark.usefixtures("config_entry_setup")
async def test_level_controllable_output_cover( async def test_level_controllable_output_cover(
hass: HomeAssistant, mock_put_request: Callable[[str, str], AiohttpClientMocker] hass: HomeAssistant,
entity_registry: er.EntityRegistry,
config_entry_factory: ConfigEntryFactoryType,
mock_put_request: Callable[[str, str], AiohttpClientMocker],
snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test that tilting a cover works.""" """Test that tilting a cover works."""
assert len(hass.states.async_all()) == 1 with patch("homeassistant.components.deconz.PLATFORMS", [Platform.COVER]):
covering_device = hass.states.get("cover.vent") config_entry = await config_entry_factory()
assert covering_device.state == STATE_OPEN await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
assert covering_device.attributes[ATTR_CURRENT_TILT_POSITION] == 97
# Verify service calls for tilting cover # Verify service calls for tilting cover