Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions homeassistant/components/zha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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
Expand Down Expand Up @@ -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
Expand All @@ -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))},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we duplicating some info in the ZhaDeviceEntity now that we add device info? Do we need to keep the ZhaDeviceEntity entity or can it be cleaned up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. As we are not able to expose arbitrary data through device info, ZhaDeviceEntity is still needed. It is currently used for rx/tx status info, last_seen, network addresses and possibly other device level attributes like battery status in the future.

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:
Expand Down
17 changes: 17 additions & 0 deletions homeassistant/components/zha/entities/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
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):
Expand Down Expand Up @@ -87,3 +91,16 @@ def attribute_updated(self, attribute, value):
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]),
}