Add guard for empty mac address in Hue integration (#61037)

pull/61699/head
Marcel van der Veldt 2021-12-05 18:46:05 +01:00 committed by GitHub
parent 5fdcbbe0e1
commit 86e8034ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -95,13 +95,12 @@ async def handle_v2_migration(hass: core.HomeAssistant, entry: ConfigEntry) -> N
# handle entities attached to device
for hue_dev in api.devices:
zigbee = api.devices.get_zigbee_connectivity(hue_dev.id)
if not zigbee:
# not a zigbee device
if not zigbee or not zigbee.mac_address:
# not a zigbee device or invalid mac
continue
mac = zigbee.mac_address
# get/update existing device by V1 identifier (mac address)
# the device will now have both the old and the new identifier
identifiers = {(DOMAIN, hue_dev.id), (DOMAIN, mac)}
identifiers = {(DOMAIN, hue_dev.id), (DOMAIN, zigbee.mac_address)}
hass_dev = dev_reg.async_get_or_create(
config_entry_id=entry.entry_id, identifiers=identifiers
)

View File

@ -49,7 +49,8 @@ async def async_setup_devices(bridge: "HueBridge"):
params[ATTR_IDENTIFIERS].add((DOMAIN, api.config.bridge_id))
else:
params[ATTR_VIA_DEVICE] = (DOMAIN, api.config.bridge_device.id)
if zigbee := dev_controller.get_zigbee_connectivity(hue_device.id):
zigbee = dev_controller.get_zigbee_connectivity(hue_device.id)
if zigbee and zigbee.mac_address:
params[ATTR_CONNECTIONS] = {
(device_registry.CONNECTION_NETWORK_MAC, zigbee.mac_address)
}