Add device_info to enable HA-devices for Homematic IP (#21241)
* add device_info to device * added checks * Fixes based on feedback * Fix spelling * Simplified implementation On homematicip devices and the ap are created * small fix with device.id * hub/ap device creation moved to __init__.py * Fixed result handling * fixes after review. * Fix test
This commit is contained in:
1 parent
9066609d23
commit
9b3a3fc1ac
4 files changed
+51
-4
No files matched your search
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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."""
|
||||
|
||||
Reference in new issue
Block a user