From 72f29b1283b925da3177bacd4b60ec0446291e81 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 7 Sep 2023 10:15:54 +1200 Subject: [PATCH] Allow upload command to flash file via serial (#5274) --- esphome/__main__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/esphome/__main__.py b/esphome/__main__.py index 9b208c2280..9fac8cd605 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -218,14 +218,16 @@ def compile_program(args, config): return 0 if idedata is not None else 1 -def upload_using_esptool(config, port): +def upload_using_esptool(config, port, file): from esphome import platformio_api first_baudrate = config[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS].get( "upload_speed", 460800 ) - def run_esptool(baud_rate): + if file is not None: + flash_images = [platformio_api.FlashImage(path=file, offset="0x0")] + else: idedata = platformio_api.get_idedata(config) firmware_offset = "0x10000" if CORE.is_esp32 else "0x0" @@ -236,12 +238,13 @@ def upload_using_esptool(config, port): *idedata.extra_flash_images, ] - mcu = "esp8266" - if CORE.is_esp32: - from esphome.components.esp32 import get_esp32_variant + mcu = "esp8266" + if CORE.is_esp32: + from esphome.components.esp32 import get_esp32_variant - mcu = get_esp32_variant().lower() + mcu = get_esp32_variant().lower() + def run_esptool(baud_rate): cmd = [ "esptool.py", "--before", @@ -292,7 +295,8 @@ def upload_using_platformio(config, port): def upload_program(config, args, host): if get_port_type(host) == "SERIAL": if CORE.target_platform in (PLATFORM_ESP32, PLATFORM_ESP8266): - return upload_using_esptool(config, host) + file = getattr(args, "file", None) + return upload_using_esptool(config, host, file) if CORE.target_platform in (PLATFORM_RP2040): return upload_using_platformio(config, args.device)