forked from boneIO-eu/esphome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_firmware.py
78 lines (66 loc) · 1.89 KB
/
create_firmware.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python
import subprocess
import glob
import os
import re
import json
import shutil
from pathlib import Path
home = str(Path.home())
cwd = os.getcwd()
pattern = r"name:\s*(\S+)"
json_destination = "../website/public/esp"
firmware_destination = "../website/public/esp/firmware"
def json_pattern(firmware_name):
return {
"name": "ESPHome",
"version": "2024.10.1",
"home_assistant_domain": "esphome",
"funding_url": "https://esphome.io/guides/supporters.html",
"new_install_prompt_erase": False,
"builds": [
{
"chipFamily": "ESP32",
"parts": [
{
"path": f"/esp/firmware/{firmware_name}.bin",
"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"):
filename = get_boneio_name(file)
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 6052: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")
with open(
f"{json_destination}/{filename}.json", "w", encoding="utf-8"
) as f:
json.dump(
json_pattern(firmware_name=filename),
f,
ensure_ascii=False,
indent=4,
)