Procházet zdrojové kódy

Default options form values from existing config.

Options schema was copied from the relevant parts of the initial config schema,
which meant that the defaults were missing for some options, and set based on
default assumptions for others.  Default them to the existing values, which
is more useful for reconfiguring existing devices.
Jason Rumney před 4 roky
rodič
revize
bde904f9c9
1 změnil soubory, kde provedl 4 přidání a 4 odebrání
  1. 4 4
      custom_components/tuya_local/config_flow.py

+ 4 - 4
custom_components/tuya_local/config_flow.py

@@ -115,16 +115,16 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
                 errors["base"] = "connection"
 
         schema = {
-            vol.Required(CONF_LOCAL_KEY): str,
-            vol.Required(CONF_HOST): str,
+            vol.Required(CONF_LOCAL_KEY, default=config.get(CONF_LOCAL_KEY, "")): str,
+            vol.Required(CONF_HOST, default=config.get(CONF_HOST, "")): str,
         }
         cfg = config_for_legacy_use(config[CONF_TYPE])
         if cfg is None:
             return self.async_abort(reason="not_supported")
         e = cfg.primary_entity
-        schema[vol.Optional(e.entity, default=True)] = bool
+        schema[vol.Optional(e.entity, default=config.get(e.entity, True))] = bool
         for e in cfg.secondary_entities():
-            schema[vol.Optional(e.entity, default=not e.deprecated)] = bool
+            schema[vol.Optional(e.entity, default=config.get(e.entity, False))] = bool
         return self.async_show_form(
             step_id="user",
             data_schema=vol.Schema(schema),