61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
import json
|
|
import sys
|
|
import glob
|
|
import os
|
|
import re
|
|
import hashlib
|
|
import shutil
|
|
|
|
|
|
def main():
|
|
os.makedirs("dist", exist_ok=True)
|
|
|
|
for path in glob.glob(".esphome/build/*/src/esphome/core/defines.h"):
|
|
fields = {}
|
|
with open(path) as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
match = re.match(r"#define\s+(\w+)\s\"(.+)\"", line)
|
|
if not match:
|
|
continue
|
|
fields[match.group(1)] = match.group(2)
|
|
|
|
name = fields.get("ESPHOME_PROJECT_NAME", None)
|
|
version = fields.get("ESPHOME_PROJECT_VERSION", None)
|
|
variant = fields.get("ESPHOME_VARIANT", None)
|
|
|
|
if None in (name, version, variant):
|
|
continue
|
|
|
|
configuration = path.split("/")[2]
|
|
ota = (
|
|
f".esphome/build/{configuration}/.pioenvs/{configuration}/firmware.ota.bin"
|
|
)
|
|
if not os.path.exists(ota):
|
|
continue
|
|
|
|
with open(ota, "r+b") as f:
|
|
md5 = hashlib.md5()
|
|
md5.update(f.read())
|
|
|
|
target = f"{name}-{version}.bin"
|
|
shutil.copy(ota, f"dist/{target}")
|
|
manifest = {
|
|
"name": name,
|
|
"version": version,
|
|
"builds": [
|
|
{
|
|
"chipFamily": variant,
|
|
"ota": {
|
|
"md5": md5.hexdigest(),
|
|
"path": target,
|
|
},
|
|
}
|
|
],
|
|
}
|
|
with open(f"dist/{name}.json", "w") as f:
|
|
json.dump(manifest, f, indent=4)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|