mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
commit
e8de6a3a67
6 changed files with 35 additions and 8 deletions
|
@ -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")
|
||||
|
|
|
@ -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});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Constants used by esphome."""
|
||||
|
||||
__version__ = "2022.9.3"
|
||||
__version__ = "2022.9.4"
|
||||
|
||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
@ -613,6 +624,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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue