Просмотр исходного кода

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 4 лет назад
Родитель
Сommit
bde904f9c9
1 измененных файлов с 4 добавлено и 4 удалено
  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),