diff --git a/homeassistant/components/axis/axis_base.py b/homeassistant/components/axis/axis_base.py index 2f21d900662..c5f32b0c245 100644 --- a/homeassistant/components/axis/axis_base.py +++ b/homeassistant/components/axis/axis_base.py @@ -51,10 +51,10 @@ class AxisEventBase(AxisEntityBase): 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.""" diff --git a/homeassistant/components/axis/binary_sensor.py b/homeassistant/components/axis/binary_sensor.py index 3e90f5ff2a1..a435b4c3872 100644 --- a/homeassistant/components/axis/binary_sensor.py +++ b/homeassistant/components/axis/binary_sensor.py @@ -55,8 +55,8 @@ async def async_setup_entry( """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)]) @@ -75,7 +75,8 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity): 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): @@ -83,6 +84,7 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity): Parameter no_delay is True when device_event_reachable is sent. """ + self._attr_is_on = self.event.is_tripped @callback def scheduled_update(now): @@ -104,22 +106,17 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity): 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), @@ -133,6 +130,6 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity): 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 diff --git a/homeassistant/components/axis/device.py b/homeassistant/components/axis/device.py index ea7edcf0483..5394c13ebff 100644 --- a/homeassistant/components/axis/device.py +++ b/homeassistant/components/axis/device.py @@ -9,8 +9,8 @@ import axis 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 diff --git a/homeassistant/components/axis/light.py b/homeassistant/components/axis/light.py index c75d18b1908..d3fefcd830d 100644 --- a/homeassistant/components/axis/light.py +++ b/homeassistant/components/axis/light.py @@ -33,7 +33,7 @@ async def async_setup_entry( """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( @@ -57,7 +57,7 @@ class AxisLight(AxisEventBase, LightEntity): 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 diff --git a/homeassistant/components/axis/manifest.json b/homeassistant/components/axis/manifest.json index aad057cd4b3..4e9b64cbb52 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==44"], + "requirements": ["axis==45"], "dhcp": [ { "registered_devices": true diff --git a/homeassistant/components/axis/switch.py b/homeassistant/components/axis/switch.py index 6576e9d519e..344dddd0b5f 100644 --- a/homeassistant/components/axis/switch.py +++ b/homeassistant/components/axis/switch.py @@ -27,7 +27,7 @@ async def async_setup_entry( """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( diff --git a/requirements_all.txt b/requirements_all.txt index e567a01fbd1..4671612432a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 78cf56ad1a6..f6f75e5bb17 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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 diff --git a/tests/components/axis/test_camera.py b/tests/components/axis/test_camera.py index 4961b4c40ca..d75722c0d4f 100644 --- a/tests/components/axis/test_camera.py +++ b/tests/components/axis/test_camera.py @@ -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 diff --git a/tests/components/axis/test_device.py b/tests/components/axis/test_device.py index ba6df6e2e2d..8a4d821e38d 100644 --- a/tests/components/axis/test_device.py +++ b/tests/components/axis/test_device.py @@ -494,7 +494,7 @@ 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) @@ -502,7 +502,7 @@ async def test_get_device_fails(hass): 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) @@ -510,6 +510,6 @@ async def test_get_device_device_unavailable(hass): 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) diff --git a/tests/components/axis/test_light.py b/tests/components/axis/test_light.py index db7ca6921fb..ce6ccce9095 100644 --- a/tests/components/axis/test_light.py +++ b/tests/components/axis/test_light.py @@ -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( @@ -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( @@ -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( @@ -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( @@ -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(