diff --git a/homeassistant/components/axis/device.py b/homeassistant/components/axis/device.py index 2d1a784dc66..94aa149c09e 100644 --- a/homeassistant/components/axis/device.py +++ b/homeassistant/components/axis/device.py @@ -161,9 +161,7 @@ class AxisNetworkDevice: async def use_mqtt(self, hass: HomeAssistant, component: str) -> None: """Set up to use MQTT.""" try: - status = await hass.async_add_executor_job( - self.api.vapix.mqtt.get_client_status - ) + status = await self.api.vapix.mqtt.get_client_status() except Unauthorized: # This means the user has too low privileges status = {} @@ -238,14 +236,15 @@ class AxisNetworkDevice: ) self.api.stream.stop() - @callback - def shutdown(self, event): + async def shutdown(self, event): """Stop the event stream.""" self.disconnect_from_stream() + await self.api.vapix.close() async def async_reset(self): """Reset this device to default state.""" self.disconnect_from_stream() + await self.api.vapix.close() unload_ok = all( await asyncio.gather( @@ -275,7 +274,7 @@ async def get_device(hass, host, port, username, password): try: with async_timeout.timeout(15): - await hass.async_add_executor_job(device.vapix.initialize) + await device.vapix.initialize() return device diff --git a/homeassistant/components/axis/light.py b/homeassistant/components/axis/light.py index 55c498b8b42..df4c00415ff 100644 --- a/homeassistant/components/axis/light.py +++ b/homeassistant/components/axis/light.py @@ -52,19 +52,17 @@ class AxisLight(AxisEventBase, LightEntity): """Subscribe lights events.""" await super().async_added_to_hass() - def get_light_capabilities(): - """Get light capabilities.""" - current_intensity = ( - self.device.api.vapix.light_control.get_current_intensity(self.light_id) - ) - self.current_intensity = current_intensity["data"]["intensity"] - - max_intensity = self.device.api.vapix.light_control.get_valid_intensity( + current_intensity = ( + await self.device.api.vapix.light_control.get_current_intensity( self.light_id ) - self.max_intensity = max_intensity["data"]["ranges"][0]["high"] + ) + self.current_intensity = current_intensity["data"]["intensity"] - await self.hass.async_add_executor_job(get_light_capabilities) + max_intensity = await self.device.api.vapix.light_control.get_valid_intensity( + self.light_id + ) + self.max_intensity = max_intensity["data"]["ranges"][0]["high"] @property def supported_features(self): @@ -87,26 +85,28 @@ class AxisLight(AxisEventBase, LightEntity): """Return the brightness of this light between 0..255.""" return int((self.current_intensity / self.max_intensity) * 255) - def turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs): """Turn on light.""" if not self.is_on: - self.device.api.vapix.light_control.activate_light(self.light_id) + await self.device.api.vapix.light_control.activate_light(self.light_id) if ATTR_BRIGHTNESS in kwargs: intensity = int((kwargs[ATTR_BRIGHTNESS] / 255) * self.max_intensity) - self.device.api.vapix.light_control.set_manual_intensity( + await self.device.api.vapix.light_control.set_manual_intensity( self.light_id, intensity ) - def turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs): """Turn off light.""" if self.is_on: - self.device.api.vapix.light_control.deactivate_light(self.light_id) + await self.device.api.vapix.light_control.deactivate_light(self.light_id) - def update(self): + async def async_update(self): """Update brightness.""" - current_intensity = self.device.api.vapix.light_control.get_current_intensity( - self.light_id + current_intensity = ( + await self.device.api.vapix.light_control.get_current_intensity( + self.light_id + ) ) self.current_intensity = current_intensity["data"]["intensity"] diff --git a/homeassistant/components/axis/manifest.json b/homeassistant/components/axis/manifest.json index 2135ecece2d..5b20e76c90d 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==39"], + "requirements": ["axis==40"], "zeroconf": [ { "type": "_axis-video._tcp.local.", "macaddress": "00408C*" }, { "type": "_axis-video._tcp.local.", "macaddress": "ACCC8E*" }, diff --git a/homeassistant/components/axis/switch.py b/homeassistant/components/axis/switch.py index 85a2237fd28..f3436b3eb83 100644 --- a/homeassistant/components/axis/switch.py +++ b/homeassistant/components/axis/switch.py @@ -37,15 +37,11 @@ class AxisSwitch(AxisEventBase, SwitchEntity): async def async_turn_on(self, **kwargs): """Turn on switch.""" - await self.hass.async_add_executor_job( - self.device.api.vapix.ports[self.event.id].close - ) + await self.device.api.vapix.ports[self.event.id].close() async def async_turn_off(self, **kwargs): """Turn off switch.""" - await self.hass.async_add_executor_job( - self.device.api.vapix.ports[self.event.id].open - ) + await self.device.api.vapix.ports[self.event.id].open() @property def name(self): diff --git a/requirements_all.txt b/requirements_all.txt index 173a1210183..d66dfe12036 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==39 +axis==40 # homeassistant.components.azure_event_hub azure-eventhub==5.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 78be9e667c1..7658ac20d91 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -180,7 +180,7 @@ av==8.0.2 avri-api==0.1.7 # homeassistant.components.axis -axis==39 +axis==40 # homeassistant.components.azure_event_hub azure-eventhub==5.1.0 diff --git a/tests/components/axis/test_device.py b/tests/components/axis/test_device.py index fa503fd4b0e..627a17ecf60 100644 --- a/tests/components/axis/test_device.py +++ b/tests/components/axis/test_device.py @@ -38,7 +38,7 @@ from homeassistant.const import ( CONF_USERNAME, ) -from tests.async_mock import Mock, patch +from tests.async_mock import AsyncMock, Mock, patch from tests.common import MockConfigEntry, async_fire_mqtt_message MAC = "00408C12345" @@ -196,7 +196,7 @@ root.StreamProfile.S1.Parameters=videocodec=h265 """ -def vapix_request(self, session, url, **kwargs): +async def vapix_request(self, session, url, **kwargs): """Return data based on url.""" if API_DISCOVERY_URL in url: return API_DISCOVERY_RESPONSE @@ -384,10 +384,12 @@ async def test_shutdown(): axis_device = axis.device.AxisNetworkDevice(hass, entry) axis_device.api = Mock() + axis_device.api.vapix.close = AsyncMock() - axis_device.shutdown(None) + await axis_device.shutdown(None) assert len(axis_device.api.stream.stop.mock_calls) == 1 + assert len(axis_device.api.vapix.close.mock_calls) == 1 async def test_get_device_fails(hass): diff --git a/tests/components/axis/test_light.py b/tests/components/axis/test_light.py index 98613451b0d..987ef1cd48b 100644 --- a/tests/components/axis/test_light.py +++ b/tests/components/axis/test_light.py @@ -91,7 +91,7 @@ async def test_lights(hass): {"entity_id": f"light.{NAME}_ir_light_0", ATTR_BRIGHTNESS: 50}, blocking=True, ) - mock_activate.not_called() + mock_activate.assert_not_awaited() mock_set_intensity.assert_called_once_with("led0", 29) # Turn off diff --git a/tests/components/axis/test_switch.py b/tests/components/axis/test_switch.py index f00c17784d2..37d50e33e3e 100644 --- a/tests/components/axis/test_switch.py +++ b/tests/components/axis/test_switch.py @@ -13,7 +13,7 @@ from .test_device import ( setup_axis_integration, ) -from tests.async_mock import Mock, patch +from tests.async_mock import AsyncMock, patch EVENTS = [ { @@ -55,8 +55,10 @@ async def test_switches_with_port_cgi(hass): """Test that switches are loaded properly using port.cgi.""" device = await setup_axis_integration(hass) - device.api.vapix.ports = {"0": Mock(), "1": Mock()} + device.api.vapix.ports = {"0": AsyncMock(), "1": AsyncMock()} device.api.vapix.ports["0"].name = "Doorbell" + device.api.vapix.ports["0"].open = AsyncMock() + device.api.vapix.ports["0"].close = AsyncMock() device.api.vapix.ports["1"].name = "" for event in EVENTS: @@ -98,8 +100,10 @@ async def test_switches_with_port_management(hass): with patch.dict(API_DISCOVERY_RESPONSE, api_discovery): device = await setup_axis_integration(hass) - device.api.vapix.ports = {"0": Mock(), "1": Mock()} + device.api.vapix.ports = {"0": AsyncMock(), "1": AsyncMock()} device.api.vapix.ports["0"].name = "Doorbell" + device.api.vapix.ports["0"].open = AsyncMock() + device.api.vapix.ports["0"].close = AsyncMock() device.api.vapix.ports["1"].name = "" for event in EVENTS: