1 """Axis network device abstraction."""
3 from __future__
import annotations
6 from axis.errors
import Unauthorized
7 from axis.interfaces.mqtt
import mqtt_json_to_event
8 from axis.models.mqtt
import ClientState
9 from axis.stream_manager
import Signal, State
20 """Manage connection to event sources from an Axis device."""
23 self, hass: HomeAssistant, config_entry: ConfigEntry, api: axis.AxisDevice
25 """Initialize the device."""
36 """Set up the device events."""
38 self.
apiapi.enable_events()
39 self.
apiapi.stream.start()
41 if self.
apiapi.vapix.mqtt.supported:
46 """Tear down connections."""
52 if self.
apiapi.stream.state != State.STOPPED:
53 self.
apiapi.stream.connection_status_callback.clear()
54 self.
apiapi.stream.stop()
57 """Set up to use MQTT."""
59 status = await self.
apiapi.vapix.mqtt.get_client_status()
64 if status.status.state == ClientState.ACTIVE:
66 await mqtt.async_subscribe(
67 hass, f
"{status.config.device_topic_prefix}/#", self.
_mqtt_message_mqtt_message
73 """Receive Axis MQTT message."""
76 if message.topic.endswith(
"event/connection"):
79 event = mqtt_json_to_event(message.payload)
80 self.
apiapi.event.handler(event)
84 """Handle signals of device connection status.
86 This is called on every RTSP keep-alive message.
87 Only signal state change if state change is true.
90 if self.
availableavailable != (status == Signal.PLAYING):
None __init__(self, HomeAssistant hass, ConfigEntry config_entry, axis.AxisDevice api)
None _disconnect_from_stream(self)
None _mqtt_message(self, ReceiveMessage message)
None _async_use_mqtt(self, HomeAssistant hass, str component)
None _connection_status_cb(self, Signal status)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)
None async_when_setup(core.HomeAssistant hass, str component, Callable[[core.HomeAssistant, str], Awaitable[None]] when_setup_cb)