From 266e4f0c8bbdd9dbb1252168a21b44a98dec0680 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 8 Apr 2024 08:29:27 -1000 Subject: [PATCH] Migrate rfxtrx to use run_immediately=True for the device registry listener (#115165) --- homeassistant/components/rfxtrx/__init__.py | 2 +- homeassistant/components/rfxtrx/config_flow.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index b40e8d921ed..78b7daa8347 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -281,7 +281,7 @@ async def async_setup_internal(hass: HomeAssistant, entry: ConfigEntry) -> None: entry.async_on_unload( hass.bus.async_listen( - dr.EVENT_DEVICE_REGISTRY_UPDATED, _updated_device, run_immediately=False + dr.EVENT_DEVICE_REGISTRY_UPDATED, _updated_device, run_immediately=True ) ) diff --git a/homeassistant/components/rfxtrx/config_flow.py b/homeassistant/components/rfxtrx/config_flow.py index 837ca554615..c1b52962f32 100644 --- a/homeassistant/components/rfxtrx/config_flow.py +++ b/homeassistant/components/rfxtrx/config_flow.py @@ -486,7 +486,10 @@ class RfxtrxOptionsFlow(OptionsFlow): if devices: for event_code, options in devices.items(): if options is None: - entry_data[CONF_DEVICES].pop(event_code) + # If the config entry is setup, the device registry + # listener will remove the device from the config + # entry before we get here + entry_data[CONF_DEVICES].pop(event_code, None) else: entry_data[CONF_DEVICES][event_code] = options self.hass.config_entries.async_update_entry(self._config_entry, data=entry_data)