Bump axis to v45 (#84992)

This commit is contained in:
Robert Svensson 2023-01-02 18:14:14 +01:00 committed by GitHub
parent 02b5da710b
commit 534bb74069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 33 additions and 36 deletions

View File

@ -51,10 +51,10 @@ class AxisEventBase(AxisEntityBase):
super().__init__(device) super().__init__(device)
self.event = event self.event = event
self._attr_name = f"{event.TYPE} {event.id}" self._attr_name = f"{event.type} {event.id}"
self._attr_unique_id = f"{device.unique_id}-{event.topic}-{event.id}" self._attr_unique_id = f"{device.unique_id}-{event.topic}-{event.id}"
self._attr_device_class = event.CLASS self._attr_device_class = event.group
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Subscribe sensors events.""" """Subscribe sensors events."""

View File

@ -55,8 +55,8 @@ async def async_setup_entry(
"""Add binary sensor from Axis device.""" """Add binary sensor from Axis device."""
event: AxisEvent = device.api.event[event_id] event: AxisEvent = device.api.event[event_id]
if event.CLASS not in (CLASS_OUTPUT, CLASS_PTZ) and not ( if event.group not in (CLASS_OUTPUT, CLASS_PTZ) and not (
event.CLASS == CLASS_LIGHT and event.TYPE == "Light" event.group == CLASS_LIGHT and event.type == "Light"
): ):
async_add_entities([AxisBinarySensor(event, device)]) async_add_entities([AxisBinarySensor(event, device)])
@ -75,7 +75,8 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity):
super().__init__(event, device) super().__init__(event, device)
self.cancel_scheduled_update = None self.cancel_scheduled_update = None
self._attr_device_class = DEVICE_CLASS.get(self.event.CLASS) self._attr_device_class = DEVICE_CLASS.get(self.event.group)
self._attr_is_on = event.is_tripped
@callback @callback
def update_callback(self, no_delay=False): def update_callback(self, no_delay=False):
@ -83,6 +84,7 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity):
Parameter no_delay is True when device_event_reachable is sent. Parameter no_delay is True when device_event_reachable is sent.
""" """
self._attr_is_on = self.event.is_tripped
@callback @callback
def scheduled_update(now): def scheduled_update(now):
@ -104,22 +106,17 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity):
utcnow() + timedelta(seconds=self.device.option_trigger_time), utcnow() + timedelta(seconds=self.device.option_trigger_time),
) )
@property
def is_on(self) -> bool:
"""Return true if event is active."""
return self.event.is_tripped
@property @property
def name(self) -> str | None: def name(self) -> str | None:
"""Return the name of the event.""" """Return the name of the event."""
if ( if (
self.event.CLASS == CLASS_INPUT self.event.group == CLASS_INPUT
and self.event.id in self.device.api.vapix.ports and self.event.id in self.device.api.vapix.ports
and self.device.api.vapix.ports[self.event.id].name and self.device.api.vapix.ports[self.event.id].name
): ):
return self.device.api.vapix.ports[self.event.id].name return self.device.api.vapix.ports[self.event.id].name
if self.event.CLASS == CLASS_MOTION: if self.event.group == CLASS_MOTION:
for event_class, event_data in ( for event_class, event_data in (
(FenceGuard, self.device.api.vapix.fence_guard), (FenceGuard, self.device.api.vapix.fence_guard),
@ -133,6 +130,6 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity):
and event_data and event_data
and self.event.id in event_data and self.event.id in event_data
): ):
return f"{self.event.TYPE} {event_data[self.event.id].name}" return f"{self.event.type} {event_data[self.event.id].name}"
return self._attr_name return self._attr_name

View File

@ -9,8 +9,8 @@ import axis
from axis.configuration import Configuration from axis.configuration import Configuration
from axis.errors import Unauthorized from axis.errors import Unauthorized
from axis.event_stream import OPERATION_INITIALIZED from axis.event_stream import OPERATION_INITIALIZED
from axis.mqtt import mqtt_json_to_event
from axis.streammanager import SIGNAL_PLAYING, STATE_STOPPED from axis.streammanager import SIGNAL_PLAYING, STATE_STOPPED
from axis.vapix.interfaces.mqtt import mqtt_json_to_event
from homeassistant.components import mqtt from homeassistant.components import mqtt
from homeassistant.components.mqtt import DOMAIN as MQTT_DOMAIN from homeassistant.components.mqtt import DOMAIN as MQTT_DOMAIN

View File

@ -33,7 +33,7 @@ async def async_setup_entry(
"""Add light from Axis device.""" """Add light from Axis device."""
event: AxisEvent = device.api.event[event_id] event: AxisEvent = device.api.event[event_id]
if event.CLASS == CLASS_LIGHT and event.TYPE == "Light": if event.group == CLASS_LIGHT and event.type == "Light":
async_add_entities([AxisLight(event, device)]) async_add_entities([AxisLight(event, device)])
config_entry.async_on_unload( config_entry.async_on_unload(
@ -57,7 +57,7 @@ class AxisLight(AxisEventBase, LightEntity):
self.max_intensity = 0 self.max_intensity = 0
light_type = device.api.vapix.light_control[self.light_id].light_type light_type = device.api.vapix.light_control[self.light_id].light_type
self._attr_name = f"{light_type} {event.TYPE} {event.id}" self._attr_name = f"{light_type} {event.type} {event.id}"
self._attr_supported_color_modes = {ColorMode.BRIGHTNESS} self._attr_supported_color_modes = {ColorMode.BRIGHTNESS}
self._attr_color_mode = ColorMode.BRIGHTNESS self._attr_color_mode = ColorMode.BRIGHTNESS

View File

@ -3,7 +3,7 @@
"name": "Axis", "name": "Axis",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/axis", "documentation": "https://www.home-assistant.io/integrations/axis",
"requirements": ["axis==44"], "requirements": ["axis==45"],
"dhcp": [ "dhcp": [
{ {
"registered_devices": true "registered_devices": true

View File

@ -27,7 +27,7 @@ async def async_setup_entry(
"""Add switch from Axis device.""" """Add switch from Axis device."""
event: AxisEvent = device.api.event[event_id] event: AxisEvent = device.api.event[event_id]
if event.CLASS == CLASS_OUTPUT: if event.group == CLASS_OUTPUT:
async_add_entities([AxisSwitch(event, device)]) async_add_entities([AxisSwitch(event, device)])
config_entry.async_on_unload( config_entry.async_on_unload(

View File

@ -392,7 +392,7 @@ aurorapy==0.2.7
# avion==0.10 # avion==0.10
# homeassistant.components.axis # homeassistant.components.axis
axis==44 axis==45
# homeassistant.components.azure_event_hub # homeassistant.components.azure_event_hub
azure-eventhub==5.7.0 azure-eventhub==5.7.0

View File

@ -334,7 +334,7 @@ auroranoaa==0.0.2
aurorapy==0.2.7 aurorapy==0.2.7
# homeassistant.components.axis # homeassistant.components.axis
axis==44 axis==45
# homeassistant.components.azure_event_hub # homeassistant.components.azure_event_hub
azure-eventhub==5.7.0 azure-eventhub==5.7.0

View File

@ -74,7 +74,7 @@ async def test_camera_with_stream_profile(hass):
async def test_camera_disabled(hass): async def test_camera_disabled(hass):
"""Test that Axis camera platform is loaded properly but does not create camera entity.""" """Test that Axis camera platform is loaded properly but does not create camera entity."""
with patch("axis.vapix.Params.image_format", new=None): with patch("axis.vapix.vapix.Params.image_format", new=None):
await setup_axis_integration(hass) await setup_axis_integration(hass)
assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 0 assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 0

View File

@ -494,7 +494,7 @@ async def test_shutdown():
async def test_get_device_fails(hass): async def test_get_device_fails(hass):
"""Device unauthorized yields authentication required error.""" """Device unauthorized yields authentication required error."""
with patch( with patch(
"axis.vapix.Vapix.request", side_effect=axislib.Unauthorized "axis.vapix.vapix.Vapix.request", side_effect=axislib.Unauthorized
), pytest.raises(axis.errors.AuthenticationRequired): ), pytest.raises(axis.errors.AuthenticationRequired):
await axis.device.get_axis_device(hass, ENTRY_CONFIG) await axis.device.get_axis_device(hass, ENTRY_CONFIG)
@ -502,7 +502,7 @@ async def test_get_device_fails(hass):
async def test_get_device_device_unavailable(hass): async def test_get_device_device_unavailable(hass):
"""Device unavailable yields cannot connect error.""" """Device unavailable yields cannot connect error."""
with patch( with patch(
"axis.vapix.Vapix.request", side_effect=axislib.RequestError "axis.vapix.vapix.Vapix.request", side_effect=axislib.RequestError
), pytest.raises(axis.errors.CannotConnect): ), pytest.raises(axis.errors.CannotConnect):
await axis.device.get_axis_device(hass, ENTRY_CONFIG) await axis.device.get_axis_device(hass, ENTRY_CONFIG)
@ -510,6 +510,6 @@ async def test_get_device_device_unavailable(hass):
async def test_get_device_unknown_error(hass): async def test_get_device_unknown_error(hass):
"""Device yield unknown error.""" """Device yield unknown error."""
with patch( with patch(
"axis.vapix.Vapix.request", side_effect=axislib.AxisException "axis.vapix.vapix.Vapix.request", side_effect=axislib.AxisException
), pytest.raises(axis.errors.AuthenticationRequired): ), pytest.raises(axis.errors.AuthenticationRequired):
await axis.device.get_axis_device(hass, ENTRY_CONFIG) await axis.device.get_axis_device(hass, ENTRY_CONFIG)

View File

@ -81,10 +81,10 @@ async def test_lights(hass, mock_rtsp_event):
# Add light # Add light
with patch( with patch(
"axis.light_control.LightControl.get_current_intensity", "axis.vapix.interfaces.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}}, return_value={"data": {"intensity": 100}},
), patch( ), patch(
"axis.light_control.LightControl.get_valid_intensity", "axis.vapix.interfaces.light_control.LightControl.get_valid_intensity",
return_value={"data": {"ranges": [{"high": 150}]}}, return_value={"data": {"ranges": [{"high": 150}]}},
): ):
mock_rtsp_event( mock_rtsp_event(
@ -106,11 +106,11 @@ async def test_lights(hass, mock_rtsp_event):
# Turn on, set brightness, light already on # Turn on, set brightness, light already on
with patch( with patch(
"axis.light_control.LightControl.activate_light" "axis.vapix.interfaces.light_control.LightControl.activate_light"
) as mock_activate, patch( ) as mock_activate, patch(
"axis.light_control.LightControl.set_manual_intensity" "axis.vapix.interfaces.light_control.LightControl.set_manual_intensity"
) as mock_set_intensity, patch( ) as mock_set_intensity, patch(
"axis.light_control.LightControl.get_current_intensity", "axis.vapix.interfaces.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}}, return_value={"data": {"intensity": 100}},
): ):
await hass.services.async_call( await hass.services.async_call(
@ -124,9 +124,9 @@ async def test_lights(hass, mock_rtsp_event):
# Turn off # Turn off
with patch( with patch(
"axis.light_control.LightControl.deactivate_light" "axis.vapix.interfaces.light_control.LightControl.deactivate_light"
) as mock_deactivate, patch( ) as mock_deactivate, patch(
"axis.light_control.LightControl.get_current_intensity", "axis.vapix.interfaces.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}}, return_value={"data": {"intensity": 100}},
): ):
await hass.services.async_call( await hass.services.async_call(
@ -152,11 +152,11 @@ async def test_lights(hass, mock_rtsp_event):
# Turn on, set brightness # Turn on, set brightness
with patch( with patch(
"axis.light_control.LightControl.activate_light" "axis.vapix.interfaces.light_control.LightControl.activate_light"
) as mock_activate, patch( ) as mock_activate, patch(
"axis.light_control.LightControl.set_manual_intensity" "axis.vapix.interfaces.light_control.LightControl.set_manual_intensity"
) as mock_set_intensity, patch( ) as mock_set_intensity, patch(
"axis.light_control.LightControl.get_current_intensity", "axis.vapix.interfaces.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}}, return_value={"data": {"intensity": 100}},
): ):
await hass.services.async_call( await hass.services.async_call(
@ -170,9 +170,9 @@ async def test_lights(hass, mock_rtsp_event):
# Turn off, light already off # Turn off, light already off
with patch( with patch(
"axis.light_control.LightControl.deactivate_light" "axis.vapix.interfaces.light_control.LightControl.deactivate_light"
) as mock_deactivate, patch( ) as mock_deactivate, patch(
"axis.light_control.LightControl.get_current_intensity", "axis.vapix.interfaces.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}}, return_value={"data": {"intensity": 100}},
): ):
await hass.services.async_call( await hass.services.async_call(