Sfoglia il codice sorgente

Always persist username; only save password on successful auth

ZiB 4 mesi fa
parent
commit
c940b9f6d2
1 ha cambiato i file con 5 aggiunte e 5 eliminazioni
  1. 5 5
      custom_components/room_cal_ha/config_flow.py

+ 5 - 5
custom_components/room_cal_ha/config_flow.py

@@ -102,12 +102,14 @@ class RoomCalOptionsFlow(OptionsFlow):
       self._username = user_input.pop(CONF_USERNAME, "") or self.config_entry.data.get(CONF_USERNAME, "")
       self._username = user_input.pop(CONF_USERNAME, "") or self.config_entry.data.get(CONF_USERNAME, "")
       password = user_input.pop(CONF_PASSWORD, "") or self.config_entry.data.get(CONF_PASSWORD, "")
       password = user_input.pop(CONF_PASSWORD, "") or self.config_entry.data.get(CONF_PASSWORD, "")
 
 
+      new_data = {**self.config_entry.data, CONF_USERNAME: self._username}
+
       if user_input.get(CONF_CALDAV_ENABLED) and user_input.get(CONF_CALDAV_URL):
       if user_input.get(CONF_CALDAV_ENABLED) and user_input.get(CONF_CALDAV_URL):
         try:
         try:
           await self.hass.async_add_executor_job(
           await self.hass.async_add_executor_job(
             _test_caldav_auth,
             _test_caldav_auth,
             user_input[CONF_CALDAV_URL],
             user_input[CONF_CALDAV_URL],
-            username,
+            self._username,
             password,
             password,
           )
           )
         except caldav_error.AuthorizationError:
         except caldav_error.AuthorizationError:
@@ -115,11 +117,9 @@ class RoomCalOptionsFlow(OptionsFlow):
         except Exception:
         except Exception:
           errors["base"] = "cannot_connect"
           errors["base"] = "cannot_connect"
         else:
         else:
-          await self.hass.config_entries.async_update_entry(
-            self.config_entry,
-            data={**self.config_entry.data, CONF_USERNAME: username, CONF_PASSWORD: password},
-          )
+          new_data[CONF_PASSWORD] = password
 
 
+      await self.hass.config_entries.async_update_entry(self.config_entry, data=new_data)
       merged = {**self.config_entry.options, **user_input}
       merged = {**self.config_entry.options, **user_input}
       return self.async_create_entry(data=merged)
       return self.async_create_entry(data=merged)