Initial commit
This commit is contained in:
117
create_firmware.py
Normal file
117
create_firmware.py
Normal file
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/python
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
home = str(Path.home())
|
||||
|
||||
|
||||
cwd = os.getcwd()
|
||||
|
||||
|
||||
pattern = r"name:\s*(\S+)"
|
||||
json_destination = "../website2/public/fwesp"
|
||||
firmware_destination = "../website2/public/fwesp/firmware"
|
||||
firmware_destination2 = "../esphome_uploader/firmware"
|
||||
|
||||
# Lista plików do wykluczenia z przetwarzania
|
||||
exclude_files = [
|
||||
"dimmer_gen2_can.yaml",
|
||||
"dimmer_gen2_emc.yaml",
|
||||
"dev-boneio-32x10_lights_v0_9.yaml"
|
||||
"boneio-mosfet48_lights_v0_7.yaml",
|
||||
"boneio-mosfet48_switches_v0_7.yaml"
|
||||
"boneio-8x10A_v0_1.yaml"
|
||||
"boneio-dimmer_gen2_8ch-dev0_4.yaml",
|
||||
|
||||
# Dodaj tutaj kolejne pliki do wykluczenia
|
||||
]
|
||||
|
||||
include_files = [
|
||||
"boneio-input24_gen2-v0_1.yaml",
|
||||
# "boneio-8x10A_gen2_lights-v0_1.yaml",
|
||||
# "boneio-dimmer_gen2_2rgbw-v0_1.yaml",
|
||||
# "boneio-dimmer_gen2_8ch-v0_1"
|
||||
]
|
||||
|
||||
|
||||
GITHUB_PAGES_URL = "https://boneio-eu.github.io/esphome"
|
||||
FIRMWARE_VERSION = "2026.1.2"
|
||||
|
||||
|
||||
def json_pattern(firmware_name, chip_family="ESP32"):
|
||||
# GitHub Pages supports CORS - works with ESP Web Tools
|
||||
firmware_path = f"{GITHUB_PAGES_URL}/firmware/{firmware_name}.bin"
|
||||
|
||||
return {
|
||||
"name": "ESPHome",
|
||||
"version": FIRMWARE_VERSION,
|
||||
"home_assistant_domain": "esphome",
|
||||
"funding_url": "https://esphome.io/guides/supporters.html",
|
||||
"new_install_prompt_erase": False,
|
||||
"builds": [
|
||||
{
|
||||
"chipFamily": chip_family,
|
||||
"parts": [
|
||||
{
|
||||
"path": firmware_path,
|
||||
"offset": 0,
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def get_boneio_name(file):
|
||||
with open(file) as f:
|
||||
next(f)
|
||||
name = next(f)
|
||||
match = re.search(pattern, name)
|
||||
if match:
|
||||
extracted_text = match.group(1)
|
||||
return extracted_text
|
||||
return None
|
||||
|
||||
|
||||
for file in glob.glob("*.yaml"):
|
||||
# Pomiń pliki z listy wykluczeń
|
||||
if file in exclude_files:
|
||||
print(f"Skipping excluded file: {file}")
|
||||
continue
|
||||
if file not in include_files:
|
||||
print(f"Skipping file: {file}")
|
||||
continue
|
||||
|
||||
filename = get_boneio_name(file)
|
||||
chip_family = "ESP32-S3" if "gen2" in filename else "ESP32"
|
||||
if not filename:
|
||||
print("No file found.")
|
||||
break
|
||||
firmware_path = f"{cwd}/.esphome/build/{filename}/.pioenvs/{filename}/firmware.factory.bin"
|
||||
cmd = f'docker run --rm -p 6053:6052 -v "{cwd}":/config -it ghcr.io/esphome/esphome compile {file}'
|
||||
print(cmd)
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
shell=True,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
print("Process failed, breaking.")
|
||||
break
|
||||
shutil.copyfile(firmware_path, f"{firmware_destination}/{filename}.bin")
|
||||
shutil.copyfile(firmware_path, f"{firmware_destination2}/{filename}.bin")
|
||||
|
||||
with open(
|
||||
f"{json_destination}/{filename}.json", "w", encoding="utf-8"
|
||||
) as f:
|
||||
print(f"Creating JSON file: {json_destination}/{filename}.json")
|
||||
json.dump(
|
||||
json_pattern(firmware_name=filename, chip_family=chip_family),
|
||||
f,
|
||||
ensure_ascii=False,
|
||||
indent=4,
|
||||
)
|
||||
Reference in New Issue
Block a user