Use snapshot in Axis light tests (#122703)
This commit is contained in:
parent
b0780e1db5
commit
6752bd450b
2 changed files with 74 additions and 10 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue