diff --git a/homeassistant/components/axis/__init__.py b/homeassistant/components/axis/__init__.py index 324c2cf369e..53087f2682c 100644 --- a/homeassistant/components/axis/__init__.py +++ b/homeassistant/components/axis/__init__.py @@ -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 diff --git a/homeassistant/components/axis/binary_sensor.py b/homeassistant/components/axis/binary_sensor.py index ec4c27ea343..3a9583f6419 100644 --- a/homeassistant/components/axis/binary_sensor.py +++ b/homeassistant/components/axis/binary_sensor.py @@ -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)} + } diff --git a/homeassistant/components/axis/camera.py b/homeassistant/components/axis/camera.py index 60dab841048..45801257d00 100644 --- a/homeassistant/components/axis/camera.py +++ b/homeassistant/components/axis/camera.py @@ -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)} + } diff --git a/homeassistant/components/axis/device.py b/homeassistant/components/axis/device.py index 02591e348a5..0d7d9348870 100644 --- a/homeassistant/components/axis/device.py +++ b/homeassistant/components/axis/device.py @@ -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 diff --git a/tests/components/axis/test_init.py b/tests/components/axis/test_init.py index 0586ffd96f6..c1c4c06f6ac 100644 --- a/tests/components/axis/test_init.py +++ b/tests/components/axis/test_init.py @@ -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, \