def update_storage_json(): path = storage_path() old = StorageJSON.load(path) new = StorageJSON.from_esphomeyaml_core(CORE, old) if old == new: return old_src_version = old.src_version if old is not None else 0 migrate_src_version(old_src_version, new.src_version) if storage_should_clean(old, new): _LOGGER.info("Core config or version changed, cleaning build files...") clean_build() new.save(path)
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 esphomeyaml.components import ota from esphomeyaml import espota2 if args.host_port is not None: host_port = args.host_port else: host_port = int( os.getenv('ESPHOMEYAML_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)
def wizard_write(path, **kwargs): name = kwargs['name'] board = kwargs['board'] if 'platform' not in kwargs: kwargs[ 'platform'] = 'ESP8266' if board in ESP8266_BOARD_PINS else 'ESP32' platform = kwargs['platform'] with codecs.open(path, 'w') as f_handle: f_handle.write(wizard_file(**kwargs)) storage = StorageJSON.from_wizard(name, name + '.local', platform, board) storage_path = ext_storage_path(os.path.dirname(path), os.path.basename(path)) storage.save(storage_path)
def get(self): if not self.is_authenticated(): self.redirect('/login') return configuration = self.get_argument('configuration') storage_path = ext_storage_path(CONFIG_DIR, configuration) storage_json = StorageJSON.load(storage_path) if storage_json is None: self.send_error() return path = storage_json.firmware_bin_path self.set_header('Content-Type', 'application/octet-stream') filename = '{}.bin'.format(storage_json.name) self.set_header("Content-Disposition", 'attachment; filename="{}"'.format(filename)) with open(path, 'rb') as f: while 1: data = f.read(16384) # or some other nice-sized chunk if not data: break self.write(data) self.finish()
def storage(self): # type: () -> Optional[StorageJSON] if not self._loaded_storage: self._storage = StorageJSON.load( ext_storage_path(CONFIG_DIR, self.filename)) self._loaded_storage = True return self._storage