Exemple #1
0
def upload_program(config, args, host):
    # if upload is to a serial port use platformio, otherwise assume ota
    if get_port_type(host) == 'SERIAL':
        if CORE.is_esp8266:
            return upload_using_esptool(config, host)
        return platformio_api.run_upload(config, args.verbose, host)

    from esphome.components import ota
    from esphome import espota2

    if args.host_port is not None:
        host_port = args.host_port
    else:
        host_port = int(
            os.getenv('ESPHOME_OTA_HOST_PORT', random.randint(10000, 60000)))

    verbose = args.verbose
    remote_port = ota.get_port(config)
    password = ota.get_auth(config)

    storage = StorageJSON.load(storage_path())
    res = espota2.run_ota(host, remote_port, password, CORE.firmware_bin)
    if res == 0:
        if storage is not None and storage.use_legacy_ota:
            storage.use_legacy_ota = False
            storage.save(storage_path())
        return res
    if storage is not None and not storage.use_legacy_ota:
        return res

    _LOGGER.warning("OTA v2 method failed. Trying with legacy OTA...")
    return espota2.run_legacy_ota(verbose, host_port, host, remote_port,
                                  password, CORE.firmware_bin)
Exemple #2
0
def update_storage_json():
    path = storage_path()
    old = StorageJSON.load(path)
    new = StorageJSON.from_esphome_core(CORE, old)
    if old == new:
        return

    if storage_should_clean(old, new):
        _LOGGER.info("Core config or version changed, cleaning build files...")
        clean_build()

    new.save(path)