1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Improve axis tests (#114035)

* Combine binary sensor tests into more logical groups

* Improve light tests

* Clean up switch tests

* Improve typing in conftest

* Add typing to camera

* Improve binary sensor

* Improve light

* Improve switch
This commit is contained in:
Robert Svensson
2024-03-23 00:44:06 +01:00
committed by GitHub
parent 26b6bd83fc
commit bf8d880e5f
6 changed files with 142 additions and 159 deletions

View File

@@ -1,12 +1,13 @@
"""Axis switch platform tests."""
from collections.abc import Callable
from unittest.mock import patch
from axis.vapix.models.api import CONTEXT
import pytest
from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ENTITY_ID,
SERVICE_TURN_OFF,
@@ -15,25 +16,9 @@ from homeassistant.const import (
STATE_ON,
)
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .const import API_DISCOVERY_PORT_MANAGEMENT, NAME
async def test_platform_manually_configured(hass: HomeAssistant) -> None:
"""Test that nothing happens when platform is manually configured."""
assert await async_setup_component(
hass, SWITCH_DOMAIN, {SWITCH_DOMAIN: {"platform": AXIS_DOMAIN}}
)
assert AXIS_DOMAIN not in hass.data
async def test_no_switches(hass: HomeAssistant, setup_config_entry) -> None:
"""Test that no output events in Axis results in no switch entities."""
assert not hass.states.async_entity_ids(SWITCH_DOMAIN)
PORT_DATA = """root.IOPort.I0.Configurable=yes
root.IOPort.I0.Direction=output
root.IOPort.I0.Output.Name=Doorbell
@@ -47,7 +32,9 @@ root.IOPort.I1.Output.Active=open
@pytest.mark.parametrize("param_ports_payload", [PORT_DATA])
async def test_switches_with_port_cgi(
hass: HomeAssistant, setup_config_entry, mock_rtsp_event
hass: HomeAssistant,
setup_config_entry: ConfigEntry,
mock_rtsp_event: Callable[[str, str, str, str, str, str], None],
) -> None:
"""Test that switches are loaded properly using port.cgi."""
mock_rtsp_event(
@@ -130,7 +117,9 @@ PORT_MANAGEMENT_RESPONSE = {
@pytest.mark.parametrize("api_discovery_items", [API_DISCOVERY_PORT_MANAGEMENT])
@pytest.mark.parametrize("port_management_payload", [PORT_MANAGEMENT_RESPONSE])
async def test_switches_with_port_management(
hass: HomeAssistant, setup_config_entry, mock_rtsp_event
hass: HomeAssistant,
setup_config_entry: ConfigEntry,
mock_rtsp_event: Callable[[str, str, str, str, str, str], None],
) -> None:
"""Test that switches are loaded properly using port management."""
mock_rtsp_event(