Second part of one_device_only big merge
This commit is contained in:
@@ -13,7 +13,6 @@ from homeassistant.const import (
|
||||
CONF_DEVICE_ID,
|
||||
CONF_FRIENDLY_NAME,
|
||||
CONF_PLATFORM,
|
||||
CONF_SWITCHES,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
@@ -97,7 +96,6 @@ def schema_defaults(schema, dps_list=None, **defaults):
|
||||
|
||||
if field.schema in defaults:
|
||||
field.default = vol.default_factory(defaults[field])
|
||||
|
||||
return copy
|
||||
|
||||
|
||||
@@ -310,37 +308,21 @@ class LocaltuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle import from YAML."""
|
||||
|
||||
def _convert_entity(conf):
|
||||
converted = {
|
||||
CONF_ID: conf[CONF_ID],
|
||||
CONF_FRIENDLY_NAME: conf[CONF_FRIENDLY_NAME],
|
||||
CONF_PLATFORM: self.platform,
|
||||
}
|
||||
for field in flow_schema(self.platform, self.dps_strings).keys():
|
||||
converted[str(field)] = conf[field]
|
||||
return converted
|
||||
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])
|
||||
self.platform = user_input[CONF_PLATFORM]
|
||||
|
||||
if len(user_input.get(CONF_SWITCHES, [])) > 0:
|
||||
for switch_conf in user_input[CONF_SWITCHES].values():
|
||||
self.entities.append(_convert_entity(switch_conf))
|
||||
else:
|
||||
self.entities.append(_convert_entity(user_input))
|
||||
for entity_conf in user_input[CONF_ENTITIES]:
|
||||
entity_conf[CONF_ID] = str(entity_conf[CONF_ID])
|
||||
_convert_entity(entity_conf)
|
||||
|
||||
# print('ENTITIES: [{}] '.format(self.entities))
|
||||
config = {
|
||||
CONF_FRIENDLY_NAME: f"{user_input[CONF_FRIENDLY_NAME]}",
|
||||
CONF_HOST: user_input[CONF_HOST],
|
||||
CONF_DEVICE_ID: user_input[CONF_DEVICE_ID],
|
||||
CONF_LOCAL_KEY: user_input[CONF_LOCAL_KEY],
|
||||
CONF_PROTOCOL_VERSION: user_input[CONF_PROTOCOL_VERSION],
|
||||
CONF_YAML_IMPORT: True,
|
||||
CONF_ENTITIES: self.entities,
|
||||
}
|
||||
self._abort_if_unique_id_configured(updates=config)
|
||||
user_input[CONF_YAML_IMPORT] = True
|
||||
|
||||
self._abort_if_unique_id_configured(updates=user_input)
|
||||
return self.async_create_entry(
|
||||
title=f"{config[CONF_FRIENDLY_NAME]} (YAML)", data=config
|
||||
title=f"{user_input[CONF_FRIENDLY_NAME]} (YAML)", data=user_input
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user