1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-13 08:42:18 +01:00

[core] Fix serial upload regression from DNS resolution PR #10595 (#10648)

This commit is contained in:
J. Nick Koston
2025-09-08 10:41:03 -05:00
committed by GitHub
parent e5bba00deb
commit 75c9430d91
2 changed files with 22 additions and 30 deletions

View File

@@ -398,28 +398,27 @@ def check_permissions(port: str):
def upload_program( def upload_program(
config: ConfigType, args: ArgsProtocol, devices: list[str] config: ConfigType, args: ArgsProtocol, devices: list[str]
) -> int | str: ) -> tuple[int, str | None]:
host = devices[0] host = devices[0]
try: try:
module = importlib.import_module("esphome.components." + CORE.target_platform) module = importlib.import_module("esphome.components." + CORE.target_platform)
if getattr(module, "upload_program")(config, args, host): if getattr(module, "upload_program")(config, args, host):
return 0 return 0, host
except AttributeError: except AttributeError:
pass pass
if get_port_type(host) == "SERIAL": if get_port_type(host) == "SERIAL":
check_permissions(host) check_permissions(host)
exit_code = 1
if CORE.target_platform in (PLATFORM_ESP32, PLATFORM_ESP8266): if CORE.target_platform in (PLATFORM_ESP32, PLATFORM_ESP8266):
file = getattr(args, "file", None) file = getattr(args, "file", None)
return upload_using_esptool(config, host, file, args.upload_speed) exit_code = upload_using_esptool(config, host, file, args.upload_speed)
elif CORE.target_platform == PLATFORM_RP2040 or CORE.is_libretiny:
exit_code = upload_using_platformio(config, host)
# else: Unknown target platform, exit_code remains 1
if CORE.target_platform in (PLATFORM_RP2040): return exit_code, host if exit_code == 0 else None
return upload_using_platformio(config, host)
if CORE.is_libretiny:
return upload_using_platformio(config, host)
return 1 # Unknown target platform
ota_conf = {} ota_conf = {}
for ota_item in config.get(CONF_OTA, []): for ota_item in config.get(CONF_OTA, []):
@@ -553,7 +552,7 @@ def command_upload(args: ArgsProtocol, config: ConfigType) -> int | None:
purpose="uploading", purpose="uploading",
) )
exit_code = upload_program(config, args, devices) exit_code, _ = upload_program(config, args, devices)
if exit_code == 0: if exit_code == 0:
_LOGGER.info("Successfully uploaded program.") _LOGGER.info("Successfully uploaded program.")
else: else:
@@ -610,19 +609,11 @@ def command_run(args: ArgsProtocol, config: ConfigType) -> int | None:
purpose="uploading", purpose="uploading",
) )
# Try each device for upload until one succeeds exit_code, successful_device = upload_program(config, args, devices)
successful_device: str | None = None if exit_code == 0:
for device in devices: _LOGGER.info("Successfully uploaded program.")
_LOGGER.info("Uploading to %s", device) else:
exit_code = upload_program(config, args, device) _LOGGER.warning("Failed to upload to %s", devices)
if exit_code == 0:
_LOGGER.info("Successfully uploaded program.")
successful_device = device
break
if len(devices) > 1:
_LOGGER.warning("Failed to upload to %s", device)
if successful_device is None:
return exit_code return exit_code
if args.no_logs: if args.no_logs:

View File

@@ -310,7 +310,7 @@ def perform_ota(
def run_ota_impl_( def run_ota_impl_(
remote_host: str | list[str], remote_port: int, password: str, filename: str remote_host: str | list[str], remote_port: int, password: str, filename: str
) -> int: ) -> tuple[int, str | None]:
# Handle both single host and list of hosts # Handle both single host and list of hosts
try: try:
# Resolve all hosts at once for parallel DNS resolution # Resolve all hosts at once for parallel DNS resolution
@@ -344,21 +344,22 @@ def run_ota_impl_(
perform_ota(sock, password, file_handle, filename) perform_ota(sock, password, file_handle, filename)
except OTAError as err: except OTAError as err:
_LOGGER.error(str(err)) _LOGGER.error(str(err))
return 1 return 1, None
finally: finally:
sock.close() sock.close()
return 0 # Successfully uploaded to sa[0]
return 0, sa[0]
_LOGGER.error("Connection failed.") _LOGGER.error("Connection failed.")
return 1 return 1, None
def run_ota( def run_ota(
remote_host: str | list[str], remote_port: int, password: str, filename: str remote_host: str | list[str], remote_port: int, password: str, filename: str
) -> int: ) -> tuple[int, str | None]:
try: try:
return run_ota_impl_(remote_host, remote_port, password, filename) return run_ota_impl_(remote_host, remote_port, password, filename)
except OTAError as err: except OTAError as err:
_LOGGER.error(err) _LOGGER.error(err)
return 1 return 1, None