From 1776540757544981ddb3457a6166681777c3a163 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Sat, 25 Jul 2020 19:13:10 +0200 Subject: [PATCH] Rfxtrx fixup config entry creation (#38185) * Make sure import flow completely replace existing config * Make sure added device contain correct config data * Revert change to directly run init --- homeassistant/components/rfxtrx/__init__.py | 7 +++++-- homeassistant/components/rfxtrx/config_flow.py | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index 3bb8a753aa9..b1b196dbfba 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -280,11 +280,14 @@ async def async_setup_internal(hass, entry: config_entries.ConfigEntry): @callback def _add_device(event, device_id): """Add a device to config entry.""" + config = DEVICE_DATA_SCHEMA({}) + config[CONF_DEVICE_ID] = device_id + data = entry.data.copy() event_code = binascii.hexlify(event.data).decode("ASCII") - data[CONF_DEVICES][event_code] = device_id + data[CONF_DEVICES][event_code] = config hass.config_entries.async_update_entry(entry=entry, data=data) - devices[device_id] = {} + devices[device_id] = config @callback def _start_rfxtrx(event): diff --git a/homeassistant/components/rfxtrx/config_flow.py b/homeassistant/components/rfxtrx/config_flow.py index 0cdaa8146ec..287e1ec4baf 100644 --- a/homeassistant/components/rfxtrx/config_flow.py +++ b/homeassistant/components/rfxtrx/config_flow.py @@ -16,6 +16,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_import(self, import_config=None): """Handle the initial step.""" - await self.async_set_unique_id(DOMAIN) - self._abort_if_unique_id_configured(import_config) + entry = await self.async_set_unique_id(DOMAIN) + if entry and import_config.items() != entry.data.items(): + self.hass.config_entries.async_update_entry(entry, data=import_config) + return self.async_abort(reason="already_configured") return self.async_create_entry(title="RFXTRX", data=import_config)