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

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 лет назад
Родитель
Сommit
0ba3421495

+ 13 - 5
custom_components/tuya_local/config_flow.py

@@ -92,20 +92,28 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
         """Manage the options."""
         errors = {}
         config = {**self.config_entry.data, **self.config_entry.options}
+        device = await async_test_connection(config, self.hass)
 
         if user_input is not None:
             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)
             else:
                 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(
             step_id="user",
-            data_schema=vol.Schema(
-                individual_config_schema(defaults=config, options_only=True)
-            ),
+            data_schema=vol.Schema(schema),
             errors=errors,
         )
 

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

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