1
0
mirror of https://github.com/esphome/esphome.git synced 2024-10-06 02:40:56 +01:00

Dont add wifi block to yaml if discovered device uses ethernet (#3882)

This commit is contained in:
Jesse Hills 2022-10-07 15:35:48 +13:00
parent 5e96b8ef7c
commit 3b83f967e4
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
2 changed files with 21 additions and 5 deletions

View File

@ -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")

View File

@ -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)