Adapt Axis integration to async HTTPx calls (#42095)
This commit is contained in:
1 parent
fcdb54d878
commit
1303d20064
9 files changed
+41
-40
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
|
||||
@@ -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*" },
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user