Store DPS as integers in config entry
Also require protocol_version to be a string and validate version to be supported.
This commit is contained in:
committed by
rospogrigio
parent
3259a4f654
commit
63090ba985
@@ -54,7 +54,7 @@ class TuyaDevice:
|
|||||||
config_entry[CONF_DEVICE_ID],
|
config_entry[CONF_DEVICE_ID],
|
||||||
config_entry[CONF_HOST],
|
config_entry[CONF_HOST],
|
||||||
config_entry[CONF_LOCAL_KEY],
|
config_entry[CONF_LOCAL_KEY],
|
||||||
config_entry[CONF_PROTOCOL_VERSION],
|
float(config_entry[CONF_PROTOCOL_VERSION]),
|
||||||
)
|
)
|
||||||
for entity in config_entry[CONF_ENTITIES]:
|
for entity in config_entry[CONF_ENTITIES]:
|
||||||
# this has to be done in case the device type is type_0d
|
# this has to be done in case the device type is type_0d
|
||||||
|
@@ -62,7 +62,7 @@ DEVICE_SCHEMA = vol.Schema(
|
|||||||
vol.Required(CONF_DEVICE_ID): cv.string,
|
vol.Required(CONF_DEVICE_ID): cv.string,
|
||||||
vol.Required(CONF_LOCAL_KEY): cv.string,
|
vol.Required(CONF_LOCAL_KEY): cv.string,
|
||||||
vol.Required(CONF_FRIENDLY_NAME): 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 = {}
|
stripped = {}
|
||||||
for field, value in user_input.items():
|
for field, value in user_input.items():
|
||||||
if value in dps_strings:
|
if value in dps_strings:
|
||||||
stripped[field] = user_input[field].split(" ")[0]
|
stripped[field] = int(user_input[field].split(" ")[0])
|
||||||
else:
|
else:
|
||||||
stripped[field] = user_input[field]
|
stripped[field] = user_input[field]
|
||||||
return stripped
|
return stripped
|
||||||
@@ -306,18 +306,8 @@ class LocaltuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_import(self, user_input):
|
async def async_step_import(self, user_input):
|
||||||
"""Handle import from YAML."""
|
"""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])
|
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
|
user_input[CONF_YAML_IMPORT] = True
|
||||||
|
|
||||||
self._abort_if_unique_id_configured(updates=user_input)
|
self._abort_if_unique_id_configured(updates=user_input)
|
||||||
|
Reference in New Issue
Block a user