From 41abc08d63bd2e20542e32eb0552358c9c4cdd19 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Sun, 6 Sep 2020 23:26:06 +0200 Subject: [PATCH] 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) --- .../components/axis/binary_sensor.py | 19 +++++++++++++++ homeassistant/components/axis/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/axis/test_binary_sensor.py | 4 ++-- tests/components/axis/test_device.py | 23 +++++++++++++++++++ 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/axis/binary_sensor.py b/homeassistant/components/axis/binary_sensor.py index feae2c8fc99..dcdf440a472 100644 --- a/homeassistant/components/axis/binary_sensor.py +++ b/homeassistant/components/axis/binary_sensor.py @@ -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 diff --git a/homeassistant/components/axis/manifest.json b/homeassistant/components/axis/manifest.json index 95175fce51a..3b08c5ad4d4 100644 --- a/homeassistant/components/axis/manifest.json +++ b/homeassistant/components/axis/manifest.json @@ -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"] diff --git a/requirements_all.txt b/requirements_all.txt index 7d5dc4f3e52..aaba7f4bd57 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 2c30f58f921..30d995ad9a5 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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 diff --git a/tests/components/axis/test_binary_sensor.py b/tests/components/axis/test_binary_sensor.py index 1ffe37ef857..e2d820a959e 100644 --- a/tests/components/axis/test_binary_sensor.py +++ b/tests/components/axis/test_binary_sensor.py @@ -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 diff --git a/tests/components/axis/test_device.py b/tests/components/axis/test_device.py index c6d78ca66e9..dc4cb607934 100644 --- a/tests/components/axis/test_device.py +++ b/tests/components/axis/test_device.py @@ -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 = """ + +""" + 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: