From 9dc4597f59c63550cad7912e91110ea6b4825c0a Mon Sep 17 00:00:00 2001 From: Andre Lengwenus Date: Thu, 9 Jan 2025 13:44:57 +0100 Subject: [PATCH] Update module properties on module scan for LCN (#135018) --- homeassistant/components/lcn/websocket.py | 31 ++++++++++------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/lcn/websocket.py b/homeassistant/components/lcn/websocket.py index d3268dfbf91..46df71d4235 100644 --- a/homeassistant/components/lcn/websocket.py +++ b/homeassistant/components/lcn/websocket.py @@ -423,25 +423,22 @@ async def async_create_or_update_device_in_config_entry( device_connection.is_group, ) - device_configs = [*config_entry.data[CONF_DEVICES]] - data = {**config_entry.data, CONF_DEVICES: device_configs} - for device_config in data[CONF_DEVICES]: - if tuple(device_config[CONF_ADDRESS]) == address: - break # device already in config_entry - else: - # create new device_entry - device_config = { - CONF_ADDRESS: address, - CONF_NAME: "", - CONF_HARDWARE_SERIAL: -1, - CONF_SOFTWARE_SERIAL: -1, - CONF_HARDWARE_TYPE: -1, - } - data[CONF_DEVICES].append(device_config) + device_config = { + CONF_ADDRESS: address, + CONF_NAME: "", + CONF_HARDWARE_SERIAL: -1, + CONF_SOFTWARE_SERIAL: -1, + CONF_HARDWARE_TYPE: -1, + } + + device_configs = [ + device + for device in config_entry.data[CONF_DEVICES] + if tuple(device[CONF_ADDRESS]) != address + ] + data = {**config_entry.data, CONF_DEVICES: [*device_configs, device_config]} - # update device_entry await async_update_device_config(device_connection, device_config) - hass.config_entries.async_update_entry(config_entry, data=data)