diff --git a/homeassistant/components/homematicip_cloud/__init__.py b/homeassistant/components/homematicip_cloud/__init__.py index b45ac291bfc..fd07356d7fb 100644 --- a/homeassistant/components/homematicip_cloud/__init__.py +++ b/homeassistant/components/homematicip_cloud/__init__.py @@ -5,6 +5,7 @@ import voluptuous as vol from homeassistant import config_entries from homeassistant.const import CONF_NAME +from homeassistant.helpers import device_registry as dr import homeassistant.helpers.config_validation as cv from .config_flow import configured_haps @@ -52,7 +53,22 @@ async def async_setup_entry(hass, entry): hap = HomematicipHAP(hass, entry) hapid = entry.data[HMIPC_HAPID].replace('-', '').upper() hass.data[DOMAIN][hapid] = hap - return await hap.async_setup() + + if not await hap.async_setup(): + return False + + # Register hap as device in registry. + device_registry = await dr.async_get_registry(hass) + home = hap.home + device_registry.async_get_or_create( + config_entry_id=home.id, + identifiers={(DOMAIN, home.id)}, + manufacturer='eQ-3', + name=home.label, + model=home.modelType, + sw_version=home.currentAPVersion, + ) + return True async def async_unload_entry(hass, entry): diff --git a/homeassistant/components/homematicip_cloud/device.py b/homeassistant/components/homematicip_cloud/device.py index c43f0e24e2b..85cc3c0c77a 100644 --- a/homeassistant/components/homematicip_cloud/device.py +++ b/homeassistant/components/homematicip_cloud/device.py @@ -1,6 +1,7 @@ """Generic device for the HomematicIP Cloud component.""" import logging +from homeassistant.components import homematicip_cloud from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -32,6 +33,25 @@ class HomematicipGenericDevice(Entity): self.post = post _LOGGER.info("Setting up %s (%s)", self.name, self._device.modelType) + @property + def device_info(self): + """Return device specific attributes.""" + from homematicip.aio.device import AsyncDevice + # Only physical devices should be HA devices. + if isinstance(self._device, AsyncDevice): + return { + 'identifiers': { + # Serial numbers of Homematic IP device + (homematicip_cloud.DOMAIN, self._device.id) + }, + 'name': self._device.label, + 'manufacturer': self._device.oem, + 'model': self._device.modelType, + 'sw_version': self._device.firmwareVersion, + 'via_hub': (homematicip_cloud.DOMAIN, self._device.homeId), + } + return None + async def async_added_to_hass(self): """Register callbacks.""" self._device.on_update(self._device_changed) diff --git a/homeassistant/components/homematicip_cloud/sensor.py b/homeassistant/components/homematicip_cloud/sensor.py index b753a4d1aa5..d755735e0e0 100644 --- a/homeassistant/components/homematicip_cloud/sensor.py +++ b/homeassistant/components/homematicip_cloud/sensor.py @@ -65,6 +65,17 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice): """Initialize access point device.""" super().__init__(home, home) + @property + def device_info(self): + """Return device specific attributes.""" + # Adds a sensor to the existing HAP device + return { + 'identifiers': { + # Serial numbers of Homematic IP device + (HMIPC_DOMAIN, self._device.id) + } + } + @property def icon(self): """Return the icon of the access point device.""" diff --git a/tests/components/homematicip_cloud/test_init.py b/tests/components/homematicip_cloud/test_init.py index 18537227247..8b02b36de20 100644 --- a/tests/components/homematicip_cloud/test_init.py +++ b/tests/components/homematicip_cloud/test_init.py @@ -21,7 +21,7 @@ async def test_config_with_accesspoint_passed_to_config_entry(hass): }) is True # Flow started for the access point - assert len(mock_config_entries.flow.mock_calls) == 2 + assert len(mock_config_entries.flow.mock_calls) >= 2 async def test_config_already_registered_not_passed_to_config_entry(hass): @@ -58,7 +58,7 @@ async def test_setup_entry_successful(hass): } }) is True - assert len(mock_hap.mock_calls) == 2 + assert len(mock_hap.mock_calls) >= 2 async def test_setup_defined_accesspoint(hass): @@ -95,7 +95,7 @@ async def test_unload_entry(hass): mock_hap.return_value.async_setup.return_value = mock_coro(True) assert await async_setup_component(hass, hmipc.DOMAIN, {}) is True - assert len(mock_hap.return_value.mock_calls) == 1 + assert len(mock_hap.return_value.mock_calls) >= 1 mock_hap.return_value.async_reset.return_value = mock_coro(True) assert await hmipc.async_unload_entry(hass, entry)