mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 00:48:19 +01:00
Dont add wifi block to yaml if discovered device uses ethernet (#3882)
This commit is contained in:
parent
6087183a0c
commit
fd57b21aff
2 changed files with 21 additions and 5 deletions
|
@ -3,6 +3,7 @@ from pathlib import Path
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components.packages import validate_source_shorthand
|
from esphome.components.packages import validate_source_shorthand
|
||||||
|
from esphome.const import CONF_WIFI
|
||||||
from esphome.wizard import wizard_file
|
from esphome.wizard import wizard_file
|
||||||
from esphome.yaml_util import dump
|
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]))
|
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)
|
p = Path(path)
|
||||||
|
|
||||||
if p.exists():
|
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,
|
"name_add_mac_suffix": False,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
p.write_text(
|
output = dump(config)
|
||||||
dump(config) + WIFI_CONFIG,
|
|
||||||
encoding="utf8",
|
if network == CONF_WIFI:
|
||||||
)
|
output += WIFI_CONFIG
|
||||||
|
|
||||||
|
p.write_text(output, encoding="utf8")
|
||||||
|
|
|
@ -395,11 +395,22 @@ class ImportRequestHandler(BaseHandler):
|
||||||
args = json.loads(self.request.body.decode())
|
args = json.loads(self.request.body.decode())
|
||||||
try:
|
try:
|
||||||
name = args["name"]
|
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(
|
import_config(
|
||||||
settings.rel_path(f"{name}.yaml"),
|
settings.rel_path(f"{name}.yaml"),
|
||||||
name,
|
name,
|
||||||
args["project_name"],
|
args["project_name"],
|
||||||
args["package_import_url"],
|
args["package_import_url"],
|
||||||
|
network,
|
||||||
)
|
)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
self.set_status(500)
|
self.set_status(500)
|
||||||
|
|
Loading…
Reference in a new issue