init home-assistant
This commit is contained in:
1
home-assistant/tests/components/axis/__init__.py
Normal file
1
home-assistant/tests/components/axis/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for the Axis component."""
|
||||
404
home-assistant/tests/components/axis/conftest.py
Normal file
404
home-assistant/tests/components/axis/conftest.py
Normal file
@@ -0,0 +1,404 @@
|
||||
"""Axis conftest."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Coroutine, Generator
|
||||
from copy import deepcopy
|
||||
from types import MappingProxyType
|
||||
from typing import Any, Protocol
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from axis.rtsp import Signal, State
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MODEL,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import (
|
||||
API_DISCOVERY_RESPONSE,
|
||||
APP_AOA_RESPONSE,
|
||||
APP_VMD4_RESPONSE,
|
||||
APPLICATIONS_LIST_RESPONSE,
|
||||
BASIC_DEVICE_INFO_RESPONSE,
|
||||
BRAND_RESPONSE,
|
||||
DEFAULT_HOST,
|
||||
FORMATTED_MAC,
|
||||
IMAGE_RESPONSE,
|
||||
MODEL,
|
||||
MQTT_CLIENT_RESPONSE,
|
||||
NAME,
|
||||
PORT_MANAGEMENT_RESPONSE,
|
||||
PORTS_RESPONSE,
|
||||
PROPERTIES_RESPONSE,
|
||||
PTZ_RESPONSE,
|
||||
STREAM_PROFILES_RESPONSE,
|
||||
VIEW_AREAS_RESPONSE,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
type ConfigEntryFactoryType = Callable[[], Coroutine[Any, Any, MockConfigEntry]]
|
||||
type RtspStateType = Callable[[bool], None]
|
||||
|
||||
|
||||
class RtspEventMock(Protocol):
|
||||
"""Fixture to allow mocking received RTSP events."""
|
||||
|
||||
def __call__(
|
||||
self,
|
||||
topic: str,
|
||||
data_type: str,
|
||||
data_value: str,
|
||||
operation: str = "Initialized",
|
||||
source_name: str = "",
|
||||
source_idx: str = "",
|
||||
) -> None:
|
||||
"""Send RTSP event."""
|
||||
|
||||
|
||||
class _RtspClientMock(Protocol):
|
||||
async def __call__(
|
||||
self, data: dict[str, Any] | None = None, state: str = ""
|
||||
) -> None: ...
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_setup_entry")
|
||||
def fixture_setup_entry() -> Generator[AsyncMock]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.axis.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
yield mock_setup_entry
|
||||
|
||||
|
||||
# Config entry fixtures
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def fixture_config_entry(
|
||||
config_entry_data: MappingProxyType[str, Any],
|
||||
config_entry_options: MappingProxyType[str, Any],
|
||||
config_entry_version: int,
|
||||
) -> MockConfigEntry:
|
||||
"""Define a config entry fixture."""
|
||||
return MockConfigEntry(
|
||||
domain=AXIS_DOMAIN,
|
||||
entry_id="676abe5b73621446e6550a2e86ffe3dd",
|
||||
unique_id=FORMATTED_MAC,
|
||||
data=config_entry_data,
|
||||
options=config_entry_options,
|
||||
version=config_entry_version,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry_version")
|
||||
def fixture_config_entry_version() -> int:
|
||||
"""Define a config entry version fixture."""
|
||||
return 3
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry_data")
|
||||
def fixture_config_entry_data() -> MappingProxyType[str, Any]:
|
||||
"""Define a config entry data fixture."""
|
||||
return {
|
||||
CONF_HOST: DEFAULT_HOST,
|
||||
CONF_USERNAME: "root",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: 80,
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_NAME: NAME,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry_options")
|
||||
def fixture_config_entry_options() -> MappingProxyType[str, Any]:
|
||||
"""Define a config entry options fixture."""
|
||||
return {}
|
||||
|
||||
|
||||
# Axis API fixtures
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_mock_requests() -> Generator[None]:
|
||||
"""Reset respx mock routes after the test."""
|
||||
yield
|
||||
respx.mock.clear()
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_requests")
|
||||
def fixture_request(
|
||||
respx_mock: respx.MockRouter,
|
||||
port_management_payload: dict[str, Any],
|
||||
param_properties_payload: str,
|
||||
param_ports_payload: str,
|
||||
mqtt_status_code: int,
|
||||
) -> Callable[[str], None]:
|
||||
"""Mock default Vapix requests responses."""
|
||||
|
||||
def __mock_default_requests(host: str) -> None:
|
||||
respx_mock(base_url=f"http://{host}:80")
|
||||
|
||||
if host != DEFAULT_HOST:
|
||||
respx.post("/axis-cgi/apidiscovery.cgi").respond(
|
||||
json=API_DISCOVERY_RESPONSE,
|
||||
)
|
||||
respx.post("/axis-cgi/basicdeviceinfo.cgi").respond(
|
||||
json=BASIC_DEVICE_INFO_RESPONSE,
|
||||
)
|
||||
respx.post("/axis-cgi/io/portmanagement.cgi").respond(
|
||||
json=port_management_payload,
|
||||
)
|
||||
respx.post("/axis-cgi/mqtt/client.cgi").respond(
|
||||
json=MQTT_CLIENT_RESPONSE, status_code=mqtt_status_code
|
||||
)
|
||||
respx.post("/axis-cgi/streamprofile.cgi").respond(
|
||||
json=STREAM_PROFILES_RESPONSE,
|
||||
)
|
||||
respx.post("/axis-cgi/viewarea/info.cgi").respond(json=VIEW_AREAS_RESPONSE)
|
||||
respx.post(
|
||||
"/axis-cgi/param.cgi",
|
||||
data={"action": "list", "group": "root.Brand"},
|
||||
).respond(
|
||||
text=BRAND_RESPONSE,
|
||||
headers={"Content-Type": "text/plain"},
|
||||
)
|
||||
respx.post(
|
||||
"/axis-cgi/param.cgi",
|
||||
data={"action": "list", "group": "root.Image"},
|
||||
).respond(
|
||||
text=IMAGE_RESPONSE,
|
||||
headers={"Content-Type": "text/plain"},
|
||||
)
|
||||
respx.post(
|
||||
"/axis-cgi/param.cgi",
|
||||
data={"action": "list", "group": "root.Input"},
|
||||
).respond(
|
||||
text=PORTS_RESPONSE,
|
||||
headers={"Content-Type": "text/plain"},
|
||||
)
|
||||
respx.post(
|
||||
"/axis-cgi/param.cgi",
|
||||
data={"action": "list", "group": "root.IOPort"},
|
||||
).respond(
|
||||
text=param_ports_payload,
|
||||
headers={"Content-Type": "text/plain"},
|
||||
)
|
||||
respx.post(
|
||||
"/axis-cgi/param.cgi",
|
||||
data={"action": "list", "group": "root.Output"},
|
||||
).respond(
|
||||
text=PORTS_RESPONSE,
|
||||
headers={"Content-Type": "text/plain"},
|
||||
)
|
||||
respx.post(
|
||||
"/axis-cgi/param.cgi",
|
||||
data={"action": "list", "group": "root.Properties"},
|
||||
).respond(
|
||||
text=param_properties_payload,
|
||||
headers={"Content-Type": "text/plain"},
|
||||
)
|
||||
respx.post(
|
||||
"/axis-cgi/param.cgi",
|
||||
data={"action": "list", "group": "root.PTZ"},
|
||||
).respond(
|
||||
text=PTZ_RESPONSE,
|
||||
headers={"Content-Type": "text/plain"},
|
||||
)
|
||||
respx.post(
|
||||
"/axis-cgi/param.cgi",
|
||||
data={"action": "list", "group": "root.StreamProfile"},
|
||||
).respond(
|
||||
text=STREAM_PROFILES_RESPONSE,
|
||||
headers={"Content-Type": "text/plain"},
|
||||
)
|
||||
respx.post("/axis-cgi/applications/list.cgi").respond(
|
||||
text=APPLICATIONS_LIST_RESPONSE,
|
||||
headers={"Content-Type": "text/xml"},
|
||||
)
|
||||
respx.post("/local/fenceguard/control.cgi").respond(json=APP_VMD4_RESPONSE)
|
||||
respx.post("/local/loiteringguard/control.cgi").respond(json=APP_VMD4_RESPONSE)
|
||||
respx.post("/local/motionguard/control.cgi").respond(json=APP_VMD4_RESPONSE)
|
||||
respx.post("/local/vmd/control.cgi").respond(json=APP_VMD4_RESPONSE)
|
||||
respx.post("/local/objectanalytics/control.cgi").respond(json=APP_AOA_RESPONSE)
|
||||
|
||||
return __mock_default_requests
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api_discovery_items() -> dict[str, Any]:
|
||||
"""Additional Apidiscovery items."""
|
||||
return {}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_api_discovery(api_discovery_items: dict[str, Any]) -> None:
|
||||
"""Apidiscovery mock response."""
|
||||
data = deepcopy(API_DISCOVERY_RESPONSE)
|
||||
if api_discovery_items:
|
||||
data["data"]["apiList"].append(api_discovery_items)
|
||||
respx.post(f"http://{DEFAULT_HOST}:80/axis-cgi/apidiscovery.cgi").respond(json=data)
|
||||
|
||||
|
||||
@pytest.fixture(name="port_management_payload")
|
||||
def fixture_io_port_management_data() -> dict[str, Any]:
|
||||
"""Property parameter data."""
|
||||
return PORT_MANAGEMENT_RESPONSE
|
||||
|
||||
|
||||
@pytest.fixture(name="param_properties_payload")
|
||||
def fixture_param_properties_data() -> str:
|
||||
"""Property parameter data."""
|
||||
return PROPERTIES_RESPONSE
|
||||
|
||||
|
||||
@pytest.fixture(name="param_ports_payload")
|
||||
def fixture_param_ports_data() -> str:
|
||||
"""Property parameter data."""
|
||||
return PORTS_RESPONSE
|
||||
|
||||
|
||||
@pytest.fixture(name="mqtt_status_code")
|
||||
def fixture_mqtt_status_code() -> int:
|
||||
"""Property parameter data."""
|
||||
return 200
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_default_requests")
|
||||
def fixture_default_requests(mock_requests: Callable[[str], None]) -> None:
|
||||
"""Mock default Vapix requests responses."""
|
||||
mock_requests(DEFAULT_HOST)
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry_factory")
|
||||
async def fixture_config_entry_factory(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
mock_requests: Callable[[str], None],
|
||||
) -> ConfigEntryFactoryType:
|
||||
"""Fixture factory to set up Axis network device."""
|
||||
|
||||
async def __mock_setup_config_entry() -> MockConfigEntry:
|
||||
config_entry.add_to_hass(hass)
|
||||
mock_requests(config_entry.data[CONF_HOST])
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
return config_entry
|
||||
|
||||
return __mock_setup_config_entry
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry_setup")
|
||||
async def fixture_config_entry_setup(
|
||||
config_entry_factory: ConfigEntryFactoryType,
|
||||
) -> MockConfigEntry:
|
||||
"""Define a fixture to set up Axis network device."""
|
||||
return await config_entry_factory()
|
||||
|
||||
|
||||
# RTSP fixtures
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, name="_mock_rtsp_client")
|
||||
def fixture_axis_rtsp_client() -> Generator[_RtspClientMock]:
|
||||
"""No real RTSP communication allowed."""
|
||||
with patch("axis.stream_manager.RTSPClient") as rtsp_client_mock:
|
||||
rtsp_client_mock.return_value.session.state = State.STOPPED
|
||||
|
||||
async def start_stream() -> None:
|
||||
"""Set state to playing when calling RTSPClient.start."""
|
||||
rtsp_client_mock.return_value.session.state = State.PLAYING
|
||||
|
||||
rtsp_client_mock.return_value.start = start_stream
|
||||
|
||||
def stop_stream() -> None:
|
||||
"""Set state to stopped when calling RTSPClient.stop."""
|
||||
rtsp_client_mock.return_value.session.state = State.STOPPED
|
||||
|
||||
rtsp_client_mock.return_value.stop = stop_stream
|
||||
|
||||
def make_rtsp_call(data: dict[str, Any] | None = None, state: str = "") -> None:
|
||||
"""Generate a RTSP call."""
|
||||
axis_streammanager_session_callback = rtsp_client_mock.call_args[0][4]
|
||||
|
||||
if data:
|
||||
rtsp_client_mock.return_value.rtp.data = data
|
||||
axis_streammanager_session_callback(signal=Signal.DATA)
|
||||
elif state:
|
||||
axis_streammanager_session_callback(signal=state)
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
yield make_rtsp_call
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, name="mock_rtsp_event")
|
||||
def fixture_rtsp_event(_mock_rtsp_client: _RtspClientMock) -> RtspEventMock:
|
||||
"""Fixture to allow mocking received RTSP events."""
|
||||
|
||||
def send_event(
|
||||
topic: str,
|
||||
data_type: str,
|
||||
data_value: str,
|
||||
operation: str = "Initialized",
|
||||
source_name: str = "",
|
||||
source_idx: str = "",
|
||||
) -> None:
|
||||
source = ""
|
||||
if source_name != "" and source_idx != "":
|
||||
source = f'<tt:SimpleItem Name="{source_name}" Value="{source_idx}"/>'
|
||||
|
||||
event = f"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tt:MetadataStream xmlns:tt="http://www.onvif.org/ver10/schema">
|
||||
<tt:Event>
|
||||
<wsnt:NotificationMessage xmlns:tns1="http://www.onvif.org/ver10/topics"
|
||||
xmlns:tnsaxis="http://www.axis.com/2009/event/topics"
|
||||
xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
|
||||
xmlns:wsa5="http://www.w3.org/2005/08/addressing">
|
||||
<wsnt:Topic Dialect="http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple">
|
||||
{topic}
|
||||
</wsnt:Topic>
|
||||
<wsnt:ProducerReference>
|
||||
<wsa5:Address>
|
||||
uri://bf32a3b9-e5e7-4d57-a48d-1b5be9ae7b16/ProducerReference
|
||||
</wsa5:Address>
|
||||
</wsnt:ProducerReference>
|
||||
<wsnt:Message>
|
||||
<tt:Message UtcTime="2020-11-03T20:21:48.346022Z"
|
||||
PropertyOperation="{operation}">
|
||||
<tt:Source>{source}</tt:Source>
|
||||
<tt:Key></tt:Key>
|
||||
<tt:Data>
|
||||
<tt:SimpleItem Name="{data_type}" Value="{data_value}"/>
|
||||
</tt:Data>
|
||||
</tt:Message>
|
||||
</wsnt:Message>
|
||||
</wsnt:NotificationMessage>
|
||||
</tt:Event>
|
||||
</tt:MetadataStream>
|
||||
"""
|
||||
|
||||
_mock_rtsp_client(data=event.encode("utf-8"))
|
||||
|
||||
return send_event
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, name="mock_rtsp_signal_state")
|
||||
def fixture_rtsp_signal_state(_mock_rtsp_client: _RtspClientMock) -> RtspStateType:
|
||||
"""Fixture to allow mocking RTSP state signalling."""
|
||||
|
||||
def send_signal(connected: bool) -> None:
|
||||
"""Signal state change of RTSP connection."""
|
||||
signal = Signal.PLAYING if connected else Signal.FAILED
|
||||
_mock_rtsp_client(state=signal)
|
||||
|
||||
return send_signal
|
||||
296
home-assistant/tests/components/axis/const.py
Normal file
296
home-assistant/tests/components/axis/const.py
Normal file
@@ -0,0 +1,296 @@
|
||||
"""Constants for Axis integration tests."""
|
||||
|
||||
from axis.models.api import CONTEXT
|
||||
|
||||
MAC = "00408C123456"
|
||||
FORMATTED_MAC = "00:40:8c:12:34:56"
|
||||
MODEL = "A1234"
|
||||
NAME = "home"
|
||||
|
||||
DEFAULT_HOST = "1.2.3.4"
|
||||
|
||||
|
||||
API_DISCOVERY_RESPONSE = {
|
||||
"method": "getApiList",
|
||||
"apiVersion": "1.0",
|
||||
"context": CONTEXT,
|
||||
"data": {
|
||||
"apiList": [
|
||||
{"id": "api-discovery", "version": "1.0", "name": "API Discovery Service"},
|
||||
{"id": "param-cgi", "version": "1.0", "name": "Legacy Parameter Handling"},
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
API_DISCOVERY_BASIC_DEVICE_INFO = {
|
||||
"id": "basic-device-info",
|
||||
"version": "1.1",
|
||||
"name": "Basic Device Information",
|
||||
}
|
||||
API_DISCOVERY_MQTT = {"id": "mqtt-client", "version": "1.0", "name": "MQTT Client API"}
|
||||
API_DISCOVERY_PORT_MANAGEMENT = {
|
||||
"id": "io-port-management",
|
||||
"version": "1.0",
|
||||
"name": "IO Port Management",
|
||||
}
|
||||
|
||||
APPLICATIONS_LIST_RESPONSE = """<reply result="ok">
|
||||
<application Name="fenceguard" NiceName="AXIS Fence Guard" Vendor="Axis Communications" Version="2.2-6" ApplicationID="47775" License="None" Status="Running" ConfigurationPage="local/fenceguard/config.html" VendorHomePage="http://www.axis.com" LicenseName="Proprietary" />
|
||||
<application Name="loiteringguard" NiceName="AXIS Loitering Guard" Vendor="Axis Communications" Version="2.2-6" ApplicationID="46775" License="None" Status="Running" ConfigurationPage="local/loiteringguard/config.html" VendorHomePage="http://www.axis.com" LicenseName="Proprietary" />
|
||||
<application Name="motionguard" NiceName="AXIS Motion Guard" Vendor="Axis Communications" Version="2.2-6" ApplicationID="48170" License="None" Status="Running" ConfigurationPage="local/motionguard/config.html" VendorHomePage="http://www.axis.com" LicenseName="Proprietary" />
|
||||
<application Name="vmd" NiceName="AXIS Video Motion Detection" Vendor="Axis Communications" Version="4.2-0" ApplicationID="143440" License="None" Status="Running" ConfigurationPage="local/vmd/config.html" VendorHomePage="http://www.axis.com" />
|
||||
<application Name="objectanalytics" NiceName="AXIS Object Analytics" Vendor="Axis Communications" Version="1.0-0" ApplicationID="143440" License="None" Status="Running" ConfigurationPage="local/vmd/config.html" VendorHomePage="http://www.axis.com" />
|
||||
</reply>"""
|
||||
|
||||
BASIC_DEVICE_INFO_RESPONSE = {
|
||||
"apiVersion": "1.1",
|
||||
"context": CONTEXT,
|
||||
"data": {
|
||||
"propertyList": {
|
||||
"ProdNbr": "M1065-LW",
|
||||
"ProdType": "Network Camera",
|
||||
"SerialNumber": MAC,
|
||||
"Version": "9.80.1",
|
||||
"Architecture": "str",
|
||||
"Brand": "str",
|
||||
"BuildDate": "str",
|
||||
"HardwareID": "str",
|
||||
"ProdFullName": "str",
|
||||
"ProdShortName": "str",
|
||||
"ProdVariant": "str",
|
||||
"Soc": "str",
|
||||
"SocSerialNumber": "str",
|
||||
"WebURL": "str",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
MQTT_CLIENT_RESPONSE = {
|
||||
"method": "getClientStatus",
|
||||
"apiVersion": "1.0",
|
||||
"context": CONTEXT,
|
||||
"data": {
|
||||
"status": {"state": "active", "connectionStatus": "Connected"},
|
||||
"config": {
|
||||
"server": {"protocol": "tcp", "host": "192.168.0.90", "port": 1883},
|
||||
"deviceTopicPrefix": f"axis/{MAC}",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
PORT_MANAGEMENT_RESPONSE = {
|
||||
"apiVersion": "1.0",
|
||||
"method": "getPorts",
|
||||
"context": CONTEXT,
|
||||
"data": {
|
||||
"numberOfPorts": 1,
|
||||
"items": [
|
||||
{
|
||||
"port": "0",
|
||||
"configurable": False,
|
||||
"usage": "",
|
||||
"name": "PIR sensor",
|
||||
"direction": "input",
|
||||
"state": "open",
|
||||
"normalState": "open",
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
APP_VMD4_RESPONSE = {
|
||||
"apiVersion": "1.4",
|
||||
"method": "getConfiguration",
|
||||
"context": CONTEXT,
|
||||
"data": {
|
||||
"cameras": [{"id": 1, "rotation": 0, "active": True}],
|
||||
"profiles": [
|
||||
{"filters": [], "camera": 1, "triggers": [], "name": "Profile 1", "uid": 1}
|
||||
],
|
||||
"configurationStatus": 2,
|
||||
},
|
||||
}
|
||||
|
||||
APP_AOA_RESPONSE = {
|
||||
"apiVersion": "1.0",
|
||||
"context": "Axis library",
|
||||
"data": {
|
||||
"devices": [{"id": 1, "rotation": 180, "type": "camera"}],
|
||||
"metadataOverlay": [],
|
||||
"perspectives": [],
|
||||
"scenarios": [
|
||||
{
|
||||
"devices": [{"id": 1}],
|
||||
"filters": [
|
||||
{"distance": 5, "type": "distanceSwayingObject"},
|
||||
{"time": 1, "type": "timeShortLivedLimit"},
|
||||
{"height": 3, "type": "sizePercentage", "width": 3},
|
||||
],
|
||||
"id": 1,
|
||||
"name": "Scenario 1",
|
||||
"objectClassifications": [],
|
||||
"perspectives": [],
|
||||
"presets": [],
|
||||
"triggers": [
|
||||
{
|
||||
"type": "includeArea",
|
||||
"vertices": [
|
||||
[-0.97, -0.97],
|
||||
[-0.97, 0.97],
|
||||
[0.97, 0.97],
|
||||
[0.97, -0.97],
|
||||
],
|
||||
}
|
||||
],
|
||||
"type": "motion",
|
||||
},
|
||||
],
|
||||
"status": {},
|
||||
},
|
||||
"method": "getConfiguration",
|
||||
}
|
||||
|
||||
|
||||
BRAND_RESPONSE = """root.Brand.Brand=AXIS
|
||||
root.Brand.ProdFullName=AXIS M1065-LW Network Camera
|
||||
root.Brand.ProdNbr=M1065-LW
|
||||
root.Brand.ProdShortName=AXIS M1065-LW
|
||||
root.Brand.ProdType=Network Camera
|
||||
root.Brand.ProdVariant=
|
||||
root.Brand.WebURL=http://www.axis.com
|
||||
"""
|
||||
|
||||
IMAGE_RESPONSE = """root.Image.I0.Enabled=yes
|
||||
root.Image.I0.Name=View Area 1
|
||||
root.Image.I0.Source=0
|
||||
root.Image.I1.Enabled=no
|
||||
root.Image.I1.Name=View Area 2
|
||||
root.Image.I1.Source=0
|
||||
root.Image.I0.Appearance.ColorEnabled=yes
|
||||
root.Image.I0.Appearance.Compression=30
|
||||
root.Image.I0.Appearance.MirrorEnabled=no
|
||||
root.Image.I0.Appearance.Resolution=1920x1080
|
||||
root.Image.I0.Appearance.Rotation=0
|
||||
root.Image.I0.MPEG.Complexity=50
|
||||
root.Image.I0.MPEG.ConfigHeaderInterval=1
|
||||
root.Image.I0.MPEG.FrameSkipMode=drop
|
||||
root.Image.I0.MPEG.ICount=1
|
||||
root.Image.I0.MPEG.PCount=31
|
||||
root.Image.I0.MPEG.UserDataEnabled=no
|
||||
root.Image.I0.MPEG.UserDataInterval=1
|
||||
root.Image.I0.MPEG.ZChromaQPMode=off
|
||||
root.Image.I0.MPEG.ZFpsMode=fixed
|
||||
root.Image.I0.MPEG.ZGopMode=fixed
|
||||
root.Image.I0.MPEG.ZMaxGopLength=300
|
||||
root.Image.I0.MPEG.ZMinFps=0
|
||||
root.Image.I0.MPEG.ZStrength=10
|
||||
root.Image.I0.MPEG.H264.Profile=high
|
||||
root.Image.I0.MPEG.H264.PSEnabled=no
|
||||
root.Image.I0.Overlay.Enabled=no
|
||||
root.Image.I0.Overlay.XPos=0
|
||||
root.Image.I0.Overlay.YPos=0
|
||||
root.Image.I0.Overlay.MaskWindows.Color=black
|
||||
root.Image.I0.RateControl.MaxBitrate=0
|
||||
root.Image.I0.RateControl.Mode=vbr
|
||||
root.Image.I0.RateControl.Priority=framerate
|
||||
root.Image.I0.RateControl.TargetBitrate=0
|
||||
root.Image.I0.SizeControl.MaxFrameSize=0
|
||||
root.Image.I0.Stream.Duration=0
|
||||
root.Image.I0.Stream.FPS=0
|
||||
root.Image.I0.Stream.NbrOfFrames=0
|
||||
root.Image.I0.Text.BGColor=black
|
||||
root.Image.I0.Text.ClockEnabled=no
|
||||
root.Image.I0.Text.Color=white
|
||||
root.Image.I0.Text.DateEnabled=no
|
||||
root.Image.I0.Text.Position=top
|
||||
root.Image.I0.Text.String=
|
||||
root.Image.I0.Text.TextEnabled=no
|
||||
root.Image.I0.Text.TextSize=medium
|
||||
root.Image.I0.TriggerData.AudioEnabled=yes
|
||||
root.Image.I0.TriggerData.MotionDetectionEnabled=yes
|
||||
root.Image.I0.TriggerData.MotionLevelEnabled=no
|
||||
root.Image.I0.TriggerData.TamperingEnabled=yes
|
||||
root.Image.I0.TriggerData.UserTriggers=
|
||||
root.Image.I1.Appearance.ColorEnabled=yes
|
||||
root.Image.I1.Appearance.Compression=30
|
||||
root.Image.I1.Appearance.MirrorEnabled=no
|
||||
root.Image.I1.Appearance.Resolution=1920x1080
|
||||
root.Image.I1.Appearance.Rotation=0
|
||||
root.Image.I1.MPEG.Complexity=50
|
||||
root.Image.I1.MPEG.ConfigHeaderInterval=1
|
||||
root.Image.I1.MPEG.FrameSkipMode=drop
|
||||
root.Image.I1.MPEG.ICount=1
|
||||
root.Image.I1.MPEG.PCount=31
|
||||
root.Image.I1.MPEG.UserDataEnabled=no
|
||||
root.Image.I1.MPEG.UserDataInterval=1
|
||||
root.Image.I1.MPEG.ZChromaQPMode=off
|
||||
root.Image.I1.MPEG.ZFpsMode=fixed
|
||||
root.Image.I1.MPEG.ZGopMode=fixed
|
||||
root.Image.I1.MPEG.ZMaxGopLength=300
|
||||
root.Image.I1.MPEG.ZMinFps=0
|
||||
root.Image.I1.MPEG.ZStrength=10
|
||||
root.Image.I1.MPEG.H264.Profile=high
|
||||
root.Image.I1.MPEG.H264.PSEnabled=no
|
||||
root.Image.I1.Overlay.Enabled=no
|
||||
root.Image.I1.Overlay.XPos=0
|
||||
root.Image.I1.Overlay.YPos=0
|
||||
root.Image.I1.RateControl.MaxBitrate=0
|
||||
root.Image.I1.RateControl.Mode=vbr
|
||||
root.Image.I1.RateControl.Priority=framerate
|
||||
root.Image.I1.RateControl.TargetBitrate=0
|
||||
root.Image.I1.SizeControl.MaxFrameSize=0
|
||||
root.Image.I1.Stream.Duration=0
|
||||
root.Image.I1.Stream.FPS=0
|
||||
root.Image.I1.Stream.NbrOfFrames=0
|
||||
root.Image.I1.Text.BGColor=black
|
||||
root.Image.I1.Text.ClockEnabled=no
|
||||
root.Image.I1.Text.Color=white
|
||||
root.Image.I1.Text.DateEnabled=no
|
||||
root.Image.I1.Text.Position=top
|
||||
root.Image.I1.Text.String=
|
||||
root.Image.I1.Text.TextEnabled=no
|
||||
root.Image.I1.Text.TextSize=medium
|
||||
root.Image.I1.TriggerData.AudioEnabled=yes
|
||||
root.Image.I1.TriggerData.MotionDetectionEnabled=yes
|
||||
root.Image.I1.TriggerData.MotionLevelEnabled=no
|
||||
root.Image.I1.TriggerData.TamperingEnabled=yes
|
||||
root.Image.I1.TriggerData.UserTriggers=
|
||||
"""
|
||||
|
||||
PORTS_RESPONSE = """root.Input.NbrOfInputs=1
|
||||
root.IOPort.I0.Configurable=no
|
||||
root.IOPort.I0.Direction=input
|
||||
root.IOPort.I0.Input.Name=PIR sensor
|
||||
root.IOPort.I0.Input.Trig=closed
|
||||
root.Output.NbrOfOutputs=0
|
||||
"""
|
||||
|
||||
PROPERTIES_RESPONSE = f"""root.Properties.API.HTTP.Version=3
|
||||
root.Properties.API.Metadata.Metadata=yes
|
||||
root.Properties.API.Metadata.Version=1.0
|
||||
root.Properties.EmbeddedDevelopment.Version=2.16
|
||||
root.Properties.Firmware.BuildDate=Feb 15 2019 09:42
|
||||
root.Properties.Firmware.BuildNumber=26
|
||||
root.Properties.Firmware.Version=9.10.1
|
||||
root.Properties.Image.Format=jpeg,mjpeg,h264
|
||||
root.Properties.Image.NbrOfViews=2
|
||||
root.Properties.Image.Resolution=1920x1080,1280x960,1280x720,1024x768,1024x576,800x600,640x480,640x360,352x240,320x240
|
||||
root.Properties.Image.Rotation=0,180
|
||||
root.Properties.System.SerialNumber={MAC}
|
||||
"""
|
||||
|
||||
PTZ_RESPONSE = ""
|
||||
|
||||
|
||||
STREAM_PROFILES_RESPONSE = """root.StreamProfile.MaxGroups=26
|
||||
root.StreamProfile.S0.Description=profile_1_description
|
||||
root.StreamProfile.S0.Name=profile_1
|
||||
root.StreamProfile.S0.Parameters=videocodec=h264
|
||||
root.StreamProfile.S1.Description=profile_2_description
|
||||
root.StreamProfile.S1.Name=profile_2
|
||||
root.StreamProfile.S1.Parameters=videocodec=h265
|
||||
"""
|
||||
|
||||
VIEW_AREAS_RESPONSE = {"apiVersion": "1.0", "method": "list", "data": {"viewAreas": []}}
|
||||
@@ -0,0 +1,518 @@
|
||||
# serializer version: 1
|
||||
# name: test_binary_sensors[event0][binary_sensor.home_daynight_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_daynight_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.LIGHT: 'light'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'DayNight 1',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tns1:VideoSource/tnsaxis:DayNightVision-1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event0][binary_sensor.home_daynight_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'light',
|
||||
'friendly_name': 'home DayNight 1',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_daynight_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event10][binary_sensor.home_object_analytics_device1scenario8-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_object_analytics_device1scenario8',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOTION: 'motion'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Object Analytics Device1Scenario8',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tnsaxis:CameraApplicationPlatform/ObjectAnalytics/Device1Scenario8-Device1Scenario8',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event10][binary_sensor.home_object_analytics_device1scenario8-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'motion',
|
||||
'friendly_name': 'home Object Analytics Device1Scenario8',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_object_analytics_device1scenario8',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event1][binary_sensor.home_sound_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_sound_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.SOUND: 'sound'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Sound 1',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tns1:AudioSource/tnsaxis:TriggerLevel-1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event1][binary_sensor.home_sound_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'sound',
|
||||
'friendly_name': 'home Sound 1',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_sound_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event2][binary_sensor.home_pir_sensor-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_pir_sensor',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.CONNECTIVITY: 'connectivity'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'PIR sensor',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tns1:Device/tnsaxis:IO/Port-0',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event2][binary_sensor.home_pir_sensor-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'connectivity',
|
||||
'friendly_name': 'home PIR sensor',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_pir_sensor',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event3][binary_sensor.home_pir_0-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_pir_0',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOTION: 'motion'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'PIR 0',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tns1:Device/tnsaxis:Sensor/PIR-0',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event3][binary_sensor.home_pir_0-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'motion',
|
||||
'friendly_name': 'home PIR 0',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_pir_0',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event4][binary_sensor.home_fence_guard_profile_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_fence_guard_profile_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOTION: 'motion'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Fence Guard Profile 1',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tnsaxis:CameraApplicationPlatform/FenceGuard/Camera1Profile1-Camera1Profile1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event4][binary_sensor.home_fence_guard_profile_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'motion',
|
||||
'friendly_name': 'home Fence Guard Profile 1',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_fence_guard_profile_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event5][binary_sensor.home_motion_guard_profile_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_motion_guard_profile_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOTION: 'motion'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Motion Guard Profile 1',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tnsaxis:CameraApplicationPlatform/MotionGuard/Camera1Profile1-Camera1Profile1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event5][binary_sensor.home_motion_guard_profile_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'motion',
|
||||
'friendly_name': 'home Motion Guard Profile 1',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_motion_guard_profile_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event6][binary_sensor.home_loitering_guard_profile_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_loitering_guard_profile_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOTION: 'motion'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Loitering Guard Profile 1',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tnsaxis:CameraApplicationPlatform/LoiteringGuard/Camera1Profile1-Camera1Profile1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event6][binary_sensor.home_loitering_guard_profile_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'motion',
|
||||
'friendly_name': 'home Loitering Guard Profile 1',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_loitering_guard_profile_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event7][binary_sensor.home_vmd4_profile_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_vmd4_profile_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOTION: 'motion'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'VMD4 Profile 1',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tnsaxis:CameraApplicationPlatform/VMD/Camera1Profile1-Camera1Profile1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event7][binary_sensor.home_vmd4_profile_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'motion',
|
||||
'friendly_name': 'home VMD4 Profile 1',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_vmd4_profile_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event8][binary_sensor.home_object_analytics_scenario_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_object_analytics_scenario_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOTION: 'motion'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Object Analytics Scenario 1',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tnsaxis:CameraApplicationPlatform/ObjectAnalytics/Device1Scenario1-Device1Scenario1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event8][binary_sensor.home_object_analytics_scenario_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'motion',
|
||||
'friendly_name': 'home Object Analytics Scenario 1',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_object_analytics_scenario_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event9][binary_sensor.home_vmd4_camera1profile9-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.home_vmd4_camera1profile9',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOTION: 'motion'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'VMD4 Camera1Profile9',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tnsaxis:CameraApplicationPlatform/VMD/Camera1Profile9-Camera1Profile9',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[event9][binary_sensor.home_vmd4_camera1profile9-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'motion',
|
||||
'friendly_name': 'home VMD4 Camera1Profile9',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.home_vmd4_camera1profile9',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
101
home-assistant/tests/components/axis/snapshots/test_camera.ambr
Normal file
101
home-assistant/tests/components/axis/snapshots/test_camera.ambr
Normal file
@@ -0,0 +1,101 @@
|
||||
# serializer version: 1
|
||||
# name: test_camera[config_entry_options0-][camera.home-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'camera',
|
||||
'entity_category': None,
|
||||
'entity_id': 'camera.home',
|
||||
'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': None,
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <CameraEntityFeature: 2>,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-camera',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_camera[config_entry_options0-][camera.home-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'access_token': '1',
|
||||
'entity_picture': '/api/camera_proxy/camera.home?token=1',
|
||||
'friendly_name': 'home',
|
||||
'frontend_stream_type': <StreamType.HLS: 'hls'>,
|
||||
'supported_features': <CameraEntityFeature: 2>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'camera.home',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'idle',
|
||||
})
|
||||
# ---
|
||||
# name: test_camera[config_entry_options1-streamprofile=profile_1][camera.home-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'camera',
|
||||
'entity_category': None,
|
||||
'entity_id': 'camera.home',
|
||||
'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': None,
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <CameraEntityFeature: 2>,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-camera',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_camera[config_entry_options1-streamprofile=profile_1][camera.home-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'access_token': '1',
|
||||
'entity_picture': '/api/camera_proxy/camera.home?token=1',
|
||||
'friendly_name': 'home',
|
||||
'frontend_stream_type': <StreamType.HLS: 'hls'>,
|
||||
'supported_features': <CameraEntityFeature: 2>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'camera.home',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'idle',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,59 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics[api_discovery_items0]
|
||||
dict({
|
||||
'api_discovery': list([
|
||||
dict({
|
||||
'id': 'api-discovery',
|
||||
'name': 'API Discovery Service',
|
||||
'version': '1.0',
|
||||
}),
|
||||
dict({
|
||||
'id': 'param-cgi',
|
||||
'name': 'Legacy Parameter Handling',
|
||||
'version': '1.0',
|
||||
}),
|
||||
dict({
|
||||
'id': 'basic-device-info',
|
||||
'name': 'Basic Device Information',
|
||||
'version': '1.1',
|
||||
}),
|
||||
]),
|
||||
'basic_device_info': dict({
|
||||
'__type': "<class 'axis.models.basic_device_info.DeviceInformation'>",
|
||||
'repr': "DeviceInformation(id='0', architecture='str', brand='str', build_date='str', firmware_version='9.80.1', hardware_id='str', product_full_name='str', product_number='M1065-LW', product_short_name='str', product_type='Network Camera', product_variant='str', serial_number='00408C123456', soc='str', soc_serial_number='str', web_url='str')",
|
||||
}),
|
||||
'camera_sources': dict({
|
||||
'Image': 'http://1.2.3.4:80/axis-cgi/jpg/image.cgi',
|
||||
'MJPEG': 'http://1.2.3.4:80/axis-cgi/mjpg/video.cgi',
|
||||
'Stream': 'rtsp://user:pass@1.2.3.4/axis-media/media.amp?videocodec=h264',
|
||||
}),
|
||||
'config': dict({
|
||||
'data': dict({
|
||||
'host': '1.2.3.4',
|
||||
'model': 'A1234',
|
||||
'name': 'home',
|
||||
'password': '**REDACTED**',
|
||||
'port': 80,
|
||||
'username': '**REDACTED**',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'axis',
|
||||
'entry_id': '676abe5b73621446e6550a2e86ffe3dd',
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': 'Mock Title',
|
||||
'unique_id': '**REDACTED**',
|
||||
'version': 3,
|
||||
}),
|
||||
'params': dict({
|
||||
'__type': "<class 'dict_items'>",
|
||||
'repr': "dict_items([('Properties', {'API': {'HTTP': {'Version': 3}, 'Metadata': {'Metadata': True, 'Version': '1.0'}}, 'EmbeddedDevelopment': {'Version': '2.16'}, 'Firmware': {'BuildDate': 'Feb 15 2019 09:42', 'BuildNumber': 26, 'Version': '9.10.1'}, 'Image': {'Format': 'jpeg,mjpeg,h264', 'NbrOfViews': 2, 'Resolution': '1920x1080,1280x960,1280x720,1024x768,1024x576,800x600,640x480,640x360,352x240,320x240', 'Rotation': '0,180'}, 'System': {'SerialNumber': '00408C123456'}}), ('Input', {'NbrOfInputs': 1}), ('IOPort', {'I0': {'Configurable': False, 'Direction': 'input', 'Input': {'Name': 'PIR sensor', 'Trig': 'closed'}}}), ('Output', {'NbrOfOutputs': 0}), ('StreamProfile', {'MaxGroups': 26, 'S0': {'Description': 'profile_1_description', 'Name': 'profile_1', 'Parameters': 'videocodec=h264'}, 'S1': {'Description': 'profile_2_description', 'Name': 'profile_2', 'Parameters': 'videocodec=h265'}})])",
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
73
home-assistant/tests/components/axis/snapshots/test_hub.ambr
Normal file
73
home-assistant/tests/components/axis/snapshots/test_hub.ambr
Normal file
@@ -0,0 +1,73 @@
|
||||
# serializer version: 1
|
||||
# name: test_device_registry_entry[api_discovery_items0]
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'http://1.2.3.4:80',
|
||||
'connections': set({
|
||||
tuple(
|
||||
'mac',
|
||||
'00:40:8c:12:34:56',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'axis',
|
||||
'00:40:8c:12:34:56',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Axis Communications AB',
|
||||
'model': 'A1234 Network Camera',
|
||||
'model_id': None,
|
||||
'name': 'home',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': '00:40:8c:12:34:56',
|
||||
'suggested_area': None,
|
||||
'sw_version': '9.10.1',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_device_registry_entry[api_discovery_items1]
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'http://1.2.3.4:80',
|
||||
'connections': set({
|
||||
tuple(
|
||||
'mac',
|
||||
'00:40:8c:12:34:56',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'axis',
|
||||
'00:40:8c:12:34:56',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Axis Communications AB',
|
||||
'model': 'A1234 Network Camera',
|
||||
'model_id': None,
|
||||
'name': 'home',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': '00:40:8c:12:34:56',
|
||||
'suggested_area': None,
|
||||
'sw_version': '9.80.1',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
@@ -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',
|
||||
})
|
||||
# ---
|
||||
189
home-assistant/tests/components/axis/snapshots/test_switch.ambr
Normal file
189
home-assistant/tests/components/axis/snapshots/test_switch.ambr
Normal file
@@ -0,0 +1,189 @@
|
||||
# serializer version: 1
|
||||
# name: test_switches_with_port_cgi[root.IOPort.I0.Configurable=yes\nroot.IOPort.I0.Direction=output\nroot.IOPort.I0.Output.Name=Doorbell\nroot.IOPort.I0.Output.Active=closed\nroot.IOPort.I1.Configurable=yes\nroot.IOPort.I1.Direction=output\nroot.IOPort.I1.Output.Name=\nroot.IOPort.I1.Output.Active=open\n][switch.home_doorbell-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'switch',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.home_doorbell',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.OUTLET: 'outlet'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Doorbell',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tns1:Device/Trigger/Relay-0',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switches_with_port_cgi[root.IOPort.I0.Configurable=yes\nroot.IOPort.I0.Direction=output\nroot.IOPort.I0.Output.Name=Doorbell\nroot.IOPort.I0.Output.Active=closed\nroot.IOPort.I1.Configurable=yes\nroot.IOPort.I1.Direction=output\nroot.IOPort.I1.Output.Name=\nroot.IOPort.I1.Output.Active=open\n][switch.home_doorbell-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'outlet',
|
||||
'friendly_name': 'home Doorbell',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.home_doorbell',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_switches_with_port_cgi[root.IOPort.I0.Configurable=yes\nroot.IOPort.I0.Direction=output\nroot.IOPort.I0.Output.Name=Doorbell\nroot.IOPort.I0.Output.Active=closed\nroot.IOPort.I1.Configurable=yes\nroot.IOPort.I1.Direction=output\nroot.IOPort.I1.Output.Name=\nroot.IOPort.I1.Output.Active=open\n][switch.home_relay_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'switch',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.home_relay_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.OUTLET: 'outlet'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Relay 1',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tns1:Device/Trigger/Relay-1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switches_with_port_cgi[root.IOPort.I0.Configurable=yes\nroot.IOPort.I0.Direction=output\nroot.IOPort.I0.Output.Name=Doorbell\nroot.IOPort.I0.Output.Active=closed\nroot.IOPort.I1.Configurable=yes\nroot.IOPort.I1.Direction=output\nroot.IOPort.I1.Output.Name=\nroot.IOPort.I1.Output.Active=open\n][switch.home_relay_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'outlet',
|
||||
'friendly_name': 'home Relay 1',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.home_relay_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switches_with_port_management[port_management_payload0-api_discovery_items0][switch.home_doorbell-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'switch',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.home_doorbell',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.OUTLET: 'outlet'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Doorbell',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tns1:Device/Trigger/Relay-0',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switches_with_port_management[port_management_payload0-api_discovery_items0][switch.home_doorbell-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'outlet',
|
||||
'friendly_name': 'home Doorbell',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.home_doorbell',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_switches_with_port_management[port_management_payload0-api_discovery_items0][switch.home_relay_1-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'switch',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.home_relay_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.OUTLET: 'outlet'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Relay 1',
|
||||
'platform': 'axis',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '00:40:8c:12:34:56-tns1:Device/Trigger/Relay-1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switches_with_port_management[port_management_payload0-api_discovery_items0][switch.home_relay_1-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'outlet',
|
||||
'friendly_name': 'home Relay 1',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.home_relay_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
166
home-assistant/tests/components/axis/test_binary_sensor.py
Normal file
166
home-assistant/tests/components/axis/test_binary_sensor.py
Normal file
@@ -0,0 +1,166 @@
|
||||
"""Axis binary sensor platform tests."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .conftest import ConfigEntryFactoryType, RtspEventMock
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"event",
|
||||
[
|
||||
(
|
||||
{
|
||||
"topic": "tns1:VideoSource/tnsaxis:DayNightVision",
|
||||
"source_name": "VideoSourceConfigurationToken",
|
||||
"source_idx": "1",
|
||||
"data_type": "DayNight",
|
||||
"data_value": "1",
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"topic": "tns1:AudioSource/tnsaxis:TriggerLevel",
|
||||
"source_name": "channel",
|
||||
"source_idx": "1",
|
||||
"data_type": "Sound",
|
||||
"data_value": "0",
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"topic": "tns1:Device/tnsaxis:IO/Port",
|
||||
"data_type": "state",
|
||||
"data_value": "0",
|
||||
"operation": "Initialized",
|
||||
"source_name": "port",
|
||||
"source_idx": "0",
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"topic": "tns1:Device/tnsaxis:Sensor/PIR",
|
||||
"data_type": "state",
|
||||
"data_value": "0",
|
||||
"source_name": "sensor",
|
||||
"source_idx": "0",
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"topic": "tnsaxis:CameraApplicationPlatform/FenceGuard/Camera1Profile1",
|
||||
"data_type": "active",
|
||||
"data_value": "1",
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"topic": "tnsaxis:CameraApplicationPlatform/MotionGuard/Camera1Profile1",
|
||||
"data_type": "active",
|
||||
"data_value": "1",
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"topic": "tnsaxis:CameraApplicationPlatform/LoiteringGuard/Camera1Profile1",
|
||||
"data_type": "active",
|
||||
"data_value": "1",
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"topic": "tnsaxis:CameraApplicationPlatform/VMD/Camera1Profile1",
|
||||
"data_type": "active",
|
||||
"data_value": "1",
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"topic": "tnsaxis:CameraApplicationPlatform/ObjectAnalytics/Device1Scenario1",
|
||||
"data_type": "active",
|
||||
"data_value": "1",
|
||||
}
|
||||
),
|
||||
# Events with names generated from event ID and topic
|
||||
(
|
||||
{
|
||||
"topic": "tnsaxis:CameraApplicationPlatform/VMD/Camera1Profile9",
|
||||
"data_type": "active",
|
||||
"data_value": "1",
|
||||
}
|
||||
),
|
||||
(
|
||||
{
|
||||
"topic": "tnsaxis:CameraApplicationPlatform/ObjectAnalytics/Device1Scenario8",
|
||||
"data_type": "active",
|
||||
"data_value": "1",
|
||||
}
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_binary_sensors(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
config_entry_factory: ConfigEntryFactoryType,
|
||||
mock_rtsp_event: RtspEventMock,
|
||||
event: dict[str, str],
|
||||
) -> None:
|
||||
"""Test that sensors are loaded properly."""
|
||||
with patch("homeassistant.components.axis.PLATFORMS", [Platform.BINARY_SENSOR]):
|
||||
config_entry = await config_entry_factory()
|
||||
mock_rtsp_event(**event)
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"event",
|
||||
[
|
||||
# Event with unsupported topic
|
||||
{
|
||||
"topic": "tns1:PTZController/tnsaxis:PTZPresets/Channel_1",
|
||||
"data_type": "on_preset",
|
||||
"data_value": "1",
|
||||
"source_name": "PresetToken",
|
||||
"source_idx": "0",
|
||||
},
|
||||
# Event with unsupported source_idx
|
||||
{
|
||||
"topic": "tns1:Device/tnsaxis:IO/Port",
|
||||
"data_type": "state",
|
||||
"data_value": "0",
|
||||
"operation": "Initialized",
|
||||
"source_name": "port",
|
||||
"source_idx": "-1",
|
||||
},
|
||||
# Event with unsupported ID in topic 'ANY'
|
||||
{
|
||||
"topic": "tnsaxis:CameraApplicationPlatform/VMD/Camera1ProfileANY",
|
||||
"data_type": "active",
|
||||
"data_value": "1",
|
||||
},
|
||||
{
|
||||
"topic": "tnsaxis:CameraApplicationPlatform/ObjectAnalytics/Device1ScenarioANY",
|
||||
"data_type": "active",
|
||||
"data_value": "1",
|
||||
},
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("config_entry_setup")
|
||||
async def test_unsupported_events(
|
||||
hass: HomeAssistant,
|
||||
mock_rtsp_event: RtspEventMock,
|
||||
event: dict[str, str],
|
||||
) -> None:
|
||||
"""Validate nothing breaks with unsupported events."""
|
||||
mock_rtsp_event(**event)
|
||||
assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 0
|
||||
79
home-assistant/tests/components/axis/test_camera.py
Normal file
79
home-assistant/tests/components/axis/test_camera.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""Axis camera platform tests."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components import camera
|
||||
from homeassistant.components.axis.const import CONF_STREAM_PROFILE
|
||||
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .conftest import ConfigEntryFactoryType
|
||||
from .const import MAC, NAME
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_getrandbits():
|
||||
"""Mock camera access token which normally is randomized."""
|
||||
with patch(
|
||||
"homeassistant.components.camera.SystemRandom.getrandbits",
|
||||
return_value=1,
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
PROPERTY_DATA = f"""root.Properties.API.HTTP.Version=3
|
||||
root.Properties.API.Metadata.Metadata=yes
|
||||
root.Properties.API.Metadata.Version=1.0
|
||||
root.Properties.EmbeddedDevelopment.Version=2.16
|
||||
root.Properties.Firmware.BuildDate=Feb 15 2019 09:42
|
||||
root.Properties.Firmware.BuildNumber=26
|
||||
root.Properties.Firmware.Version=9.10.1
|
||||
root.Properties.System.SerialNumber={MAC}
|
||||
""" # No image format data to signal camera support
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("config_entry_options", "stream_profile"),
|
||||
[
|
||||
({}, ""),
|
||||
({CONF_STREAM_PROFILE: "profile_1"}, "streamprofile=profile_1"),
|
||||
],
|
||||
)
|
||||
async def test_camera(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
config_entry_factory: ConfigEntryFactoryType,
|
||||
snapshot: SnapshotAssertion,
|
||||
stream_profile: str,
|
||||
) -> None:
|
||||
"""Test that Axis camera platform is loaded properly."""
|
||||
with patch("homeassistant.components.deconz.PLATFORMS", [Platform.CAMERA]):
|
||||
config_entry = await config_entry_factory()
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
entity_id = f"{CAMERA_DOMAIN}.{NAME}"
|
||||
camera_entity = camera.helper.get_camera_from_entity_id(hass, entity_id)
|
||||
assert camera_entity.image_source == "http://1.2.3.4:80/axis-cgi/jpg/image.cgi"
|
||||
assert (
|
||||
camera_entity.mjpeg_source == "http://1.2.3.4:80/axis-cgi/mjpg/video.cgi"
|
||||
f"{"" if not stream_profile else f"?{stream_profile}"}"
|
||||
)
|
||||
assert (
|
||||
await camera_entity.stream_source()
|
||||
== "rtsp://root:pass@1.2.3.4/axis-media/media.amp?videocodec=h264"
|
||||
f"{"" if not stream_profile else f"&{stream_profile}"}"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("param_properties_payload", [PROPERTY_DATA])
|
||||
@pytest.mark.usefixtures("config_entry_setup")
|
||||
async def test_camera_disabled(hass: HomeAssistant) -> None:
|
||||
"""Test that Axis camera platform is loaded properly but does not create camera entity."""
|
||||
assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 0
|
||||
635
home-assistant/tests/components/axis/test_config_flow.py
Normal file
635
home-assistant/tests/components/axis/test_config_flow.py
Normal file
@@ -0,0 +1,635 @@
|
||||
"""Test Axis config flow."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from ipaddress import ip_address
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import dhcp, ssdp, zeroconf
|
||||
from homeassistant.components.axis import config_flow
|
||||
from homeassistant.components.axis.const import (
|
||||
CONF_STREAM_PROFILE,
|
||||
CONF_VIDEO_SOURCE,
|
||||
DEFAULT_STREAM_PROFILE,
|
||||
DEFAULT_VIDEO_SOURCE,
|
||||
DOMAIN as AXIS_DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_DHCP,
|
||||
SOURCE_SSDP,
|
||||
SOURCE_USER,
|
||||
SOURCE_ZEROCONF,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MODEL,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_PROTOCOL,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import BaseServiceInfo, FlowResultType
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .const import DEFAULT_HOST, MAC, MODEL, NAME
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
DHCP_FORMATTED_MAC = dr.format_mac(MAC).replace(":", "")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_default_requests")
|
||||
async def test_flow_manual_configuration(hass: HomeAssistant) -> None:
|
||||
"""Test that config flow works."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_PROTOCOL: "http",
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: 80,
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == f"M1065-LW - {MAC}"
|
||||
assert result["data"] == {
|
||||
CONF_PROTOCOL: "http",
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: 80,
|
||||
CONF_MODEL: "M1065-LW",
|
||||
CONF_NAME: "M1065-LW 0",
|
||||
}
|
||||
|
||||
|
||||
async def test_manual_configuration_duplicate_fails(
|
||||
hass: HomeAssistant,
|
||||
config_entry_setup: MockConfigEntry,
|
||||
mock_requests: Callable[[str], None],
|
||||
) -> None:
|
||||
"""Test that config flow fails on already configured device."""
|
||||
assert config_entry_setup.data[CONF_HOST] == "1.2.3.4"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
mock_requests("2.3.4.5")
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_PROTOCOL: "http",
|
||||
CONF_HOST: "2.3.4.5",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: 80,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert config_entry_setup.data[CONF_HOST] == "1.2.3.4"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("exc", "error"),
|
||||
[
|
||||
(config_flow.AuthenticationRequired, "invalid_auth"),
|
||||
(config_flow.CannotConnect, "cannot_connect"),
|
||||
],
|
||||
)
|
||||
async def test_flow_fails_on_api(
|
||||
hass: HomeAssistant, exc: Exception, error: str
|
||||
) -> None:
|
||||
"""Test that config flow fails on faulty credentials."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.axis.config_flow.get_axis_api",
|
||||
side_effect=exc,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_PROTOCOL: "http",
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: 80,
|
||||
},
|
||||
)
|
||||
|
||||
assert result["errors"] == {"base": error}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_default_requests")
|
||||
async def test_flow_create_entry_multiple_existing_entries_of_same_model(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test that create entry can generate a name with other entries."""
|
||||
entry = MockConfigEntry(
|
||||
domain=AXIS_DOMAIN,
|
||||
data={CONF_NAME: "M1065-LW 0", CONF_MODEL: "M1065-LW"},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
entry2 = MockConfigEntry(
|
||||
domain=AXIS_DOMAIN,
|
||||
data={CONF_NAME: "M1065-LW 1", CONF_MODEL: "M1065-LW"},
|
||||
)
|
||||
entry2.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_PROTOCOL: "http",
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: 80,
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == f"M1065-LW - {MAC}"
|
||||
assert result["data"] == {
|
||||
CONF_PROTOCOL: "http",
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: 80,
|
||||
CONF_MODEL: "M1065-LW",
|
||||
CONF_NAME: "M1065-LW 2",
|
||||
}
|
||||
|
||||
assert result["data"][CONF_NAME] == "M1065-LW 2"
|
||||
|
||||
|
||||
async def test_reauth_flow_update_configuration(
|
||||
hass: HomeAssistant,
|
||||
config_entry_setup: MockConfigEntry,
|
||||
mock_requests: Callable[[str], None],
|
||||
) -> None:
|
||||
"""Test that config flow fails on already configured device."""
|
||||
assert config_entry_setup.data[CONF_HOST] == "1.2.3.4"
|
||||
assert config_entry_setup.data[CONF_USERNAME] == "root"
|
||||
assert config_entry_setup.data[CONF_PASSWORD] == "pass"
|
||||
|
||||
result = await config_entry_setup.start_reauth_flow(hass)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
mock_requests("2.3.4.5")
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_PROTOCOL: "https",
|
||||
CONF_HOST: "2.3.4.5",
|
||||
CONF_USERNAME: "user2",
|
||||
CONF_PASSWORD: "pass2",
|
||||
CONF_PORT: 443,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
assert config_entry_setup.data[CONF_PROTOCOL] == "https"
|
||||
assert config_entry_setup.data[CONF_HOST] == "2.3.4.5"
|
||||
assert config_entry_setup.data[CONF_PORT] == 443
|
||||
assert config_entry_setup.data[CONF_USERNAME] == "user2"
|
||||
assert config_entry_setup.data[CONF_PASSWORD] == "pass2"
|
||||
|
||||
|
||||
async def test_reconfiguration_flow_update_configuration(
|
||||
hass: HomeAssistant,
|
||||
config_entry_setup: MockConfigEntry,
|
||||
mock_requests: Callable[[str], None],
|
||||
) -> None:
|
||||
"""Test that config flow reconfiguration updates configured device."""
|
||||
assert config_entry_setup.data[CONF_HOST] == "1.2.3.4"
|
||||
assert config_entry_setup.data[CONF_USERNAME] == "root"
|
||||
assert config_entry_setup.data[CONF_PASSWORD] == "pass"
|
||||
|
||||
result = await config_entry_setup.start_reconfigure_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
mock_requests("2.3.4.5")
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: "2.3.4.5",
|
||||
CONF_USERNAME: "user",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
assert config_entry_setup.data[CONF_PROTOCOL] == "http"
|
||||
assert config_entry_setup.data[CONF_HOST] == "2.3.4.5"
|
||||
assert config_entry_setup.data[CONF_PORT] == 80
|
||||
assert config_entry_setup.data[CONF_USERNAME] == "user"
|
||||
assert config_entry_setup.data[CONF_PASSWORD] == "pass"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("source", "discovery_info"),
|
||||
[
|
||||
(
|
||||
SOURCE_DHCP,
|
||||
dhcp.DhcpServiceInfo(
|
||||
hostname=f"axis-{MAC}",
|
||||
ip=DEFAULT_HOST,
|
||||
macaddress=DHCP_FORMATTED_MAC,
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"st": "urn:axis-com:service:BasicService:1",
|
||||
"usn": f"uuid:Upnp-BasicDevice-1_0-{MAC}::urn:axis-com:service:BasicService:1",
|
||||
"ext": "",
|
||||
"server": (
|
||||
"Linux/4.14.173-axis8, UPnP/1.0, Portable SDK for UPnP"
|
||||
" devices/1.8.7"
|
||||
),
|
||||
"deviceType": "urn:schemas-upnp-org:device:Basic:1",
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"manufacturer": "AXIS",
|
||||
"manufacturerURL": "http://www.axis.com/",
|
||||
"modelDescription": "AXIS M1065-LW Network Camera",
|
||||
"modelName": "AXIS M1065-LW",
|
||||
"modelNumber": "M1065-LW",
|
||||
"modelURL": "http://www.axis.com/",
|
||||
"serialNumber": MAC,
|
||||
"UDN": f"uuid:Upnp-BasicDevice-1_0-{MAC}",
|
||||
"serviceList": {
|
||||
"service": {
|
||||
"serviceType": "urn:axis-com:service:BasicService:1",
|
||||
"serviceId": "urn:axis-com:serviceId:BasicServiceId",
|
||||
"controlURL": "/upnp/control/BasicServiceId",
|
||||
"eventSubURL": "/upnp/event/BasicServiceId",
|
||||
"SCPDURL": "/scpd_basic.xml",
|
||||
}
|
||||
},
|
||||
"presentationURL": f"http://{DEFAULT_HOST}:80/",
|
||||
},
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_ZEROCONF,
|
||||
zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=ip_address(DEFAULT_HOST),
|
||||
ip_addresses=[ip_address(DEFAULT_HOST)],
|
||||
port=80,
|
||||
hostname=f"axis-{MAC.lower()}.local.",
|
||||
type="_axis-video._tcp.local.",
|
||||
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
|
||||
properties={
|
||||
"_raw": {"macaddress": MAC.encode()},
|
||||
"macaddress": MAC,
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_default_requests")
|
||||
async def test_discovery_flow(
|
||||
hass: HomeAssistant,
|
||||
source: str,
|
||||
discovery_info: BaseServiceInfo,
|
||||
) -> None:
|
||||
"""Test the different discovery flows for new devices work."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN, data=discovery_info, context={"source": source}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
assert len(flows) == 1
|
||||
assert flows[0].get("context", {}).get("configuration_url") == "http://1.2.3.4:80"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_PROTOCOL: "http",
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: 80,
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == f"M1065-LW - {MAC}"
|
||||
assert result["data"] == {
|
||||
CONF_PROTOCOL: "http",
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: 80,
|
||||
CONF_MODEL: "M1065-LW",
|
||||
CONF_NAME: "M1065-LW 0",
|
||||
}
|
||||
|
||||
assert result["data"][CONF_NAME] == "M1065-LW 0"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("source", "discovery_info"),
|
||||
[
|
||||
(
|
||||
SOURCE_DHCP,
|
||||
dhcp.DhcpServiceInfo(
|
||||
hostname=f"axis-{MAC}",
|
||||
ip=DEFAULT_HOST,
|
||||
macaddress=DHCP_FORMATTED_MAC,
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"serialNumber": MAC,
|
||||
"presentationURL": f"http://{DEFAULT_HOST}:80/",
|
||||
},
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_ZEROCONF,
|
||||
zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=ip_address(DEFAULT_HOST),
|
||||
ip_addresses=[ip_address(DEFAULT_HOST)],
|
||||
hostname="mock_hostname",
|
||||
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
|
||||
port=80,
|
||||
properties={"macaddress": MAC},
|
||||
type="mock_type",
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_discovered_device_already_configured(
|
||||
hass: HomeAssistant,
|
||||
config_entry_setup: MockConfigEntry,
|
||||
source: str,
|
||||
discovery_info: BaseServiceInfo,
|
||||
) -> None:
|
||||
"""Test that discovery doesn't setup already configured devices."""
|
||||
assert config_entry_setup.data[CONF_HOST] == DEFAULT_HOST
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN, data=discovery_info, context={"source": source}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert config_entry_setup.data[CONF_HOST] == DEFAULT_HOST
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("source", "discovery_info", "expected_port"),
|
||||
[
|
||||
(
|
||||
SOURCE_DHCP,
|
||||
dhcp.DhcpServiceInfo(
|
||||
hostname=f"axis-{MAC}",
|
||||
ip="2.3.4.5",
|
||||
macaddress=DHCP_FORMATTED_MAC,
|
||||
),
|
||||
80,
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"serialNumber": MAC,
|
||||
"presentationURL": "http://2.3.4.5:8080/",
|
||||
},
|
||||
),
|
||||
80,
|
||||
),
|
||||
(
|
||||
SOURCE_ZEROCONF,
|
||||
zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=ip_address("2.3.4.5"),
|
||||
ip_addresses=[ip_address("2.3.4.5")],
|
||||
hostname="mock_hostname",
|
||||
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
|
||||
port=8080,
|
||||
properties={"macaddress": MAC},
|
||||
type="mock_type",
|
||||
),
|
||||
80,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_discovery_flow_updated_configuration(
|
||||
hass: HomeAssistant,
|
||||
config_entry_setup: MockConfigEntry,
|
||||
mock_requests: Callable[[str], None],
|
||||
source: str,
|
||||
discovery_info: BaseServiceInfo,
|
||||
expected_port: int,
|
||||
) -> None:
|
||||
"""Test that discovery flow update configuration with new parameters."""
|
||||
assert config_entry_setup.data == {
|
||||
CONF_HOST: DEFAULT_HOST,
|
||||
CONF_PORT: 80,
|
||||
CONF_USERNAME: "root",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_NAME: NAME,
|
||||
}
|
||||
|
||||
mock_requests("2.3.4.5")
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN, data=discovery_info, context={"source": source}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert config_entry_setup.data == {
|
||||
CONF_HOST: "2.3.4.5",
|
||||
CONF_PORT: expected_port,
|
||||
CONF_USERNAME: "root",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_NAME: NAME,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("source", "discovery_info"),
|
||||
[
|
||||
(
|
||||
SOURCE_DHCP,
|
||||
dhcp.DhcpServiceInfo(
|
||||
hostname="",
|
||||
ip="",
|
||||
macaddress=dr.format_mac("01234567890").replace(":", ""),
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"friendlyName": "",
|
||||
"serialNumber": "01234567890",
|
||||
"presentationURL": "",
|
||||
},
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_ZEROCONF,
|
||||
zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=None,
|
||||
ip_addresses=[],
|
||||
hostname="mock_hostname",
|
||||
name="",
|
||||
port=0,
|
||||
properties={"macaddress": "01234567890"},
|
||||
type="mock_type",
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_discovery_flow_ignore_non_axis_device(
|
||||
hass: HomeAssistant, source: str, discovery_info: BaseServiceInfo
|
||||
) -> None:
|
||||
"""Test that discovery flow ignores devices with non Axis OUI."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN, data=discovery_info, context={"source": source}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "not_axis_device"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("source", "discovery_info"),
|
||||
[
|
||||
(
|
||||
SOURCE_DHCP,
|
||||
dhcp.DhcpServiceInfo(
|
||||
hostname=f"axis-{MAC}",
|
||||
ip="169.254.3.4",
|
||||
macaddress=DHCP_FORMATTED_MAC,
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_SSDP,
|
||||
ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
upnp={
|
||||
"friendlyName": f"AXIS M1065-LW - {MAC}",
|
||||
"serialNumber": MAC,
|
||||
"presentationURL": "http://169.254.3.4:80/",
|
||||
},
|
||||
),
|
||||
),
|
||||
(
|
||||
SOURCE_ZEROCONF,
|
||||
zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=ip_address("169.254.3.4"),
|
||||
ip_addresses=[ip_address("169.254.3.4")],
|
||||
hostname="mock_hostname",
|
||||
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
|
||||
port=80,
|
||||
properties={"macaddress": MAC},
|
||||
type="mock_type",
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_discovery_flow_ignore_link_local_address(
|
||||
hass: HomeAssistant, source: str, discovery_info: BaseServiceInfo
|
||||
) -> None:
|
||||
"""Test that discovery flow ignores devices with link local addresses."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN, data=discovery_info, context={"source": source}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "link_local_address"
|
||||
|
||||
|
||||
async def test_option_flow(
|
||||
hass: HomeAssistant, config_entry_setup: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test config flow options."""
|
||||
assert CONF_STREAM_PROFILE not in config_entry_setup.options
|
||||
assert CONF_VIDEO_SOURCE not in config_entry_setup.options
|
||||
|
||||
result = await hass.config_entries.options.async_init(config_entry_setup.entry_id)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "configure_stream"
|
||||
assert set(result["data_schema"].schema[CONF_STREAM_PROFILE].container) == {
|
||||
DEFAULT_STREAM_PROFILE,
|
||||
"profile_1",
|
||||
"profile_2",
|
||||
}
|
||||
assert set(result["data_schema"].schema[CONF_VIDEO_SOURCE].container) == {
|
||||
DEFAULT_VIDEO_SOURCE,
|
||||
1,
|
||||
}
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_STREAM_PROFILE: "profile_1", CONF_VIDEO_SOURCE: 1},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"] == {
|
||||
CONF_STREAM_PROFILE: "profile_1",
|
||||
CONF_VIDEO_SOURCE: 1,
|
||||
}
|
||||
assert config_entry_setup.options[CONF_STREAM_PROFILE] == "profile_1"
|
||||
assert config_entry_setup.options[CONF_VIDEO_SOURCE] == 1
|
||||
26
home-assistant/tests/components/axis/test_diagnostics.py
Normal file
26
home-assistant/tests/components/axis/test_diagnostics.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Test Axis diagnostics."""
|
||||
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import API_DISCOVERY_BASIC_DEVICE_INFO
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
@pytest.mark.parametrize("api_discovery_items", [API_DISCOVERY_BASIC_DEVICE_INFO])
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
config_entry_setup: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
assert await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry_setup
|
||||
) == snapshot(exclude=props("created_at", "modified_at"))
|
||||
209
home-assistant/tests/components/axis/test_hub.py
Normal file
209
home-assistant/tests/components/axis/test_hub.py
Normal file
@@ -0,0 +1,209 @@
|
||||
"""Test Axis device."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from ipaddress import ip_address
|
||||
from types import MappingProxyType
|
||||
from typing import Any
|
||||
from unittest import mock
|
||||
from unittest.mock import ANY, Mock, call, patch
|
||||
|
||||
import axis as axislib
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components import axis, zeroconf
|
||||
from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_ZEROCONF, ConfigEntryState
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .conftest import RtspEventMock, RtspStateType
|
||||
from .const import (
|
||||
API_DISCOVERY_BASIC_DEVICE_INFO,
|
||||
API_DISCOVERY_MQTT,
|
||||
FORMATTED_MAC,
|
||||
MAC,
|
||||
NAME,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_mqtt_message
|
||||
from tests.typing import MqttMockHAClient
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"api_discovery_items", [({}), (API_DISCOVERY_BASIC_DEVICE_INFO)]
|
||||
)
|
||||
async def test_device_registry_entry(
|
||||
config_entry_setup: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Successful setup."""
|
||||
device_entry = device_registry.async_get_device(
|
||||
identifiers={(AXIS_DOMAIN, config_entry_setup.unique_id)}
|
||||
)
|
||||
assert device_entry == snapshot
|
||||
|
||||
|
||||
@pytest.mark.parametrize("api_discovery_items", [API_DISCOVERY_MQTT])
|
||||
@pytest.mark.usefixtures("config_entry_setup")
|
||||
async def test_device_support_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
||||
) -> None:
|
||||
"""Successful setup."""
|
||||
mqtt_call = call(f"axis/{MAC}/#", mock.ANY, 0, "utf-8", ANY)
|
||||
assert mqtt_call in mqtt_mock.async_subscribe.call_args_list
|
||||
|
||||
topic = f"axis/{MAC}/event/tns:onvif/Device/tns:axis/Sensor/PIR/$source/sensor/0"
|
||||
message = (
|
||||
b'{"timestamp": 1590258472044, "topic": "onvif:Device/axis:Sensor/PIR",'
|
||||
b' "message": {"source": {"sensor": "0"}, "key": {}, "data": {"state": "1"}}}'
|
||||
)
|
||||
|
||||
assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 0
|
||||
async_fire_mqtt_message(hass, topic, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 1
|
||||
|
||||
pir = hass.states.get(f"{BINARY_SENSOR_DOMAIN}.{NAME}_pir_0")
|
||||
assert pir.state == STATE_ON
|
||||
assert pir.name == f"{NAME} PIR 0"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("api_discovery_items", [API_DISCOVERY_MQTT])
|
||||
@pytest.mark.parametrize("mqtt_status_code", [401])
|
||||
@pytest.mark.usefixtures("config_entry_setup")
|
||||
async def test_device_support_mqtt_low_privilege(mqtt_mock: MqttMockHAClient) -> None:
|
||||
"""Successful setup."""
|
||||
mqtt_call = call(f"{MAC}/#", mock.ANY, 0, "utf-8")
|
||||
assert mqtt_call not in mqtt_mock.async_subscribe.call_args_list
|
||||
|
||||
|
||||
async def test_update_address(
|
||||
hass: HomeAssistant,
|
||||
config_entry_setup: MockConfigEntry,
|
||||
mock_requests: Callable[[str], None],
|
||||
) -> None:
|
||||
"""Test update address works."""
|
||||
hub = config_entry_setup.runtime_data
|
||||
assert hub.api.config.host == "1.2.3.4"
|
||||
|
||||
mock_requests("2.3.4.5")
|
||||
await hass.config_entries.flow.async_init(
|
||||
AXIS_DOMAIN,
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=ip_address("2.3.4.5"),
|
||||
ip_addresses=[ip_address("2.3.4.5")],
|
||||
hostname="mock_hostname",
|
||||
name="name",
|
||||
port=80,
|
||||
properties={"macaddress": MAC},
|
||||
type="mock_type",
|
||||
),
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hub.api.config.host == "2.3.4.5"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("config_entry_setup")
|
||||
async def test_device_unavailable(
|
||||
hass: HomeAssistant,
|
||||
mock_rtsp_event: RtspEventMock,
|
||||
mock_rtsp_signal_state: RtspStateType,
|
||||
) -> None:
|
||||
"""Successful setup."""
|
||||
# Provide an entity that can be used to verify connection state on
|
||||
mock_rtsp_event(
|
||||
topic="tns1:AudioSource/tnsaxis:TriggerLevel",
|
||||
data_type="triggered",
|
||||
data_value="10",
|
||||
source_name="channel",
|
||||
source_idx="1",
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(f"{BINARY_SENSOR_DOMAIN}.{NAME}_sound_1").state == STATE_OFF
|
||||
|
||||
# Connection to device has failed
|
||||
|
||||
mock_rtsp_signal_state(connected=False)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
hass.states.get(f"{BINARY_SENSOR_DOMAIN}.{NAME}_sound_1").state
|
||||
== STATE_UNAVAILABLE
|
||||
)
|
||||
|
||||
# Connection to device has been restored
|
||||
|
||||
mock_rtsp_signal_state(connected=True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(f"{BINARY_SENSOR_DOMAIN}.{NAME}_sound_1").state == STATE_OFF
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_default_requests")
|
||||
async def test_device_trigger_reauth_flow(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Failed authentication trigger a reauthentication flow."""
|
||||
config_entry.add_to_hass(hass)
|
||||
with (
|
||||
patch.object(
|
||||
axis, "get_axis_api", side_effect=axis.errors.AuthenticationRequired
|
||||
),
|
||||
patch.object(hass.config_entries.flow, "async_init") as mock_flow_init,
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
mock_flow_init.assert_called_once()
|
||||
assert config_entry.state == ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
||||
async def test_shutdown(config_entry_data: MappingProxyType[str, Any]) -> None:
|
||||
"""Successful shutdown."""
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
entry.data = config_entry_data
|
||||
|
||||
mock_api = Mock()
|
||||
mock_api.vapix.serial_number = FORMATTED_MAC
|
||||
axis_device = axis.hub.AxisHub(hass, entry, mock_api)
|
||||
|
||||
await axis_device.shutdown(None)
|
||||
|
||||
assert len(axis_device.api.stream.stop.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "state"),
|
||||
[
|
||||
# Device unauthorized yields authentication required error
|
||||
(axislib.Unauthorized, ConfigEntryState.SETUP_ERROR),
|
||||
# Device unavailable yields cannot connect error
|
||||
(TimeoutError, ConfigEntryState.SETUP_RETRY),
|
||||
(axislib.RequestError, ConfigEntryState.SETUP_RETRY),
|
||||
# Device yield unknown error
|
||||
(axislib.AxisException, ConfigEntryState.SETUP_ERROR),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_default_requests")
|
||||
async def test_get_axis_api_errors(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
side_effect: Exception,
|
||||
state: ConfigEntryState,
|
||||
) -> None:
|
||||
"""Failed setup schedules a retry of setup."""
|
||||
config_entry.add_to_hass(hass)
|
||||
with patch(
|
||||
"homeassistant.components.axis.hub.api.axis.interfaces.vapix.Vapix.initialize",
|
||||
side_effect=side_effect,
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state == state
|
||||
64
home-assistant/tests/components/axis/test_init.py
Normal file
64
home-assistant/tests/components/axis/test_init.py
Normal file
@@ -0,0 +1,64 @@
|
||||
"""Test Axis component setup process."""
|
||||
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import axis
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_setup_entry(config_entry_setup: MockConfigEntry) -> None:
|
||||
"""Test successful setup of entry."""
|
||||
assert config_entry_setup.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_setup_entry_fails(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test successful setup of entry."""
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
mock_device = Mock()
|
||||
mock_device.async_setup = AsyncMock(return_value=False)
|
||||
|
||||
with patch.object(axis, "AxisHub") as mock_device_class:
|
||||
mock_device_class.return_value = mock_device
|
||||
|
||||
assert not await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
assert config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant, config_entry_setup: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test successful unload of entry."""
|
||||
assert config_entry_setup.state is ConfigEntryState.LOADED
|
||||
|
||||
assert await hass.config_entries.async_unload(config_entry_setup.entry_id)
|
||||
assert config_entry_setup.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
@pytest.mark.parametrize("config_entry_version", [1])
|
||||
async def test_migrate_entry(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test successful migration of entry data."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert config_entry.version == 1
|
||||
|
||||
mock_device = Mock()
|
||||
mock_device.async_setup = AsyncMock()
|
||||
mock_device.async_update_device_registry = AsyncMock()
|
||||
mock_device.api.vapix.light_control = None
|
||||
mock_device.api.vapix.params.image_format = None
|
||||
|
||||
with patch("homeassistant.components.axis.async_setup_entry", return_value=True):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
assert config_entry.version == 3
|
||||
219
home-assistant/tests/components/axis/test_light.py
Normal file
219
home-assistant/tests/components/axis/test_light.py
Normal file
@@ -0,0 +1,219 @@
|
||||
"""Axis light platform tests."""
|
||||
|
||||
from typing import Any
|
||||
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 (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
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",
|
||||
"name": "Light Control",
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def light_control_items() -> list[dict[str, Any]]:
|
||||
"""Available lights."""
|
||||
return [
|
||||
{
|
||||
"lightID": "led0",
|
||||
"lightType": "IR",
|
||||
"enabled": True,
|
||||
"synchronizeDayNightMode": True,
|
||||
"lightState": False,
|
||||
"automaticIntensityMode": False,
|
||||
"automaticAngleOfIlluminationMode": False,
|
||||
"nrOfLEDs": 1,
|
||||
"error": False,
|
||||
"errorInfo": "",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def light_control_fixture(light_control_items: list[dict[str, Any]]) -> None:
|
||||
"""Light control mock response."""
|
||||
data = {
|
||||
"apiVersion": "1.1",
|
||||
"context": CONTEXT,
|
||||
"method": "getLightInformation",
|
||||
"data": {"items": light_control_items},
|
||||
}
|
||||
respx.post(
|
||||
f"http://{DEFAULT_HOST}:80/axis-cgi/lightcontrol.cgi",
|
||||
json={
|
||||
"apiVersion": "1.1",
|
||||
"context": CONTEXT,
|
||||
"method": "getLightInformation",
|
||||
},
|
||||
).respond(
|
||||
json=data,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("api_discovery_items", [API_DISCOVERY_LIGHT_CONTROL])
|
||||
@pytest.mark.parametrize("light_control_items", [[]])
|
||||
@pytest.mark.usefixtures("config_entry_setup")
|
||||
async def test_no_light_entity_without_light_control_representation(
|
||||
hass: HomeAssistant,
|
||||
mock_rtsp_event: RtspEventMock,
|
||||
) -> None:
|
||||
"""Verify no lights entities get created without light control representation."""
|
||||
mock_rtsp_event(
|
||||
topic="tns1:Device/tnsaxis:Light/Status",
|
||||
data_type="state",
|
||||
data_value="ON",
|
||||
source_name="id",
|
||||
source_idx="0",
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert not hass.states.async_entity_ids(LIGHT_DOMAIN)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("api_discovery_items", [API_DISCOVERY_LIGHT_CONTROL])
|
||||
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(
|
||||
f"http://{DEFAULT_HOST}:80/axis-cgi/lightcontrol.cgi",
|
||||
json={
|
||||
"apiVersion": "1.1",
|
||||
"context": CONTEXT,
|
||||
"method": "getCurrentIntensity",
|
||||
"params": {"lightID": "led0"},
|
||||
},
|
||||
).respond(
|
||||
json={
|
||||
"apiVersion": "1.1",
|
||||
"context": "Axis library",
|
||||
"method": "getCurrentIntensity",
|
||||
"data": {"intensity": 100},
|
||||
},
|
||||
)
|
||||
respx.post(
|
||||
f"http://{DEFAULT_HOST}:80/axis-cgi/lightcontrol.cgi",
|
||||
json={
|
||||
"apiVersion": "1.1",
|
||||
"context": CONTEXT,
|
||||
"method": "getValidIntensity",
|
||||
"params": {"lightID": "led0"},
|
||||
},
|
||||
).respond(
|
||||
json={
|
||||
"apiVersion": "1.1",
|
||||
"context": "Axis library",
|
||||
"method": "getValidIntensity",
|
||||
"data": {"ranges": [{"low": 0, "high": 150}]},
|
||||
},
|
||||
)
|
||||
|
||||
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",
|
||||
data_value="ON",
|
||||
source_name="id",
|
||||
source_idx="0",
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
entity_id = f"{LIGHT_DOMAIN}.{NAME}_ir_light_0"
|
||||
|
||||
# Turn on, set brightness, light already on
|
||||
with (
|
||||
patch("axis.interfaces.vapix.LightHandler.activate_light") as mock_activate,
|
||||
patch(
|
||||
"axis.interfaces.vapix.LightHandler.set_manual_intensity"
|
||||
) as mock_set_intensity,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: entity_id, ATTR_BRIGHTNESS: 50},
|
||||
blocking=True,
|
||||
)
|
||||
mock_activate.assert_not_awaited()
|
||||
mock_set_intensity.assert_called_once_with("led0", 29)
|
||||
|
||||
# Turn off
|
||||
with patch(
|
||||
"axis.interfaces.vapix.LightHandler.deactivate_light"
|
||||
) as mock_deactivate:
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
mock_deactivate.assert_called_once()
|
||||
|
||||
# Event turn off light
|
||||
mock_rtsp_event(
|
||||
topic="tns1:Device/tnsaxis:Light/Status",
|
||||
data_type="state",
|
||||
data_value="OFF",
|
||||
source_name="id",
|
||||
source_idx="0",
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
light_0 = hass.states.get(entity_id)
|
||||
assert light_0.state == STATE_OFF
|
||||
|
||||
# Turn on, set brightness
|
||||
with (
|
||||
patch("axis.interfaces.vapix.LightHandler.activate_light") as mock_activate,
|
||||
patch(
|
||||
"axis.interfaces.vapix.LightHandler.set_manual_intensity"
|
||||
) as mock_set_intensity,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
mock_activate.assert_called_once()
|
||||
mock_set_intensity.assert_not_called()
|
||||
|
||||
# Turn off, light already off
|
||||
with patch(
|
||||
"axis.interfaces.vapix.LightHandler.deactivate_light"
|
||||
) as mock_deactivate:
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
mock_deactivate.assert_not_called()
|
||||
178
home-assistant/tests/components/axis/test_switch.py
Normal file
178
home-assistant/tests/components/axis/test_switch.py
Normal file
@@ -0,0 +1,178 @@
|
||||
"""Axis switch platform tests."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from axis.models.api import CONTEXT
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_ON,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .conftest import ConfigEntryFactoryType, RtspEventMock
|
||||
from .const import API_DISCOVERY_PORT_MANAGEMENT, NAME
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
PORT_DATA = """root.IOPort.I0.Configurable=yes
|
||||
root.IOPort.I0.Direction=output
|
||||
root.IOPort.I0.Output.Name=Doorbell
|
||||
root.IOPort.I0.Output.Active=closed
|
||||
root.IOPort.I1.Configurable=yes
|
||||
root.IOPort.I1.Direction=output
|
||||
root.IOPort.I1.Output.Name=
|
||||
root.IOPort.I1.Output.Active=open
|
||||
"""
|
||||
|
||||
PORT_MANAGEMENT_RESPONSE = {
|
||||
"apiVersion": "1.0",
|
||||
"method": "getPorts",
|
||||
"context": CONTEXT,
|
||||
"data": {
|
||||
"numberOfPorts": 2,
|
||||
"items": [
|
||||
{
|
||||
"port": "0",
|
||||
"configurable": True,
|
||||
"usage": "",
|
||||
"name": "Doorbell",
|
||||
"direction": "output",
|
||||
"state": "open",
|
||||
"normalState": "open",
|
||||
},
|
||||
{
|
||||
"port": "1",
|
||||
"configurable": True,
|
||||
"usage": "",
|
||||
"name": "",
|
||||
"direction": "output",
|
||||
"state": "open",
|
||||
"normalState": "open",
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("param_ports_payload", [PORT_DATA])
|
||||
async def test_switches_with_port_cgi(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
config_entry_factory: ConfigEntryFactoryType,
|
||||
mock_rtsp_event: RtspEventMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test that switches are loaded properly using port.cgi."""
|
||||
with patch("homeassistant.components.axis.PLATFORMS", [Platform.SWITCH]):
|
||||
config_entry = await config_entry_factory()
|
||||
|
||||
mock_rtsp_event(
|
||||
topic="tns1:Device/Trigger/Relay",
|
||||
data_type="LogicalState",
|
||||
data_value="inactive",
|
||||
source_name="RelayToken",
|
||||
source_idx="0",
|
||||
)
|
||||
mock_rtsp_event(
|
||||
topic="tns1:Device/Trigger/Relay",
|
||||
data_type="LogicalState",
|
||||
data_value="active",
|
||||
source_name="RelayToken",
|
||||
source_idx="1",
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
entity_id = f"{SWITCH_DOMAIN}.{NAME}_doorbell"
|
||||
|
||||
with patch("axis.interfaces.vapix.Ports.close") as mock_turn_on:
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
mock_turn_on.assert_called_once_with("0")
|
||||
|
||||
with patch("axis.interfaces.vapix.Ports.open") as mock_turn_off:
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
mock_turn_off.assert_called_once_with("0")
|
||||
|
||||
|
||||
@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,
|
||||
entity_registry: er.EntityRegistry,
|
||||
config_entry_factory: ConfigEntryFactoryType,
|
||||
mock_rtsp_event: RtspEventMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test that switches are loaded properly using port management."""
|
||||
with patch("homeassistant.components.axis.PLATFORMS", [Platform.SWITCH]):
|
||||
config_entry = await config_entry_factory()
|
||||
|
||||
mock_rtsp_event(
|
||||
topic="tns1:Device/Trigger/Relay",
|
||||
data_type="LogicalState",
|
||||
data_value="inactive",
|
||||
source_name="RelayToken",
|
||||
source_idx="0",
|
||||
)
|
||||
mock_rtsp_event(
|
||||
topic="tns1:Device/Trigger/Relay",
|
||||
data_type="LogicalState",
|
||||
data_value="active",
|
||||
source_name="RelayToken",
|
||||
source_idx="1",
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
entity_id = f"{SWITCH_DOMAIN}.{NAME}_doorbell"
|
||||
|
||||
with patch("axis.interfaces.vapix.IoPortManagement.close") as mock_turn_on:
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
mock_turn_on.assert_called_once_with("0")
|
||||
|
||||
with patch("axis.interfaces.vapix.IoPortManagement.open") as mock_turn_off:
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
mock_turn_off.assert_called_once_with("0")
|
||||
|
||||
# State update
|
||||
|
||||
mock_rtsp_event(
|
||||
topic="tns1:Device/Trigger/Relay",
|
||||
data_type="LogicalState",
|
||||
data_value="active",
|
||||
source_name="RelayToken",
|
||||
source_idx="0",
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(f"{SWITCH_DOMAIN}.{NAME}_relay_1").state == STATE_ON
|
||||
Reference in New Issue
Block a user