diff --git a/esphome/components/dashboard_import/__init__.py b/esphome/components/dashboard_import/__init__.py index 41b4a8bed1..b795c85b12 100644 --- a/esphome/components/dashboard_import/__init__.py +++ b/esphome/components/dashboard_import/__init__.py @@ -3,6 +3,7 @@ from pathlib import Path import esphome.codegen as cg import esphome.config_validation as cv from esphome.components.packages import validate_source_shorthand +from esphome.const import CONF_WIFI from esphome.wizard import wizard_file from esphome.yaml_util import dump @@ -43,7 +44,9 @@ async def to_code(config): cg.add(dashboard_import_ns.set_package_import_url(config[CONF_PACKAGE_IMPORT_URL])) -def import_config(path: str, name: str, project_name: str, import_url: str) -> None: +def import_config( + path: str, name: str, project_name: str, import_url: str, network: str = CONF_WIFI +) -> None: p = Path(path) if p.exists(): @@ -69,7 +72,9 @@ def import_config(path: str, name: str, project_name: str, import_url: str) -> N "name_add_mac_suffix": False, }, } - p.write_text( - dump(config) + WIFI_CONFIG, - encoding="utf8", - ) + output = dump(config) + + if network == CONF_WIFI: + output += WIFI_CONFIG + + p.write_text(output, encoding="utf8") diff --git a/esphome/dashboard/dashboard.py b/esphome/dashboard/dashboard.py index c812ec4b49..07ee151949 100644 --- a/esphome/dashboard/dashboard.py +++ b/esphome/dashboard/dashboard.py @@ -395,11 +395,22 @@ class ImportRequestHandler(BaseHandler): args = json.loads(self.request.body.decode()) try: name = args["name"] + + imported_device = next( + (res for res in IMPORT_RESULT.values() if res.device_name == name), None + ) + + if imported_device is not None: + network = imported_device.network + else: + network = const.CONF_WIFI + import_config( settings.rel_path(f"{name}.yaml"), name, args["project_name"], args["package_import_url"], + network, ) except FileExistsError: self.set_status(500)