-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate_firmware_yaml.py
149 lines (117 loc) · 5.79 KB
/
generate_firmware_yaml.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import os
from itertools import product
def get_host_architectures():
"""Get host architectures from firmware/hosts directory"""
hosts_dir = os.path.join('firmware', 'hosts')
if not os.path.exists(hosts_dir):
raise FileNotFoundError(f"Hosts directory not found: {hosts_dir}")
hosts = []
for file in os.listdir(hosts_dir):
if file.endswith('.yaml'):
# Remove .yaml extension
host = os.path.splitext(file)[0]
hosts.append(host)
if not hosts:
raise ValueError("No host configuration files found in firmware/hosts directory")
return sorted(hosts) # Sort for consistent order
def get_packages(host, api_variant, firmware, branch):
# Define packages in exact order with their conditions
is_esp32 = 'esp32' in host.lower()
has_psram = host in ['esp32-s2', 'esp32-s3', 'esp32-s3-quad']
has_status_led = is_esp32
packages_config = [
('host', f'!include ../hosts/{host}.yaml', True),
('rgb_status_led', '!include ../components/rgb-status-led.yaml', has_status_led),
('rgb_status_led', '!include ../components/rgb-status-led.dummy.yaml', not has_status_led),
('base', '!include ../base.yaml', True),
('bluedroid_ble', '!include ../components/bluedroid-ble.yaml', is_esp32 and firmware != 'nuki-bridge'),
('ota_updates', '!include ../components/ota-updates.yaml', api_variant == 'ha'),
('ota_updates_default_dev', '!include ../components/ota-updates-default-dev.yaml', api_variant == 'ha' and branch == 'dev'),
('dashboard_import', '!include ../components/dashboard-import.yaml', api_variant == 'ha'),
('api', '!include ../components/api-homeassistant.yaml', api_variant == 'ha'),
('api', '!include ../components/api-mqtt.yaml', api_variant == 'mqtt'),
('api', '!include ../components/api-custom.yaml', api_variant == 'custom'),
('debug_utilities', '!include ../components/debug-utilities.yaml', branch == 'dev'),
('debug_utilities_psram', '!include ../components/debug-utilities.psram.yaml', branch == 'dev' and has_psram),
('debug_utilities_non_esp32', '!include ../components/debug-utilities.non-esp32.yaml', branch == 'dev' and not is_esp32),
('pattern_events', '!include ../components/pattern-events.yaml', True),
('ring_to_open', '!include ../components/ring-to-open.yaml', True),
('intercom_settings', '!include ../components/intercom-settings.yaml', True),
('addon_nuki_bridge', '!include ../components/nuki-bridge.yaml', firmware == 'nuki-bridge'),
('interactive_setup', '!include ../components/interactive-setup.yaml', True),
]
return [(name, path) for name, path, condition in packages_config if condition]
def generate_yaml_content(host, api_variant, firmware, branch):
content = [
'substitutions:',
f' branch: "{branch}"',
f' firmware_type: "{firmware}"',
f' api_variant: "{api_variant}"',
f' host_platform: "{host}"',
'',
'packages:'
]
packages = get_packages(host, api_variant, firmware, branch)
for name, path in packages:
content.append(f' {name}: {path}')
return '\n'.join(content)
def generate_example_yaml(host, api_variant, firmware, branch):
filename = f'github://azoninc/doorman/firmware/configurations/{host}.{api_variant}.{firmware}.{branch}.yaml@{branch}'
content = [
f'# Doorman {"Nuki Bridge" if firmware == "nuki-bridge" else "Stock"} Firmware ({"Home Assistant" if api_variant == "ha" else "MQTT"})',
f'# Base Board {host.upper()}',
'',
'# You can change a few options here.',
'substitutions:',
' name: "doorman-s3"',
' friendly_name: "Doorman S3"',
' # log_level: "ERROR"',
' # led_pin: "GPIO1"',
' # rgb_led_pin: "GPIO2"',
' # relay_pin: "GPIO42"',
' # external_button_pin: "GPIO41"',
' # adc_input_pin: "GPIO10"',
'',
'# Import Doorman Firmware Config',
'packages:',
f' AzonInc.Doorman{"-Nuki-Bridge" if firmware == "nuki-bridge" else ""}: ' +
f'{filename}',
'',
'wifi:',
' ssid: !secret wifi_ssid',
' password: !secret wifi_password'
]
if api_variant == 'mqtt':
content.extend([
'',
'mqtt:',
' broker: "10.10.0.2"',
' username: ""',
' password: ""'
])
return '\n'.join(content)
# Configuration options
HOST_ARCHITECTURES = get_host_architectures()
API_VARIANTS = ['ha', 'mqtt', 'custom']
FIRMWARES = ['stock', 'nuki-bridge']
BRANCHES = ['master', 'dev']
def main():
os.makedirs('firmware/configurations', exist_ok=True)
os.makedirs('firmware/examples', exist_ok=True)
combinations = product(HOST_ARCHITECTURES, API_VARIANTS, FIRMWARES, BRANCHES)
for host, api_variant, firmware, branch in combinations:
filename = f'{host}.{api_variant}.{firmware}.{branch}.yaml'
example_filename = f'{host}.{api_variant}.{firmware}.{branch}.example.yaml'
config_content = generate_yaml_content(host, api_variant, firmware, branch)
example_content = generate_example_yaml(host, api_variant, firmware, branch)
# Write config YAML
config_filepath = os.path.join('firmware', 'configurations', filename)
with open(config_filepath, 'w', encoding='utf-8') as f:
f.write(config_content)
# Write example YAML
example_filepath = os.path.join('firmware', 'examples', example_filename)
with open(example_filepath, 'w', encoding='utf-8') as f:
f.write(example_content)
print(f'Generated: {filename}')
if __name__ == '__main__':
main()