Skip to content

Commit

Permalink
Bump axis to v45 (home-assistant#84992)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 authored Jan 2, 2023
1 parent 02b5da7 commit 534bb74
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 36 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/axis/axis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def __init__(self, event: AxisEvent, device: AxisNetworkDevice) -> None:
super().__init__(device)
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_device_class = event.CLASS
self._attr_device_class = event.group

async def async_added_to_hass(self) -> None:
"""Subscribe sensors events."""
Expand Down
19 changes: 8 additions & 11 deletions homeassistant/components/axis/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def async_add_sensor(event_id):
"""Add binary sensor from Axis device."""
event: AxisEvent = device.api.event[event_id]

if event.CLASS not in (CLASS_OUTPUT, CLASS_PTZ) and not (
event.CLASS == CLASS_LIGHT and event.TYPE == "Light"
if event.group not in (CLASS_OUTPUT, CLASS_PTZ) and not (
event.group == CLASS_LIGHT and event.type == "Light"
):
async_add_entities([AxisBinarySensor(event, device)])

Expand All @@ -75,14 +75,16 @@ def __init__(self, event: AxisEvent, device: AxisNetworkDevice) -> None:
super().__init__(event, device)
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
def update_callback(self, no_delay=False):
"""Update the sensor's state, if needed.
Parameter no_delay is True when device_event_reachable is sent.
"""
self._attr_is_on = self.event.is_tripped

@callback
def scheduled_update(now):
Expand All @@ -104,22 +106,17 @@ def scheduled_update(now):
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
def name(self) -> str | None:
"""Return the name of the event."""
if (
self.event.CLASS == CLASS_INPUT
self.event.group == CLASS_INPUT
and self.event.id in self.device.api.vapix.ports
and 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 (
(FenceGuard, self.device.api.vapix.fence_guard),
Expand All @@ -133,6 +130,6 @@ def name(self) -> str | None:
and 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
2 changes: 1 addition & 1 deletion homeassistant/components/axis/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from axis.configuration import Configuration
from axis.errors import Unauthorized
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.vapix.interfaces.mqtt import mqtt_json_to_event

from homeassistant.components import mqtt
from homeassistant.components.mqtt import DOMAIN as MQTT_DOMAIN
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/axis/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def async_add_sensor(event_id):
"""Add light from Axis device."""
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)])

config_entry.async_on_unload(
Expand All @@ -57,7 +57,7 @@ def __init__(self, event: AxisEvent, device: AxisNetworkDevice) -> None:
self.max_intensity = 0

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_color_mode = ColorMode.BRIGHTNESS
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/axis/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Axis",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/axis",
"requirements": ["axis==44"],
"requirements": ["axis==45"],
"dhcp": [
{
"registered_devices": true
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/axis/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def async_add_switch(event_id):
"""Add switch from Axis device."""
event: AxisEvent = device.api.event[event_id]

if event.CLASS == CLASS_OUTPUT:
if event.group == CLASS_OUTPUT:
async_add_entities([AxisSwitch(event, device)])

config_entry.async_on_unload(
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ aurorapy==0.2.7
# avion==0.10

# homeassistant.components.axis
axis==44
axis==45

# homeassistant.components.azure_event_hub
azure-eventhub==5.7.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ auroranoaa==0.0.2
aurorapy==0.2.7

# homeassistant.components.axis
axis==44
axis==45

# homeassistant.components.azure_event_hub
azure-eventhub==5.7.0
Expand Down
2 changes: 1 addition & 1 deletion tests/components/axis/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def test_camera_with_stream_profile(hass):

async def test_camera_disabled(hass):
"""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)

assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 0
6 changes: 3 additions & 3 deletions tests/components/axis/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,22 +494,22 @@ async def test_shutdown():
async def test_get_device_fails(hass):
"""Device unauthorized yields authentication required error."""
with patch(
"axis.vapix.Vapix.request", side_effect=axislib.Unauthorized
"axis.vapix.vapix.Vapix.request", side_effect=axislib.Unauthorized
), pytest.raises(axis.errors.AuthenticationRequired):
await axis.device.get_axis_device(hass, ENTRY_CONFIG)


async def test_get_device_device_unavailable(hass):
"""Device unavailable yields cannot connect error."""
with patch(
"axis.vapix.Vapix.request", side_effect=axislib.RequestError
"axis.vapix.vapix.Vapix.request", side_effect=axislib.RequestError
), pytest.raises(axis.errors.CannotConnect):
await axis.device.get_axis_device(hass, ENTRY_CONFIG)


async def test_get_device_unknown_error(hass):
"""Device yield unknown error."""
with patch(
"axis.vapix.Vapix.request", side_effect=axislib.AxisException
"axis.vapix.vapix.Vapix.request", side_effect=axislib.AxisException
), pytest.raises(axis.errors.AuthenticationRequired):
await axis.device.get_axis_device(hass, ENTRY_CONFIG)
24 changes: 12 additions & 12 deletions tests/components/axis/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ async def test_lights(hass, mock_rtsp_event):

# Add light
with patch(
"axis.light_control.LightControl.get_current_intensity",
"axis.vapix.interfaces.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}},
), patch(
"axis.light_control.LightControl.get_valid_intensity",
"axis.vapix.interfaces.light_control.LightControl.get_valid_intensity",
return_value={"data": {"ranges": [{"high": 150}]}},
):
mock_rtsp_event(
Expand All @@ -106,11 +106,11 @@ async def test_lights(hass, mock_rtsp_event):

# Turn on, set brightness, light already on
with patch(
"axis.light_control.LightControl.activate_light"
"axis.vapix.interfaces.light_control.LightControl.activate_light"
) 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(
"axis.light_control.LightControl.get_current_intensity",
"axis.vapix.interfaces.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}},
):
await hass.services.async_call(
Expand All @@ -124,9 +124,9 @@ async def test_lights(hass, mock_rtsp_event):

# Turn off
with patch(
"axis.light_control.LightControl.deactivate_light"
"axis.vapix.interfaces.light_control.LightControl.deactivate_light"
) 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}},
):
await hass.services.async_call(
Expand All @@ -152,11 +152,11 @@ async def test_lights(hass, mock_rtsp_event):

# Turn on, set brightness
with patch(
"axis.light_control.LightControl.activate_light"
"axis.vapix.interfaces.light_control.LightControl.activate_light"
) 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(
"axis.light_control.LightControl.get_current_intensity",
"axis.vapix.interfaces.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}},
):
await hass.services.async_call(
Expand All @@ -170,9 +170,9 @@ async def test_lights(hass, mock_rtsp_event):

# Turn off, light already off
with patch(
"axis.light_control.LightControl.deactivate_light"
"axis.vapix.interfaces.light_control.LightControl.deactivate_light"
) 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}},
):
await hass.services.async_call(
Expand Down

0 comments on commit 534bb74

Please sign in to comment.