1 """Base classes for Axis entities."""
3 from __future__
import annotations
5 from abc
import abstractmethod
6 from collections.abc
import Callable
7 from dataclasses
import dataclass
8 from typing
import TYPE_CHECKING
10 from axis.models.event
import Event, EventTopic
17 from .const
import DOMAIN
as AXIS_DOMAIN
20 from .hub
import AxisHub
22 TOPIC_TO_EVENT_TYPE = {
23 EventTopic.DAY_NIGHT_VISION:
"DayNight",
24 EventTopic.FENCE_GUARD:
"Fence Guard",
25 EventTopic.LIGHT_STATUS:
"Light",
26 EventTopic.LOITERING_GUARD:
"Loitering Guard",
27 EventTopic.MOTION_DETECTION:
"Motion",
28 EventTopic.MOTION_DETECTION_3:
"VMD3",
29 EventTopic.MOTION_DETECTION_4:
"VMD4",
30 EventTopic.MOTION_GUARD:
"Motion Guard",
31 EventTopic.OBJECT_ANALYTICS:
"Object Analytics",
32 EventTopic.PIR:
"PIR",
33 EventTopic.PORT_INPUT:
"Input",
34 EventTopic.PORT_SUPERVISED_INPUT:
"Supervised Input",
35 EventTopic.PTZ_IS_MOVING:
"is_moving",
36 EventTopic.PTZ_ON_PRESET:
"on_preset",
37 EventTopic.RELAY:
"Relay",
38 EventTopic.SOUND_TRIGGER_LEVEL:
"Sound",
42 @dataclass(frozen=True, kw_only=True)
44 """Axis event based entity description."""
46 event_topic: tuple[EventTopic, ...] | EventTopic
47 """Event topic that provides state updates."""
48 name_fn: Callable[[AxisHub, Event], str] =
lambda hub, event:
""
49 """Function providing the corresponding name to the event ID."""
50 supported_fn: Callable[[AxisHub, Event], bool] =
lambda hub, event:
True
51 """Function validating if event is supported."""
55 """Base common to all Axis entities."""
57 _attr_has_entity_name =
True
60 """Initialize the Axis event."""
64 identifiers={(AXIS_DOMAIN, hub.unique_id)},
65 serial_number=hub.unique_id,
69 """Subscribe device events."""
73 self.
hubhub.signal_reachable,
80 """Call when device connection state change."""
86 """Base common to all Axis entities from event stream."""
88 entity_description: AxisEventDescription
90 _attr_should_poll =
False
93 self, hub: AxisHub, description: AxisEventDescription, event: Event
95 """Initialize the Axis event."""
103 event_type = TOPIC_TO_EVENT_TYPE[event.topic_base]
104 self.
_attr_name_attr_name = description.name_fn(hub, event)
or f
"{event_type} {event.id}"
111 """Update the entities state."""
114 """Subscribe sensors events."""
117 self.
hubhub.api.event.subscribe(
None async_added_to_hass(self)
None __init__(self, AxisHub hub)
None async_signal_reachable_callback(self)
None async_event_callback(self, Event event)
None async_added_to_hass(self)
None __init__(self, AxisHub hub, AxisEventDescription description, Event event)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)