Add support for zha device registry (#18755)

This commit is contained in:
damarco 2018-12-01 10:31:49 +01:00 committed by Martin Hjelmare
parent ecca51b16b
commit 1ae58ce48b
2 changed files with 31 additions and 0 deletions

View File

@ -15,6 +15,7 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.components.zha.entities import ZhaDeviceEntity
from homeassistant import config_entries, const as ha_const
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE
from . import const as zha_const
# Loading the config flow file will register the flow
@ -116,10 +117,12 @@ async def async_setup_entry(hass, config_entry):
import bellows.ezsp
from bellows.zigbee.application import ControllerApplication
radio = bellows.ezsp.EZSP()
radio_description = "EZSP"
elif radio_type == RadioType.xbee.name:
import zigpy_xbee.api
from zigpy_xbee.zigbee.application import ControllerApplication
radio = zigpy_xbee.api.XBee()
radio_description = "XBee"
await radio.connect(usb_path, baudrate)
hass.data[DATA_ZHA][DATA_ZHA_RADIO] = radio
@ -137,6 +140,17 @@ async def async_setup_entry(hass, config_entry):
hass.async_create_task(
listener.async_device_initialized(device, False))
device_registry = await \
hass.helpers.device_registry.async_get_registry()
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(CONNECTION_ZIGBEE, str(APPLICATION_CONTROLLER.ieee))},
identifiers={(DOMAIN, str(APPLICATION_CONTROLLER.ieee))},
name="Zigbee Coordinator",
manufacturer="ZHA",
model=radio_description,
)
hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID] = str(APPLICATION_CONTROLLER.ieee)
for component in COMPONENTS:

View File

@ -7,6 +7,10 @@ https://home-assistant.io/components/zha/
from homeassistant.helpers import entity
from homeassistant.util import slugify
from homeassistant.core import callback
from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE
from homeassistant.components.zha.const import (
DOMAIN, DATA_ZHA, DATA_ZHA_BRIDGE_ID
)
class ZhaEntity(entity.Entity):
@ -87,3 +91,16 @@ class ZhaEntity(entity.Entity):
def zdo_command(self, tsn, command_id, args):
"""Handle a ZDO command received on this cluster."""
pass
@property
def device_info(self):
"""Return a device description for device registry."""
ieee = str(self._endpoint.device.ieee)
return {
'connections': {(CONNECTION_ZIGBEE, ieee)},
'identifiers': {(DOMAIN, ieee)},
'manufacturer': self._endpoint.manufacturer,
'model': self._endpoint.model,
'name': self._device_state_attributes['friendly_name'],
'via_hub': (DOMAIN, self.hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID]),
}