Axis component reflect device availability (#22401)
This commit is contained in:
1 parent
f4625fd561
commit
5f6037d563
10 files changed
+69
-28
No files matched your search
@@ -5,6 +5,7 @@ from homeassistant.components.mjpeg.camera import (
|
||||
from homeassistant.const import (
|
||||
CONF_AUTHENTICATION, CONF_DEVICE, CONF_HOST, CONF_MAC, CONF_NAME,
|
||||
CONF_PASSWORD, CONF_PORT, CONF_USERNAME, HTTP_DIGEST_AUTHENTICATION)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import DOMAIN as AXIS_DOMAIN
|
||||
@@ -46,12 +47,25 @@ class AxisCamera(MjpegCamera):
|
||||
self.device_config = config
|
||||
self.device = device
|
||||
self.port = device.config_entry.data[CONF_DEVICE][CONF_PORT]
|
||||
self.unsub_dispatcher = None
|
||||
self.unsub_dispatcher = []
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe camera events."""
|
||||
self.unsub_dispatcher = async_dispatcher_connect(
|
||||
self.hass, 'axis_{}_new_ip'.format(self.device.name), self._new_ip)
|
||||
self.unsub_dispatcher.append(async_dispatcher_connect(
|
||||
self.hass, 'axis_{}_new_ip'.format(self.device.name),
|
||||
self._new_ip))
|
||||
self.unsub_dispatcher.append(async_dispatcher_connect(
|
||||
self.hass, self.device.event_reachable, self.update_callback))
|
||||
|
||||
@callback
|
||||
def update_callback(self, no_delay=None):
|
||||
"""Update the cameras state."""
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if device is available."""
|
||||
return self.device.available
|
||||
|
||||
def _new_ip(self, host):
|
||||
"""Set new IP for video stream."""
|
||||
|
||||
Reference in new issue
Block a user