Add network type to mdns service message (#3880)

This commit is contained in:
Jesse Hills 2022-10-07 14:42:28 +13:00 committed by GitHub
parent 7171286c3c
commit 01b7c4200e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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}); 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 #ifdef ESPHOME_PROJECT_NAME
service.txt_records.push_back({"project_name", ESPHOME_PROJECT_NAME}); service.txt_records.push_back({"project_name", ESPHOME_PROJECT_NAME});
service.txt_records.push_back({"project_version", ESPHOME_PROJECT_VERSION}); 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, "package_import_url": res.package_import_url,
"project_name": res.project_name, "project_name": res.project_name,
"project_version": res.project_version, "project_version": res.project_version,
"network": res.network,
} }
for res in IMPORT_RESULT.values() for res in IMPORT_RESULT.values()
if res.device_name not in configured 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_PACKAGE_IMPORT_URL = b"package_import_url"
TXT_RECORD_PROJECT_NAME = b"project_name" TXT_RECORD_PROJECT_NAME = b"project_name"
TXT_RECORD_PROJECT_VERSION = b"project_version" TXT_RECORD_PROJECT_VERSION = b"project_version"
TXT_RECORD_NETWORK = b"network"
@dataclass @dataclass
@ -126,6 +127,7 @@ class DiscoveredImport:
package_import_url: str package_import_url: str
project_name: str project_name: str
project_version: str project_version: str
network: str
class DashboardImportDiscovery: class DashboardImportDiscovery:
@ -134,7 +136,7 @@ class DashboardImportDiscovery:
self.service_browser = ServiceBrowser( self.service_browser = ServiceBrowser(
self.zc, ESPHOME_SERVICE_TYPE, [self._on_update] self.zc, ESPHOME_SERVICE_TYPE, [self._on_update]
) )
self.import_state = {} self.import_state: dict[str, DiscoveredImport] = {}
def _on_update( def _on_update(
self, self,
@ -171,12 +173,14 @@ class DashboardImportDiscovery:
import_url = info.properties[TXT_RECORD_PACKAGE_IMPORT_URL].decode() import_url = info.properties[TXT_RECORD_PACKAGE_IMPORT_URL].decode()
project_name = info.properties[TXT_RECORD_PROJECT_NAME].decode() project_name = info.properties[TXT_RECORD_PROJECT_NAME].decode()
project_version = info.properties[TXT_RECORD_PROJECT_VERSION].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( self.import_state[name] = DiscoveredImport(
device_name=node_name, device_name=node_name,
package_import_url=import_url, package_import_url=import_url,
project_name=project_name, project_name=project_name,
project_version=project_version, project_version=project_version,
network=network,
) )
def cancel(self) -> None: def cancel(self) -> None: