From 5df0e82c372362a310b332720e63e47e8284ab01 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 7 Oct 2022 14:42:28 +1300 Subject: [PATCH 1/4] Add network type to mdns service message (#3880) --- esphome/components/mdns/mdns_component.cpp | 6 ++++++ esphome/dashboard/dashboard.py | 1 + esphome/zeroconf.py | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/esphome/components/mdns/mdns_component.cpp b/esphome/components/mdns/mdns_component.cpp index 31858c0d3c..e1fcf320ed 100644 --- a/esphome/components/mdns/mdns_component.cpp +++ b/esphome/components/mdns/mdns_component.cpp @@ -45,6 +45,12 @@ void MDNSComponent::compile_records_() { service.txt_records.push_back({"board", ESPHOME_BOARD}); +#if defined(USE_WIFI) + service.txt_records.push_back({"network", "wifi"}); +#elif defined(USE_ETHERNET) + service.txt_records.push_back({"network", "ethernet"}); +#endif + #ifdef ESPHOME_PROJECT_NAME service.txt_records.push_back({"project_name", ESPHOME_PROJECT_NAME}); service.txt_records.push_back({"project_version", ESPHOME_PROJECT_VERSION}); diff --git a/esphome/dashboard/dashboard.py b/esphome/dashboard/dashboard.py index 9a8f072237..c812ec4b49 100644 --- a/esphome/dashboard/dashboard.py +++ b/esphome/dashboard/dashboard.py @@ -613,6 +613,7 @@ class ListDevicesHandler(BaseHandler): "package_import_url": res.package_import_url, "project_name": res.project_name, "project_version": res.project_version, + "network": res.network, } for res in IMPORT_RESULT.values() if res.device_name not in configured diff --git a/esphome/zeroconf.py b/esphome/zeroconf.py index 1fbdf7e93f..089ae4f1c2 100644 --- a/esphome/zeroconf.py +++ b/esphome/zeroconf.py @@ -118,6 +118,7 @@ ESPHOME_SERVICE_TYPE = "_esphomelib._tcp.local." TXT_RECORD_PACKAGE_IMPORT_URL = b"package_import_url" TXT_RECORD_PROJECT_NAME = b"project_name" TXT_RECORD_PROJECT_VERSION = b"project_version" +TXT_RECORD_NETWORK = b"network" @dataclass @@ -126,6 +127,7 @@ class DiscoveredImport: package_import_url: str project_name: str project_version: str + network: str class DashboardImportDiscovery: @@ -134,7 +136,7 @@ class DashboardImportDiscovery: self.service_browser = ServiceBrowser( self.zc, ESPHOME_SERVICE_TYPE, [self._on_update] ) - self.import_state = {} + self.import_state: dict[str, DiscoveredImport] = {} def _on_update( self, @@ -171,12 +173,14 @@ class DashboardImportDiscovery: import_url = info.properties[TXT_RECORD_PACKAGE_IMPORT_URL].decode() project_name = info.properties[TXT_RECORD_PROJECT_NAME].decode() project_version = info.properties[TXT_RECORD_PROJECT_VERSION].decode() + network = info.properties.get(TXT_RECORD_NETWORK, b"wifi").decode() self.import_state[name] = DiscoveredImport( device_name=node_name, package_import_url=import_url, project_name=project_name, project_version=project_version, + network=network, ) def cancel(self) -> None: From 5e96b8ef7c903d5c4a15a1e66384e0c7ff8dfa0f Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 7 Oct 2022 15:20:13 +1300 Subject: [PATCH 2/4] Bump esphome-dashboard to 20221007.0 (#3881) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7f86acdbef..00e6e0ba67 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ pyserial==3.5 platformio==6.0.2 # When updating platformio, also update Dockerfile esptool==3.3.1 click==8.1.3 -esphome-dashboard==20220925.0 +esphome-dashboard==20221007.0 aioesphomeapi==10.13.0 zeroconf==0.39.1 From 3b83f967e4859ae800ff9448cc47034ef045a011 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 7 Oct 2022 15:35:48 +1300 Subject: [PATCH 3/4] Dont add wifi block to yaml if discovered device uses ethernet (#3882) --- esphome/components/dashboard_import/__init__.py | 15 ++++++++++----- esphome/dashboard/dashboard.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) 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) From 3c320c4c836c4611ac8171b0b69be3cdbfc40ee0 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 7 Oct 2022 16:34:39 +1300 Subject: [PATCH 4/4] Bump version to 2022.9.4 --- esphome/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/const.py b/esphome/const.py index ff59f2b8bf..e93808e6d4 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -1,6 +1,6 @@ """Constants used by esphome.""" -__version__ = "2022.9.3" +__version__ = "2022.9.4" ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"