Use snapshot in Axis light tests (#122703)

This commit is contained in:
Robert Svensson 2024-07-27 17:41:42 +02:00 committed by GitHub
parent b0780e1db5
commit 6752bd450b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 74 additions and 10 deletions

View File

@ -0,0 +1,57 @@
# serializer version: 1
# name: test_lights[api_discovery_items0][light.home_ir_light_0-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'supported_color_modes': list([
<ColorMode.BRIGHTNESS: 'brightness'>,
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'light',
'entity_category': None,
'entity_id': 'light.home_ir_light_0',
'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': 'IR Light 0',
'platform': 'axis',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00:40:8c:12:34:56-tns1:Device/tnsaxis:Light/Status-0',
'unit_of_measurement': None,
})
# ---
# name: test_lights[api_discovery_items0][light.home_ir_light_0-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'brightness': 170,
'color_mode': <ColorMode.BRIGHTNESS: 'brightness'>,
'friendly_name': 'home IR Light 0',
'supported_color_modes': list([
<ColorMode.BRIGHTNESS: 'brightness'>,
]),
'supported_features': <LightEntityFeature: 0>,
}),
'context': <ANY>,
'entity_id': 'light.home_ir_light_0',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---

View File

@ -6,6 +6,7 @@ from unittest.mock import patch
from axis.models.api import CONTEXT
import pytest
import respx
from syrupy import SnapshotAssertion
from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN as LIGHT_DOMAIN
from homeassistant.const import (
@ -13,13 +14,16 @@ from homeassistant.const import (
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from .conftest import RtspEventMock
from .conftest import ConfigEntryFactoryType, RtspEventMock
from .const import DEFAULT_HOST, NAME
from tests.common import snapshot_platform
API_DISCOVERY_LIGHT_CONTROL = {
"id": "light-control",
"version": "1.1",
@ -88,8 +92,13 @@ async def test_no_light_entity_without_light_control_representation(
@pytest.mark.parametrize("api_discovery_items", [API_DISCOVERY_LIGHT_CONTROL])
@pytest.mark.usefixtures("config_entry_setup")
async def test_lights(hass: HomeAssistant, mock_rtsp_event: RtspEventMock) -> None:
async def test_lights(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
config_entry_factory: ConfigEntryFactoryType,
mock_rtsp_event: RtspEventMock,
snapshot: SnapshotAssertion,
) -> None:
"""Test that lights are loaded properly."""
# Add light
respx.post(
@ -125,6 +134,9 @@ async def test_lights(hass: HomeAssistant, mock_rtsp_event: RtspEventMock) -> No
},
)
with patch("homeassistant.components.axis.PLATFORMS", [Platform.LIGHT]):
config_entry = await config_entry_factory()
mock_rtsp_event(
topic="tns1:Device/tnsaxis:Light/Status",
data_type="state",
@ -133,15 +145,10 @@ async def test_lights(hass: HomeAssistant, mock_rtsp_event: RtspEventMock) -> No
source_idx="0",
)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(LIGHT_DOMAIN)) == 1
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
entity_id = f"{LIGHT_DOMAIN}.{NAME}_ir_light_0"
light_0 = hass.states.get(entity_id)
assert light_0.state == STATE_ON
assert light_0.name == f"{NAME} IR Light 0"
# Turn on, set brightness, light already on
with (
patch("axis.interfaces.vapix.LightHandler.activate_light") as mock_activate,