diff --git a/custom_components/localtuya/config_flow.py b/custom_components/localtuya/config_flow.py index ca0cfd7b1..65f74e95a 100644 --- a/custom_components/localtuya/config_flow.py +++ b/custom_components/localtuya/config_flow.py @@ -30,6 +30,7 @@ _LOGGER = logging.getLogger(__name__) PLATFORM_TO_ADD = "platform_to_add" +SUGGEST_DPS = "suggest_dps" NO_ADDITIONAL_PLATFORMS = "no_additional_platforms" DISCOVERED_DEVICE = "discovered_device" @@ -65,7 +66,10 @@ ) PICK_ENTITY_SCHEMA = vol.Schema( - {vol.Required(PLATFORM_TO_ADD, default=PLATFORMS[0]): vol.In(PLATFORMS)} + { + vol.Required(PLATFORM_TO_ADD, default=PLATFORMS[0]): vol.In(PLATFORMS), + vol.Required(SUGGEST_DPS, default=True): bool, + } ) @@ -107,7 +111,9 @@ def gen_dps_strings(): return [f"{dp} (value: ?)" for dp in range(1, 256)] -def platform_schema(platform, dps_strings, allow_id=True, yaml=False, dps_in_use=None): +def platform_schema( + platform, dps_strings, allow_id=True, yaml=False, dps_in_use=None, suggest_dps=False +): """Generate input validation schema for a platform.""" schema = {} if yaml: @@ -124,9 +130,11 @@ def platform_schema(platform, dps_strings, allow_id=True, yaml=False, dps_in_use if yaml: return vol.Schema(schema) - return schema_defaults( - vol.Schema(schema), dps_strings, **suggest(platform, dps_strings, dps_in_use) - ) + suggestions = {} + if suggest_dps: + suggestions = suggest(platform, dps_strings, dps_in_use) + + return schema_defaults(vol.Schema(schema), dps_strings, **suggestions) def strip_dps_values(user_input, dps_strings): @@ -203,6 +211,7 @@ def __init__(self): self.basic_info = None self.dps_strings = [] self.platform = None + self.suggest_dps = None self.devices = {} self.selected_device = None self.entities = [] @@ -281,6 +290,7 @@ async def async_step_pick_entity_type(self, user_input=None): ) self.platform = user_input[PLATFORM_TO_ADD] + self.suggest_dps = user_input[SUGGEST_DPS] return await self.async_step_add_entity() # Add a checkbox that allows bailing out from config flow iff at least one @@ -310,7 +320,10 @@ async def async_step_add_entity(self, user_input=None): return self.async_show_form( step_id="add_entity", data_schema=platform_schema( - self.platform, self.dps_strings, dps_in_use=self.async_dps_in_use() + self.platform, + self.dps_strings, + dps_in_use=self.async_dps_in_use(), + suggest_dps=self.suggest_dps, ), errors=errors, description_placeholders={"platform": self.platform}, diff --git a/custom_components/localtuya/translations/en.json b/custom_components/localtuya/translations/en.json index 9e87bf2dc..870cf3de5 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -33,6 +33,7 @@ "description": "Please pick the type of entity you want to add.", "data": { "platform_to_add": "Platform", + "suggest_dps": "Suggest platform configuration", "no_additional_platforms": "Do not add any more entities" } },