forked from AzonInc/Doorman
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_firmware_yaml.py
More file actions
208 lines (162 loc) · 8.49 KB
/
Copy pathgenerate_firmware_yaml.py
File metadata and controls
208 lines (162 loc) · 8.49 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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']
packages_config = [
('host', f'!include ../hosts/{host}.yaml', True),
('external_components', '!include ../components/external-components.yaml', branch != 'local'),
('external_components_local', '!include ../components/external-components.local.yaml', branch == 'local'),
('rgb_status_led', '!include ../components/rgb-status-led.yaml', True),
('rgb_status_led_effects', '!include ../components/rgb-status-led.effects.yaml', True),
('base', '!include ../base.yaml', True),
('webserver_dev', '!include ../components/web-server.dev.yaml', branch == 'dev' or branch == 'local'),
('bluedroid_ble', '!include ../components/bluedroid-ble.yaml', is_esp32 and firmware != 'nuki-bridge'),
('ota_update_esphome', '!include ../components/ota-update.esphome.yaml', True),
('ota_update_http', '!include ../components/ota-update.http.yaml', branch != 'local'),
('ota_update_http_dev', '!include ../components/ota-update.http.dev.yaml', branch == 'dev'),
('dashboard_import', '!include ../components/dashboard-import.yaml', api_variant == 'ha' and branch != 'local'),
('api', '!include ../components/api.homeassistant.yaml', api_variant == 'ha'),
('api', '!include ../components/api.mqtt.yaml', api_variant == 'mqtt'),
('api', '!include ../components/api.homekit.yaml', api_variant == 'homekit'),
('api', '!include ../components/api.custom.yaml', api_variant == 'custom'),
('debug_utilities', '!include ../components/debug-utilities.yaml', branch == 'dev' or branch == 'local'),
('debug_component', '!include ../components/debug-component.yaml', branch == 'dev' or branch == 'local'),
('debug_component_psram', '!include ../components/debug-component.psram.yaml', (branch == 'dev' or branch == 'local') and has_psram),
# Add configo for local tests
('configo', '!include ../components/configo.yaml', branch == 'local'),
('pattern_events', '!include ../components/pattern-events.yaml', True),
('ring_to_open', '!include ../components/ring-to-open.yaml', True),
('ring_to_open_homekit', '!include ../components/ring-to-open.homekit.yaml', api_variant == 'homekit'),
('ring_to_open_nuki', '!include ../components/ring-to-open-nuki.yaml', firmware == 'nuki-bridge'),
('indoor_station_settings', '!include ../components/indoor-station-settings.yaml', True),
('addon_nuki_bridge', '!include ../components/nuki-bridge.yaml', firmware == 'nuki-bridge'),
('interactive_setup', '!include ../components/interactive-setup.yaml', True),
# Add outdoor station for local tests
('outdoor_station', '!include ../components/outdoor-station.yaml', branch == 'local'),
]
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):
if branch == "local":
filename = f'!include ../configurations/{host}.{api_variant}.{firmware}.{branch}.yaml'
else:
filename = f'github://azoninc/doorman/firmware/configurations/{host}.{api_variant}.{firmware}.{branch}.yaml@{branch}'
if api_variant == "ha":
api_variant_desc = "Home Assistant"
elif api_variant == "mqtt":
api_variant_desc = "MQTT"
elif api_variant == "homekit":
api_variant_desc = "HomeKit"
else:
api_variant_desc = "Custom"
if branch == "local":
device_name = "doorman-s3-local-dev"
device_friendly_name = "Doorman S3 (Development)"
else:
device_name = "doorman-s3"
device_friendly_name = "Doorman S3"
content = [
f'# Doorman {"Nuki Bridge" if firmware == "nuki-bridge" else "Standard"} Firmware ({api_variant_desc})',
f'# Base Board {host.upper()}',
'',
'# You can change a few options here.',
'substitutions:',
f' name: "{device_name}"',
f' friendly_name: "{device_friendly_name}"',
' # 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 "Standard"}: ' +
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', 'homekit', 'custom']
FIRMWARES = ['standard', 'nuki-bridge']
BRANCHES = ['master', 'dev', 'local']
def main():
os.makedirs('firmware/configurations', exist_ok=True)
os.makedirs('firmware/examples', exist_ok=True)
# Filter out invalid combinations before generating files
combinations = [
(host, api_variant, firmware, branch)
for host, api_variant, firmware, branch in product(HOST_ARCHITECTURES, API_VARIANTS, FIRMWARES, BRANCHES)
if not (firmware == 'nuki-bridge' and 'mqtt' in api_variant)
]
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}')
# Also generate stock version for compatibility with older setups
if firmware == 'standard':
print('Generate stock version for compatibility...')
stock_filename = f'{host}.{api_variant}.stock.{branch}.yaml'
stock_example_filename = f'{host}.{api_variant}.stock.{branch}.example.yaml'
# Write stock config YAML (same content as standard)
stock_config_filepath = os.path.join('firmware', 'configurations', stock_filename)
with open(stock_config_filepath, 'w', encoding='utf-8') as f:
f.write(config_content)
# Write stock example YAML (same content as standard)
stock_example_filepath = os.path.join('firmware', 'examples', stock_example_filename)
with open(stock_example_filepath, 'w', encoding='utf-8') as f:
f.write(example_content)
print(f'Generated: {stock_filename}')
if __name__ == '__main__':
main()