Explorar el Código

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 hace 4 años
padre
commit
bde904f9c9
Se han modificado 1 ficheros con 4 adiciones y 4 borrados
  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"
                 errors["base"] = "connection"
 
 
         schema = {
         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])
         cfg = config_for_legacy_use(config[CONF_TYPE])
         if cfg is None:
         if cfg is None:
             return self.async_abort(reason="not_supported")
             return self.async_abort(reason="not_supported")
         e = cfg.primary_entity
         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():
         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(
         return self.async_show_form(
             step_id="user",
             step_id="user",
             data_schema=vol.Schema(schema),
             data_schema=vol.Schema(schema),