Axis - Improve naming of some events (#39699)

* Add support for events from Loitering guard and Motion guard
* Improve naming of events originating from applications Fence guard and VMD4 (Loitering guard and motion guard also benefit from this)
This commit is contained in:
Robert Svensson 2020-09-06 23:26:06 +02:00 committed by GitHub
parent 251d8919ea
commit 41abc08d63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 5 deletions

View File

@ -8,6 +8,10 @@ from axis.event_stream import (
CLASS_MOTION,
CLASS_OUTPUT,
CLASS_SOUND,
FenceGuard,
LoiteringGuard,
MotionGuard,
Vmd4,
)
from homeassistant.components.binary_sensor import (
@ -104,6 +108,21 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity):
f"{self.device.name} {self.device.api.vapix.ports[self.event.id].name}"
)
if self.event.CLASS == CLASS_MOTION:
for event_class, event_data in (
(FenceGuard, self.device.api.vapix.fence_guard),
(LoiteringGuard, self.device.api.vapix.loitering_guard),
(MotionGuard, self.device.api.vapix.motion_guard),
(Vmd4, self.device.api.vapix.vmd4),
):
if (
isinstance(self.event, event_class)
and event_data
and self.event.id in event_data
):
return f"{self.device.name} {self.event.TYPE} {event_data[self.event.id].name}"
return super().name
@property

View File

@ -3,7 +3,7 @@
"name": "Axis",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/axis",
"requirements": ["axis==33"],
"requirements": ["axis==35"],
"zeroconf": ["_axis-video._tcp.local."],
"after_dependencies": ["mqtt"],
"codeowners": ["@Kane610"]

View File

@ -309,7 +309,7 @@ av==8.0.2
avri-api==0.1.7
# homeassistant.components.axis
axis==33
axis==35
# homeassistant.components.azure_event_hub
azure-eventhub==5.1.0

View File

@ -174,7 +174,7 @@ av==8.0.2
avri-api==0.1.7
# homeassistant.components.axis
axis==33
axis==35
# homeassistant.components.azure_event_hub
azure-eventhub==5.1.0

View File

@ -63,7 +63,7 @@ async def test_binary_sensors(hass):
assert pir.name == f"{NAME} PIR 0"
assert pir.attributes["device_class"] == DEVICE_CLASS_MOTION
vmd4 = hass.states.get(f"binary_sensor.{NAME}_vmd4_camera1profile1")
vmd4 = hass.states.get(f"binary_sensor.{NAME}_vmd4_profile_1")
assert vmd4.state == "on"
assert vmd4.name == f"{NAME} VMD4 Camera1Profile1"
assert vmd4.name == f"{NAME} VMD4 Profile 1"
assert vmd4.attributes["device_class"] == DEVICE_CLASS_MOTION

View File

@ -5,6 +5,8 @@ from unittest import mock
import axis as axislib
from axis.api_discovery import URL as API_DISCOVERY_URL
from axis.applications import URL_LIST as APPLICATIONS_URL
from axis.applications.vmd4 import URL as VMD4_URL
from axis.basic_device_info import URL as BASIC_DEVICE_INFO_URL
from axis.event_stream import OPERATION_INITIALIZED
from axis.light_control import URL as LIGHT_CONTROL_URL
@ -79,6 +81,10 @@ API_DISCOVERY_PORT_MANAGEMENT = {
"name": "IO Port Management",
}
APPLICATIONS_LIST_RESPONSE = """<reply result="ok">
<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" />
</reply>"""
BASIC_DEVICE_INFO_RESPONSE = {
"apiVersion": "1.1",
"data": {
@ -138,6 +144,18 @@ PORT_MANAGEMENT_RESPONSE = {
},
}
VMD4_RESPONSE = {
"apiVersion": "1.4",
"method": "getConfiguration",
"context": "Axis library",
"data": {
"cameras": [{"id": 1, "rotation": 0, "active": True}],
"profiles": [
{"filters": [], "camera": 1, "triggers": [], "name": "Profile 1", "uid": 1}
],
},
}
BRAND_RESPONSE = """root.Brand.Brand=AXIS
root.Brand.ProdFullName=AXIS M1065-LW Network Camera
root.Brand.ProdNbr=M1065-LW
@ -158,6 +176,7 @@ root.Output.NbrOfOutputs=0
PROPERTIES_RESPONSE = """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
@ -182,6 +201,8 @@ def vapix_session_request(session, url, **kwargs):
"""Return data based on url."""
if API_DISCOVERY_URL in url:
return json.dumps(API_DISCOVERY_RESPONSE)
if APPLICATIONS_URL in url:
return APPLICATIONS_LIST_RESPONSE
if BASIC_DEVICE_INFO_URL in url:
return json.dumps(BASIC_DEVICE_INFO_RESPONSE)
if LIGHT_CONTROL_URL in url:
@ -190,6 +211,8 @@ def vapix_session_request(session, url, **kwargs):
return json.dumps(MQTT_CLIENT_RESPONSE)
if PORT_MANAGEMENT_URL in url:
return json.dumps(PORT_MANAGEMENT_RESPONSE)
if VMD4_URL in url:
return json.dumps(VMD4_RESPONSE)
if BRAND_URL in url:
return BRAND_RESPONSE
if IOPORT_URL in url or INPUT_URL in url or OUTPUT_URL in url: