Add network type to mdns service message (#3880)

This commit is contained in:
Jesse Hills 2022-10-07 14:42:28 +13:00
parent 2d58239b74
commit 5df0e82c37
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A
3 changed files with 12 additions and 1 deletions

View file

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

View file

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

View file

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