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
@@ -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"]
|
||||
|
||||
|
||||
Reference in new issue
Block a user