فهرست منبع

Update options flow

- Limit entities to those available in the configuration.
- Do not allow changing type, as that would require a multi-step flow to retain the above.

This will require devices to be deleted and reconfigured to change their type,
which isn't ideal, but it avoids an extra step that might confuse users into
thinking the second step options are not available.
Jason Rumney 4 سال پیش
والد
کامیت
0ba3421495
2فایلهای تغییر یافته به همراه13 افزوده شده و 6 حذف شده
  1. 13 5
      custom_components/tuya_local/config_flow.py
  2. 0 1
      custom_components/tuya_local/translations/en.json

+ 13 - 5
custom_components/tuya_local/config_flow.py

@@ -92,20 +92,28 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
         """Manage the options."""
         """Manage the options."""
         errors = {}
         errors = {}
         config = {**self.config_entry.data, **self.config_entry.options}
         config = {**self.config_entry.data, **self.config_entry.options}
+        device = await async_test_connection(config, self.hass)
 
 
         if user_input is not None:
         if user_input is not None:
             config = {**config, **user_input}
             config = {**config, **user_input}
-            connect_success = await async_test_connection(config, self.hass)
-            if connect_success:
+            device = await async_test_connection(config, self.hass)
+            if device:
                 return self.async_create_entry(title="", data=user_input)
                 return self.async_create_entry(title="", data=user_input)
             else:
             else:
                 errors["base"] = "connection"
                 errors["base"] = "connection"
 
 
+        schema = {
+            vol.Required(CONF_LOCAL_KEY): str,
+            vol.Required(CONF_HOST): str,
+        }
+        cfg = config_for_legacy_use(config[CONF_TYPE])
+        e = cfg.primary_entity
+        schema[vol.Optional(e.entity, default=True)] = bool
+        for e in cfg.secondary_entities():
+            schema[vol.Optional(e.entity, default=not e.deprecated)] = bool
         return self.async_show_form(
         return self.async_show_form(
             step_id="user",
             step_id="user",
-            data_schema=vol.Schema(
-                individual_config_schema(defaults=config, options_only=True)
-            ),
+            data_schema=vol.Schema(schema),
             errors=errors,
             errors=errors,
         )
         )
 
 

+ 0 - 1
custom_components/tuya_local/translations/en.json

@@ -48,7 +48,6 @@
             "data": {
             "data": {
 		"host": "IP address or hostname",
 		"host": "IP address or hostname",
 		"local_key": "Local key",
 		"local_key": "Local key",
-		"type": "Device type",
 		"humidifier": "Include a humidifier entity",
 		"humidifier": "Include a humidifier entity",
 		"fan": "Include a fan entitiy",
 		"fan": "Include a fan entitiy",
 		"climate": "Include a climate entity",
 		"climate": "Include a climate entity",