diff --git a/tests/components/axis/snapshots/test_light.ambr b/tests/components/axis/snapshots/test_light.ambr new file mode 100644 index 00000000000..b37da39fe27 --- /dev/null +++ b/tests/components/axis/snapshots/test_light.ambr @@ -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([ + , + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + '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': , + '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': , + 'friendly_name': 'home IR Light 0', + 'supported_color_modes': list([ + , + ]), + 'supported_features': , + }), + 'context': , + 'entity_id': 'light.home_ir_light_0', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- diff --git a/tests/components/axis/test_light.py b/tests/components/axis/test_light.py index 9f68aa6fdd3..c33af5ec3a4 100644 --- a/tests/components/axis/test_light.py +++ b/tests/components/axis/test_light.py @@ -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,