mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 15:27:08 +00:00
Axis devices support device registry (#22367)
* Add support for device registry * Fix test
This commit is contained in:
parent
646c4a7137
commit
52437f6246
@ -52,6 +52,8 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
|
|
||||||
hass.data[DOMAIN][device.serial] = device
|
hass.data[DOMAIN][device.serial] = device
|
||||||
|
|
||||||
|
await device.async_update_device_registry()
|
||||||
|
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, device.shutdown)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, device.shutdown)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -81,7 +81,20 @@ class AxisBinarySensor(BinarySensorDevice):
|
|||||||
"""Return the class of the event."""
|
"""Return the class of the event."""
|
||||||
return self.event.event_class
|
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
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
"""No polling needed."""
|
"""No polling needed."""
|
||||||
return False
|
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."""
|
"""Set new IP for video stream."""
|
||||||
self._mjpeg_url = AXIS_VIDEO.format(host, self.port)
|
self._mjpeg_url = AXIS_VIDEO.format(host, self.port)
|
||||||
self._still_image_url = AXIS_IMAGE.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)
|
CONF_USERNAME)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
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
|
from .errors import AuthenticationRequired, CannotConnect
|
||||||
|
|
||||||
|
|
||||||
@ -49,6 +50,20 @@ class AxisNetworkDevice:
|
|||||||
"""Return the mac of this device."""
|
"""Return the mac of this device."""
|
||||||
return self.config_entry.data[CONF_MAC]
|
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):
|
async def async_setup(self):
|
||||||
"""Set up the device."""
|
"""Set up the device."""
|
||||||
from axis.vapix import VAPIX_FW_VERSION, VAPIX_PROD_TYPE
|
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 = Mock()
|
||||||
mock_device.async_setup.return_value = mock_coro(True)
|
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'
|
mock_device.serial.return_value = '1'
|
||||||
|
|
||||||
with patch.object(axis, 'AxisNetworkDevice') as mock_device_class, \
|
with patch.object(axis, 'AxisNetworkDevice') as mock_device_class, \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user