From 86e8034ea0eb30a622c9cd50503d47ead569478a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sun, 5 Dec 2021 18:46:05 +0100 Subject: [PATCH] Add guard for empty mac address in Hue integration (#61037) --- homeassistant/components/hue/migration.py | 7 +++---- homeassistant/components/hue/v2/device.py | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/hue/migration.py b/homeassistant/components/hue/migration.py index 5396e646ce1..2da13ce8bf2 100644 --- a/homeassistant/components/hue/migration.py +++ b/homeassistant/components/hue/migration.py @@ -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 ) diff --git a/homeassistant/components/hue/v2/device.py b/homeassistant/components/hue/v2/device.py index 1608743cc48..64bdcc7a4f2 100644 --- a/homeassistant/components/hue/v2/device.py +++ b/homeassistant/components/hue/v2/device.py @@ -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) }