Axis devices support device registry (#22367)
* Add support for device registry * Fix test
This commit is contained in:
parent
646c4a7137
commit
52437f6246
5 changed files with 44 additions and 1 deletions
|
@ -52,6 +52,8 @@ async def async_setup_entry(hass, config_entry):
|
|||
|
||||
hass.data[DOMAIN][device.serial] = device
|
||||
|
||||
await device.async_update_device_registry()
|
||||
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, device.shutdown)
|
||||
|
||||
return True
|
||||
|
|
|
@ -81,7 +81,20 @@ class AxisBinarySensor(BinarySensorDevice):
|
|||
"""Return the class of the event."""
|
||||
return self.event.event_class
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique identifier for this device."""
|
||||
return '{}-{}-{}'.format(
|
||||
self.device.serial, self.event.topic, self.event.id)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return a device description for device registry."""
|
||||
return {
|
||||
'identifiers': {(AXIS_DOMAIN, self.device.serial)}
|
||||
}
|
||||
|
|
|
@ -57,3 +57,15 @@ class AxisCamera(MjpegCamera):
|
|||
"""Set new IP for video stream."""
|
||||
self._mjpeg_url = AXIS_VIDEO.format(host, self.port)
|
||||
self._still_image_url = AXIS_IMAGE.format(host, self.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)}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,10 @@ from homeassistant.const import (
|
|||
CONF_USERNAME)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
from .const import CONF_CAMERA, CONF_EVENTS, CONF_MODEL, LOGGER
|
||||
from .const import CONF_CAMERA, CONF_EVENTS, CONF_MODEL, DOMAIN, LOGGER
|
||||
from .errors import AuthenticationRequired, CannotConnect
|
||||
|
||||
|
||||
|
@ -49,6 +50,20 @@ class AxisNetworkDevice:
|
|||
"""Return the mac of this device."""
|
||||
return self.config_entry.data[CONF_MAC]
|
||||
|
||||
async def async_update_device_registry(self):
|
||||
"""Update device registry."""
|
||||
device_registry = await \
|
||||
self.hass.helpers.device_registry.async_get_registry()
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=self.config_entry.entry_id,
|
||||
connections={(CONNECTION_NETWORK_MAC, self.serial)},
|
||||
identifiers={(DOMAIN, self.serial)},
|
||||
manufacturer='Axis Communications AB',
|
||||
model="{} {}".format(self.model, self.product_type),
|
||||
name=self.name,
|
||||
sw_version=self.fw_version
|
||||
)
|
||||
|
||||
async def async_setup(self):
|
||||
"""Set up the device."""
|
||||
from axis.vapix import VAPIX_FW_VERSION, VAPIX_PROD_TYPE
|
||||
|
|
|
@ -53,6 +53,7 @@ async def test_setup_entry(hass):
|
|||
|
||||
mock_device = Mock()
|
||||
mock_device.async_setup.return_value = mock_coro(True)
|
||||
mock_device.async_update_device_registry.return_value = mock_coro(True)
|
||||
mock_device.serial.return_value = '1'
|
||||
|
||||
with patch.object(axis, 'AxisNetworkDevice') as mock_device_class, \
|
||||
|
|
Loading…
Add table
Reference in a new issue