From c1e1db9863cb2080fdf4c3f8db6e6628aea2a1d9 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Mon, 25 Mar 2024 17:16:41 +0100 Subject: [PATCH] Adapt to Axis library file structure changes (#114181) * Adapt to axis library file structure changes * Bump axis to v59 --- .../components/axis/binary_sensor.py | 8 +++---- homeassistant/components/axis/hub/api.py | 2 +- homeassistant/components/axis/hub/hub.py | 4 ++-- homeassistant/components/axis/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/axis/const.py | 2 +- .../axis/snapshots/test_diagnostics.ambr | 2 +- tests/components/axis/test_hub.py | 6 ++--- tests/components/axis/test_light.py | 22 +++++++++++++------ tests/components/axis/test_switch.py | 10 ++++----- 11 files changed, 35 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/axis/binary_sensor.py b/homeassistant/components/axis/binary_sensor.py index af8c394813a..8cd90ba1554 100644 --- a/homeassistant/components/axis/binary_sensor.py +++ b/homeassistant/components/axis/binary_sensor.py @@ -6,11 +6,11 @@ from collections.abc import Callable from dataclasses import dataclass from datetime import datetime, timedelta +from axis.interfaces.applications.fence_guard import FenceGuardHandler +from axis.interfaces.applications.loitering_guard import LoiteringGuardHandler +from axis.interfaces.applications.motion_guard import MotionGuardHandler +from axis.interfaces.applications.vmd4 import Vmd4Handler from axis.models.event import Event, EventTopic -from axis.vapix.interfaces.applications.fence_guard import FenceGuardHandler -from axis.vapix.interfaces.applications.loitering_guard import LoiteringGuardHandler -from axis.vapix.interfaces.applications.motion_guard import MotionGuardHandler -from axis.vapix.interfaces.applications.vmd4 import Vmd4Handler from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, diff --git a/homeassistant/components/axis/hub/api.py b/homeassistant/components/axis/hub/api.py index dc2e63598b6..8e5d7533631 100644 --- a/homeassistant/components/axis/hub/api.py +++ b/homeassistant/components/axis/hub/api.py @@ -5,7 +5,7 @@ from types import MappingProxyType from typing import Any import axis -from axis.configuration import Configuration +from axis.models.configuration import Configuration from homeassistant.const import ( CONF_HOST, diff --git a/homeassistant/components/axis/hub/hub.py b/homeassistant/components/axis/hub/hub.py index 6252c0e29c5..08eb816f6ab 100644 --- a/homeassistant/components/axis/hub/hub.py +++ b/homeassistant/components/axis/hub/hub.py @@ -6,9 +6,9 @@ from typing import Any import axis from axis.errors import Unauthorized +from axis.interfaces.mqtt import mqtt_json_to_event +from axis.models.mqtt import ClientState from axis.stream_manager import Signal, State -from axis.vapix.interfaces.mqtt import mqtt_json_to_event -from axis.vapix.models.mqtt import ClientState from homeassistant.components import mqtt from homeassistant.components.mqtt import DOMAIN as MQTT_DOMAIN diff --git a/homeassistant/components/axis/manifest.json b/homeassistant/components/axis/manifest.json index f2a2dd40740..f47d10df484 100644 --- a/homeassistant/components/axis/manifest.json +++ b/homeassistant/components/axis/manifest.json @@ -26,7 +26,7 @@ "iot_class": "local_push", "loggers": ["axis"], "quality_scale": "platinum", - "requirements": ["axis==58"], + "requirements": ["axis==59"], "ssdp": [ { "manufacturer": "AXIS" diff --git a/requirements_all.txt b/requirements_all.txt index 2765da52873..dbd15073e62 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -514,7 +514,7 @@ aurorapy==0.2.7 # avion==0.10 # homeassistant.components.axis -axis==58 +axis==59 # homeassistant.components.azure_event_hub azure-eventhub==5.11.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 10bfa1ec632..74e85ab6b2e 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -454,7 +454,7 @@ auroranoaa==0.0.3 aurorapy==0.2.7 # homeassistant.components.axis -axis==58 +axis==59 # homeassistant.components.azure_event_hub azure-eventhub==5.11.1 diff --git a/tests/components/axis/const.py b/tests/components/axis/const.py index 8dffac5866a..7b881ea55e5 100644 --- a/tests/components/axis/const.py +++ b/tests/components/axis/const.py @@ -1,6 +1,6 @@ """Constants for Axis integration tests.""" -from axis.vapix.models.api import CONTEXT +from axis.models.api import CONTEXT MAC = "00408C123456" FORMATTED_MAC = "00:40:8c:12:34:56" diff --git a/tests/components/axis/snapshots/test_diagnostics.ambr b/tests/components/axis/snapshots/test_diagnostics.ambr index 3902cee6a0b..8ea316d00cf 100644 --- a/tests/components/axis/snapshots/test_diagnostics.ambr +++ b/tests/components/axis/snapshots/test_diagnostics.ambr @@ -19,7 +19,7 @@ }), ]), 'basic_device_info': dict({ - '__type': "", + '__type': "", '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({ diff --git a/tests/components/axis/test_hub.py b/tests/components/axis/test_hub.py index f12665a995d..d166aaed733 100644 --- a/tests/components/axis/test_hub.py +++ b/tests/components/axis/test_hub.py @@ -224,7 +224,7 @@ async def test_shutdown(config_entry_data) -> None: async def test_get_device_fails(hass: HomeAssistant, config_entry_data) -> None: """Device unauthorized yields authentication required error.""" with patch( - "axis.vapix.vapix.Vapix.initialize", side_effect=axislib.Unauthorized + "axis.interfaces.vapix.Vapix.initialize", side_effect=axislib.Unauthorized ), pytest.raises(axis.errors.AuthenticationRequired): await axis.hub.get_axis_api(hass, config_entry_data) @@ -234,7 +234,7 @@ async def test_get_device_device_unavailable( ) -> None: """Device unavailable yields cannot connect error.""" with patch( - "axis.vapix.vapix.Vapix.request", side_effect=axislib.RequestError + "axis.interfaces.vapix.Vapix.request", side_effect=axislib.RequestError ), pytest.raises(axis.errors.CannotConnect): await axis.hub.get_axis_api(hass, config_entry_data) @@ -242,6 +242,6 @@ async def test_get_device_device_unavailable( async def test_get_device_unknown_error(hass: HomeAssistant, config_entry_data) -> None: """Device yield unknown error.""" with patch( - "axis.vapix.vapix.Vapix.request", side_effect=axislib.AxisException + "axis.interfaces.vapix.Vapix.request", side_effect=axislib.AxisException ), pytest.raises(axis.errors.AuthenticationRequired): await axis.hub.get_axis_api(hass, config_entry_data) diff --git a/tests/components/axis/test_light.py b/tests/components/axis/test_light.py index b8983cd8b9b..95956450c9e 100644 --- a/tests/components/axis/test_light.py +++ b/tests/components/axis/test_light.py @@ -4,7 +4,7 @@ from collections.abc import Callable from typing import Any from unittest.mock import patch -from axis.vapix.models.api import CONTEXT +from axis.models.api import CONTEXT import pytest import respx @@ -149,8 +149,10 @@ async def test_lights( assert light_0.name == f"{NAME} IR Light 0" # Turn on, set brightness, light already on - with patch("axis.vapix.vapix.LightHandler.activate_light") as mock_activate, patch( - "axis.vapix.vapix.LightHandler.set_manual_intensity" + 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, @@ -162,7 +164,9 @@ async def test_lights( mock_set_intensity.assert_called_once_with("led0", 29) # Turn off - with patch("axis.vapix.vapix.LightHandler.deactivate_light") as mock_deactivate: + with patch( + "axis.interfaces.vapix.LightHandler.deactivate_light" + ) as mock_deactivate: await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_OFF, @@ -185,8 +189,10 @@ async def test_lights( assert light_0.state == STATE_OFF # Turn on, set brightness - with patch("axis.vapix.vapix.LightHandler.activate_light") as mock_activate, patch( - "axis.vapix.vapix.LightHandler.set_manual_intensity" + 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, @@ -198,7 +204,9 @@ async def test_lights( mock_set_intensity.assert_not_called() # Turn off, light already off - with patch("axis.vapix.vapix.LightHandler.deactivate_light") as mock_deactivate: + with patch( + "axis.interfaces.vapix.LightHandler.deactivate_light" + ) as mock_deactivate: await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_OFF, diff --git a/tests/components/axis/test_switch.py b/tests/components/axis/test_switch.py index a2a1088d7ef..b9202d42e25 100644 --- a/tests/components/axis/test_switch.py +++ b/tests/components/axis/test_switch.py @@ -3,7 +3,7 @@ from collections.abc import Callable from unittest.mock import patch -from axis.vapix.models.api import CONTEXT +from axis.models.api import CONTEXT import pytest from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN @@ -65,7 +65,7 @@ async def test_switches_with_port_cgi( assert relay_0.state == STATE_OFF assert relay_0.name == f"{NAME} Doorbell" - with patch("axis.vapix.vapix.Ports.close") as mock_turn_on: + with patch("axis.interfaces.vapix.Ports.close") as mock_turn_on: await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_ON, @@ -74,7 +74,7 @@ async def test_switches_with_port_cgi( ) mock_turn_on.assert_called_once_with("0") - with patch("axis.vapix.vapix.Ports.open") as mock_turn_off: + with patch("axis.interfaces.vapix.Ports.open") as mock_turn_off: await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_OFF, @@ -163,7 +163,7 @@ async def test_switches_with_port_management( assert hass.states.get(f"{SWITCH_DOMAIN}.{NAME}_relay_1").state == STATE_ON - with patch("axis.vapix.vapix.IoPortManagement.close") as mock_turn_on: + with patch("axis.interfaces.vapix.IoPortManagement.close") as mock_turn_on: await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_ON, @@ -172,7 +172,7 @@ async def test_switches_with_port_management( ) mock_turn_on.assert_called_once_with("0") - with patch("axis.vapix.vapix.IoPortManagement.open") as mock_turn_off: + with patch("axis.interfaces.vapix.IoPortManagement.open") as mock_turn_off: await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_OFF,