diff --git a/custom_components/localtuya/common.py b/custom_components/localtuya/common.py index 9e141eb..91bb226 100644 --- a/custom_components/localtuya/common.py +++ b/custom_components/localtuya/common.py @@ -54,7 +54,7 @@ class TuyaDevice: config_entry[CONF_DEVICE_ID], config_entry[CONF_HOST], config_entry[CONF_LOCAL_KEY], - config_entry[CONF_PROTOCOL_VERSION], + float(config_entry[CONF_PROTOCOL_VERSION]), ) for entity in config_entry[CONF_ENTITIES]: # this has to be done in case the device type is type_0d diff --git a/custom_components/localtuya/config_flow.py b/custom_components/localtuya/config_flow.py index bd73ffd..431ef87 100644 --- a/custom_components/localtuya/config_flow.py +++ b/custom_components/localtuya/config_flow.py @@ -62,7 +62,7 @@ DEVICE_SCHEMA = vol.Schema( vol.Required(CONF_DEVICE_ID): cv.string, vol.Required(CONF_LOCAL_KEY): cv.string, vol.Required(CONF_FRIENDLY_NAME): cv.string, - vol.Required(CONF_PROTOCOL_VERSION, default="3.3"): vol.Coerce(float), + vol.Required(CONF_PROTOCOL_VERSION, default="3.3"): vol.In(["3.1", "3.3"]), } ) @@ -132,7 +132,7 @@ def strip_dps_values(user_input, dps_strings): stripped = {} for field, value in user_input.items(): if value in dps_strings: - stripped[field] = user_input[field].split(" ")[0] + stripped[field] = int(user_input[field].split(" ")[0]) else: stripped[field] = user_input[field] return stripped @@ -306,18 +306,8 @@ class LocaltuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_import(self, user_input): """Handle import from YAML.""" - - def _convert_entity(conf): - for field in flow_schema(conf[CONF_PLATFORM], self.dps_strings).keys(): - if str(field) in conf: - conf[str(field)] = str(conf[field]) - await self.async_set_unique_id(user_input[CONF_DEVICE_ID]) - for entity_conf in user_input[CONF_ENTITIES]: - entity_conf[CONF_ID] = str(entity_conf[CONF_ID]) - _convert_entity(entity_conf) - user_input[CONF_YAML_IMPORT] = True self._abort_if_unique_id_configured(updates=user_input)