Bump axis to v46 (#85431)

This commit is contained in:
Robert Svensson 2023-01-09 12:43:40 +01:00 committed by GitHub
parent 54168c9bdb
commit 1cdd535f21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 111 additions and 127 deletions

View file

@ -1,12 +1,11 @@
"""Support for Axis lights."""
from typing import Any
from axis.event_stream import CLASS_LIGHT, AxisBinaryEvent, AxisEvent
from axis.models.event import Event, EventOperation, EventTopic
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .axis_base import AxisEventBase
@ -29,15 +28,14 @@ async def async_setup_entry(
return
@callback
def async_add_sensor(event_id):
"""Add light from Axis device."""
event: AxisEvent = device.api.event[event_id]
def async_create_entity(event: Event) -> None:
"""Create Axis light entity."""
async_add_entities([AxisLight(event, device)])
if event.group == CLASS_LIGHT and event.type == "Light":
async_add_entities([AxisLight(event, device)])
config_entry.async_on_unload(
async_dispatcher_connect(hass, device.signal_new_event, async_add_sensor)
device.api.event.subscribe(
async_create_entity,
topic_filter=EventTopic.LIGHT_STATUS,
operation_filter=EventOperation.INITIALIZED,
)
@ -45,9 +43,8 @@ class AxisLight(AxisEventBase, LightEntity):
"""Representation of a light Axis event."""
_attr_should_poll = True
event: AxisBinaryEvent
def __init__(self, event: AxisEvent, device: AxisNetworkDevice) -> None:
def __init__(self, event: Event, device: AxisNetworkDevice) -> None:
"""Initialize the Axis light."""
super().__init__(event, device)
@ -57,7 +54,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} {self.event_type} {event.id}"
self._attr_supported_color_modes = {ColorMode.BRIGHTNESS}
self._attr_color_mode = ColorMode.BRIGHTNESS