Axis IO-port support (#23312)
Support digital inputs and supervised inputs, digital outputs and relays
This commit is contained in:
1 parent
5c346e8fb6
commit
eb912be47a
10 files changed
+334
-99
No files matched your search
@@ -6,9 +6,9 @@ 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 .axis_base import AxisEntityBase
|
||||
from .const import DOMAIN as AXIS_DOMAIN
|
||||
|
||||
AXIS_IMAGE = 'http://{}:{}/axis-cgi/jpg/image.cgi'
|
||||
@@ -38,28 +38,20 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async_add_entities([AxisCamera(config, device)])
|
||||
|
||||
|
||||
class AxisCamera(MjpegCamera):
|
||||
class AxisCamera(AxisEntityBase, MjpegCamera):
|
||||
"""Representation of a Axis camera."""
|
||||
|
||||
def __init__(self, config, device):
|
||||
"""Initialize Axis Communications camera component."""
|
||||
super().__init__(config)
|
||||
self.device_config = config
|
||||
self.device = device
|
||||
self.port = device.config_entry.data[CONF_DEVICE][CONF_PORT]
|
||||
self.unsub_dispatcher = []
|
||||
AxisEntityBase.__init__(self, device)
|
||||
MjpegCamera.__init__(self, config)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe camera events."""
|
||||
self.unsub_dispatcher.append(async_dispatcher_connect(
|
||||
self.hass, self.device.event_new_address, self._new_address))
|
||||
self.unsub_dispatcher.append(async_dispatcher_connect(
|
||||
self.hass, self.device.event_reachable, self.update_callback))
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Disconnect device object when removed."""
|
||||
for unsub_dispatcher in self.unsub_dispatcher:
|
||||
unsub_dispatcher()
|
||||
await super().async_added_to_hass()
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
@@ -74,29 +66,13 @@ class AxisCamera(MjpegCamera):
|
||||
self.device.config_entry.data[CONF_DEVICE][CONF_PASSWORD],
|
||||
self.device.host)
|
||||
|
||||
@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_address(self):
|
||||
"""Set new device address for video stream."""
|
||||
self._mjpeg_url = AXIS_VIDEO.format(self.device.host, self.port)
|
||||
self._still_image_url = AXIS_IMAGE.format(self.device.host, self.port)
|
||||
port = self.device.config_entry.data[CONF_DEVICE][CONF_PORT]
|
||||
self._mjpeg_url = AXIS_VIDEO.format(self.device.host, port)
|
||||
self._still_image_url = AXIS_IMAGE.format(self.device.host, port)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique identifier for this device."""
|
||||
return '{}-camera'.format(self.device.serial)
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return a device description for device registry."""
|
||||
return {
|
||||
'identifiers': {(AXIS_DOMAIN, self.device.serial)}
|
||||
}
|
||||
Reference in new issue
Block a user