@pellebot/homebridge-fritz-platform-hb2 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +2 -0
- package/branding/Icon.png +0 -0
- package/config.schema.json +1 -0
- package/homebridge-ui/package.json +4 -0
- package/homebridge-ui/public/index.html +972 -0
- package/homebridge-ui/server.js +232 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
> **Hinweis zum Format:** Releases ab `v1.0.0` werden unter dem npm-Paket `@pellebot/homebridge-fritz-platform-hb2` veröffentlicht. Die `6.1.0-hb2patch.x` Pre-Releases sind Vorstufen unter dem alten Paketnamen `@pellebot/homebridge-fritz-platform` (deprecated). Die `registerPlatform`-Kennung bleibt durchgängig `homebridge-fritz-platform`, sodass cached Accessories über den Rename hinweg matchen — kein Re-Pairing nötig.
|
|
4
4
|
|
|
5
|
+
# v1.1.0 — 2026-05-13 (Setup-Wizard Release)
|
|
6
|
+
|
|
7
|
+
**Neue Custom-UI mit Setup-Wizard.** Config UI X öffnet beim Klick auf das Plugin-Settings-Icon ab dieser Version unseren geführten 5-Schritt-Wizard statt des bisherigen JSON-Schema-Formulars. Das macht das Erstsetup deutlich freundlicher — kein Raten mehr bei Feldern wie `accType`, `obisChannel` oder AIN-Format.
|
|
8
|
+
|
|
9
|
+
## Neuerungen
|
|
10
|
+
|
|
11
|
+
- **`homebridge-ui/server.js` + `homebridge-ui/public/index.html`** — neuer Custom-UI-Server-Prozess der bei Plugin-Settings-Aufruf gestartet wird. Kommuniziert per IPC mit dem Config UI X Frontend.
|
|
12
|
+
- **5-Schritt-Wizard:**
|
|
13
|
+
- **Schritt 1 — FritzBox-Verbindung:** Form mit Host/Port/SSL/TR-064/User/Passwort + "Verbindung testen"-Button. Backend ruft TR-064 + AHA-API live an, gibt actionable Hints bei Fehlern (ECONNREFUSED → "TR-064 aktivieren", 401 → "Smart Home Berechtigung fehlt", etc.).
|
|
14
|
+
- **Schritt 2 — Geräte-Auswahl:** Auto-Discovery aller DECT-Geräte. Pro Gerät wird der `accType` anhand der von `@seydx/fritzbox` normalisierten Feldern (`.thermostat`, `.light`, `.switch`, `.powermeter`, `.temperature`, `.button`, `.blind`, `.alert`) automatisch vorgeschlagen. Nutzer kann pro Gerät einzeln overriden.
|
|
15
|
+
- **Schritt 3 — Smart Energy 250 OBIS-Reader:** OBIS-Sub-AINs aus Schritt 2 werden nach Base-AIN gruppiert. Pro Reader werden 4 HomeKit-Tiles auto-vorgeschlagen (Aktueller Verbrauch + Gesamt Verbrauch + Aktuelle Einspeisung + Gesamt Einspeisung mit anpassbaren Namen).
|
|
16
|
+
- **Schritt 4 — Router-Switches:** Checkboxen für Gast-WLAN, WPS, WLAN 2.4/5 GHz, DECT-Basis, AB, Rufumleitung, Reconnect. Vorausgewählt aus bestehender Config wenn vorhanden.
|
|
17
|
+
- **Schritt 5 — Speichern + Apply:** Zusammenfassung, JSON-Vorschau mit maskiertem Passwort, Save via `homebridge.updatePluginConfig` + `homebridge.savePluginConfig`, Restart-Homebridge-Button.
|
|
18
|
+
- **Auto-Pre-fill aus bestehender Config:** Verbindungs-Schritt und Router-Switches lesen die aktuelle Config beim Öffnen und füllen Formularfelder/Checkboxen vor. Make-it-easy bei Migration und beim Editieren.
|
|
19
|
+
- **AIN-Suffix-Detection:** OBIS-Sub-AIN-Erkennung (`-1`/`-2`) korrekt priorisiert nach physischen Features — DECT 500 Lampen werden nicht mehr fälschlich als OBIS-Reader interpretiert (HAN-FUN-Sub-Unit mit `-1`-Suffix aber `.light`-Objekt).
|
|
20
|
+
|
|
21
|
+
## Breaking Changes
|
|
22
|
+
|
|
23
|
+
Keine. Bestehende Configs werden unverändert übernommen, das alte JSON-Schema-Form ist über den "Save"-Button (bottom-right) im Config UI X immer noch als Fallback erreichbar.
|
|
24
|
+
|
|
25
|
+
## Bekannte Limitationen
|
|
26
|
+
|
|
27
|
+
- **Standalone Config UI X:** `homebridge.savePluginConfig()` kann in Standalone-Modus die WebSocket-ACK nicht empfangen → wir racen den Save mit einem 3-Sek-Timeout. Datei wird trotzdem korrekt geschrieben.
|
|
28
|
+
- **Custom-UI-Icon:** wird im Config UI X Plugin-Tile erst nach Homebridge-Verified-Plugin-Approval angezeigt (Repo `homebridge/plugins`-Icons-Liste). Bis dahin Default-Lila-Homebridge-Icon.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
5
32
|
# v1.0.0 — 2026-05-13 (First Production Release)
|
|
6
33
|
|
|
7
34
|
**Erstes stabiles Release** des `@pellebot/homebridge-fritz-platform-hb2`. Setzt die Code-Linie der `6.1.0-hb2patch.x` Pre-Releases fort, jetzt mit unabhängiger Versionierung und neuem npm-Paketnamen.
|
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Production: läuft produktiv beim Maintainer mit 12 DECT-Thermostaten, 1 DECT-Lampe, 2 Temperatursensoren, einem FRITZ!Smart Energy 250 OBIS-Reader an einem ISKRA-Stromzähler, sowie aktiven Router-Switches für Gast-WLAN und WPS — alles auf Homebridge 2.0.2 + Node 24 + FRITZ!OS 8.x.
|
|
17
17
|
|
|
18
|
+
**Seit v1.1.0:** Setup-Wizard in Config UI X — beim ersten Plugin-Settings-Aufruf führt ein 5-Schritt-Assistent durch FritzBox-Verbindung, Geräte-Auswahl, Smart Energy 250, Router-Switches und Speichern. Auto-Discovery aller DECT-Geräte mit accType-Vorschlag pro Gerät.
|
|
19
|
+
|
|
18
20
|
## Unterstützte Geräte
|
|
19
21
|
|
|
20
22
|
| Gerätetyp | accType | Was wird in HomeKit angezeigt |
|
package/branding/Icon.png
CHANGED
|
Binary file
|
package/config.schema.json
CHANGED
|
@@ -0,0 +1,972 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Custom UI for @pellebot/homebridge-fritz-platform-hb2
|
|
3
|
+
|
|
4
|
+
Phases A+B+C implemented:
|
|
5
|
+
A. Foundation (server.js, public/index.html, customUi flag)
|
|
6
|
+
B. Connection test — Step 1 with form + /test-connection endpoint
|
|
7
|
+
C. Device discovery — Step 2 with auto-detected accType per device
|
|
8
|
+
|
|
9
|
+
Future phases: Energy 250, Router-Switches, Save, Edit mode.
|
|
10
|
+
-->
|
|
11
|
+
<style>
|
|
12
|
+
.wizard-step-indicator {
|
|
13
|
+
display: flex;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
margin-bottom: 1.5rem;
|
|
16
|
+
padding: 0 1rem;
|
|
17
|
+
}
|
|
18
|
+
.wizard-step-indicator .step {
|
|
19
|
+
flex: 1;
|
|
20
|
+
text-align: center;
|
|
21
|
+
position: relative;
|
|
22
|
+
padding-top: 2.5rem;
|
|
23
|
+
color: var(--bs-secondary, #6c757d);
|
|
24
|
+
font-size: 0.8rem;
|
|
25
|
+
}
|
|
26
|
+
.wizard-step-indicator .step::before {
|
|
27
|
+
content: attr(data-step);
|
|
28
|
+
position: absolute;
|
|
29
|
+
top: 0;
|
|
30
|
+
left: 50%;
|
|
31
|
+
transform: translateX(-50%);
|
|
32
|
+
width: 2rem;
|
|
33
|
+
height: 2rem;
|
|
34
|
+
border-radius: 50%;
|
|
35
|
+
background: var(--bs-gray-300, #dee2e6);
|
|
36
|
+
color: white;
|
|
37
|
+
line-height: 2rem;
|
|
38
|
+
font-weight: bold;
|
|
39
|
+
font-size: 1rem;
|
|
40
|
+
}
|
|
41
|
+
.wizard-step-indicator .step.active {
|
|
42
|
+
color: var(--bs-primary, #6f42c1);
|
|
43
|
+
font-weight: 600;
|
|
44
|
+
}
|
|
45
|
+
.wizard-step-indicator .step.active::before {
|
|
46
|
+
background: var(--bs-primary, #6f42c1);
|
|
47
|
+
}
|
|
48
|
+
.wizard-step-indicator .step.done::before {
|
|
49
|
+
background: var(--bs-success, #198754);
|
|
50
|
+
content: "✓";
|
|
51
|
+
}
|
|
52
|
+
.form-row {
|
|
53
|
+
margin-bottom: 1rem;
|
|
54
|
+
}
|
|
55
|
+
.step-pane {
|
|
56
|
+
display: none;
|
|
57
|
+
}
|
|
58
|
+
.step-pane.active {
|
|
59
|
+
display: block;
|
|
60
|
+
}
|
|
61
|
+
.device-card {
|
|
62
|
+
border: 1px solid var(--bs-border-color, #dee2e6);
|
|
63
|
+
border-radius: 0.5rem;
|
|
64
|
+
padding: 0.75rem 1rem;
|
|
65
|
+
margin-bottom: 0.75rem;
|
|
66
|
+
background: var(--bs-body-bg, #fff);
|
|
67
|
+
}
|
|
68
|
+
.device-card.inactive {
|
|
69
|
+
opacity: 0.5;
|
|
70
|
+
}
|
|
71
|
+
.device-card .device-header {
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
gap: 0.75rem;
|
|
75
|
+
}
|
|
76
|
+
.device-card .device-name {
|
|
77
|
+
flex: 1;
|
|
78
|
+
font-weight: 600;
|
|
79
|
+
}
|
|
80
|
+
.device-card .device-ain {
|
|
81
|
+
font-family: monospace;
|
|
82
|
+
font-size: 0.8rem;
|
|
83
|
+
color: var(--bs-secondary, #6c757d);
|
|
84
|
+
}
|
|
85
|
+
.device-card .device-meta {
|
|
86
|
+
margin-top: 0.5rem;
|
|
87
|
+
margin-left: 1.75rem;
|
|
88
|
+
font-size: 0.85rem;
|
|
89
|
+
color: var(--bs-secondary, #6c757d);
|
|
90
|
+
}
|
|
91
|
+
.device-card .device-meta .badge {
|
|
92
|
+
margin-right: 0.5rem;
|
|
93
|
+
}
|
|
94
|
+
.wizard-nav {
|
|
95
|
+
display: flex;
|
|
96
|
+
justify-content: space-between;
|
|
97
|
+
margin-top: 1.5rem;
|
|
98
|
+
padding-top: 1rem;
|
|
99
|
+
border-top: 1px solid var(--bs-border-color, #dee2e6);
|
|
100
|
+
}
|
|
101
|
+
</style>
|
|
102
|
+
|
|
103
|
+
<div class="card">
|
|
104
|
+
<div class="card-body">
|
|
105
|
+
<div style="text-align: center; margin-bottom: 1rem;">
|
|
106
|
+
<img src="https://raw.githubusercontent.com/PelleBot/homebridge-fritz-platform-ng/main/branding/Icon.png"
|
|
107
|
+
alt="Plugin Logo"
|
|
108
|
+
style="max-width: 80px; border-radius: 12px;">
|
|
109
|
+
<h4 style="margin-top: 0.75rem;">Homebridge FRITZ!Box Platform (HB2) — Setup Wizard</h4>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div class="wizard-step-indicator">
|
|
113
|
+
<div class="step active" data-step="1">FritzBox-Verbindung</div>
|
|
114
|
+
<div class="step" data-step="2">Geräte-Auswahl</div>
|
|
115
|
+
<div class="step" data-step="3">Energy 250</div>
|
|
116
|
+
<div class="step" data-step="4">Router-Switches</div>
|
|
117
|
+
<div class="step" data-step="5">Speichern</div>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<!-- ============ STEP 1 — Connection Test ============ -->
|
|
121
|
+
<div class="step-pane active" id="step-1">
|
|
122
|
+
<div class="alert alert-info">
|
|
123
|
+
<strong>Schritt 1 — FritzBox-Verbindung</strong><br>
|
|
124
|
+
Trage hier die Verbindungsdaten zu deiner FritzBox ein. Du brauchst einen
|
|
125
|
+
dedizierten FRITZ!Box-User mit der Berechtigung <em>"Smart Home"</em>
|
|
126
|
+
(FritzBox-UI → System → FRITZ!Box-Benutzer → Bearbeiten).
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<div class="form-row">
|
|
130
|
+
<label for="host">FritzBox-IP-Adresse</label>
|
|
131
|
+
<input type="text" id="host" class="form-control" placeholder="192.168.178.1">
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<div class="form-row" style="display: flex; gap: 1rem;">
|
|
135
|
+
<div style="flex: 1;">
|
|
136
|
+
<label for="port">Port</label>
|
|
137
|
+
<input type="number" id="port" class="form-control" placeholder="49000" value="49000">
|
|
138
|
+
</div>
|
|
139
|
+
<div style="flex: 1; padding-top: 1.85rem;">
|
|
140
|
+
<div class="form-check">
|
|
141
|
+
<input type="checkbox" id="ssl" class="form-check-input" checked>
|
|
142
|
+
<label class="form-check-label" for="ssl">SSL aktiviert</label>
|
|
143
|
+
</div>
|
|
144
|
+
<div class="form-check">
|
|
145
|
+
<input type="checkbox" id="tr064" class="form-check-input" checked>
|
|
146
|
+
<label class="form-check-label" for="tr064">TR-064 aktiviert</label>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
<div class="form-row">
|
|
152
|
+
<label for="username">FritzBox-User</label>
|
|
153
|
+
<input type="text" id="username" class="form-control" placeholder="homebridge-user" autocomplete="off">
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<div class="form-row">
|
|
157
|
+
<label for="password">Passwort</label>
|
|
158
|
+
<input type="password" id="password" class="form-control" placeholder="••••••••" autocomplete="off">
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<div style="margin-top: 1.5rem; text-align: center;">
|
|
162
|
+
<button id="testBtn" class="btn btn-primary btn-lg">
|
|
163
|
+
Verbindung testen
|
|
164
|
+
</button>
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
<div id="testResult" style="margin-top: 1rem;"></div>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<!-- ============ STEP 2 — Device Discovery ============ -->
|
|
171
|
+
<div class="step-pane" id="step-2">
|
|
172
|
+
<div class="alert alert-info">
|
|
173
|
+
<strong>Schritt 2 — Geräte-Auswahl</strong><br>
|
|
174
|
+
Wir haben deine FritzBox abgefragt. Wähle aus, welche Geräte du in
|
|
175
|
+
HomeKit nutzen möchtest. Der vorgeschlagene Typ wurde automatisch
|
|
176
|
+
anhand der Geräte-Eigenschaften erkannt — du kannst ihn pro Gerät
|
|
177
|
+
überschreiben falls nötig.
|
|
178
|
+
</div>
|
|
179
|
+
|
|
180
|
+
<div id="deviceList" style="margin-top: 1rem;">
|
|
181
|
+
<div class="text-center text-muted" style="padding: 2rem;">
|
|
182
|
+
Lade Geräte…
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
|
|
186
|
+
<div class="wizard-nav">
|
|
187
|
+
<button id="backTo1" class="btn btn-outline-secondary">← Zurück zu Schritt 1</button>
|
|
188
|
+
<button id="goTo3" class="btn btn-primary">Weiter zu Schritt 3 →</button>
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
<!-- ============ STEP 3 — Energy 250 Special Path ============ -->
|
|
193
|
+
<div class="step-pane" id="step-3">
|
|
194
|
+
<div class="alert alert-info">
|
|
195
|
+
<strong>Schritt 3 — Smart Energy 250 (OBIS-Reader)</strong><br>
|
|
196
|
+
Falls deine FritzBox einen Smart Energy 250 mit ISKRA/Iskra-Stromzähler
|
|
197
|
+
hat: hier kannst du die 4 HomeKit-Tiles für aktuelle Leistung (W) und
|
|
198
|
+
kumulierte Energie (kWh) je Richtung (Bezug + Einspeisung) anlegen.
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<div id="energy250Content" style="margin-top: 1rem;">
|
|
202
|
+
<!-- Generated dynamically from wizardState.deviceSelections -->
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
<div class="wizard-nav">
|
|
206
|
+
<button id="backTo2" class="btn btn-outline-secondary">← Zurück zu Schritt 2</button>
|
|
207
|
+
<button id="goTo4" class="btn btn-primary">Weiter zu Schritt 4 →</button>
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<!-- ============ STEP 4 — Router Switches ============ -->
|
|
212
|
+
<div class="step-pane" id="step-4">
|
|
213
|
+
<div class="alert alert-info">
|
|
214
|
+
<strong>Schritt 4 — FritzBox Router-Switches (optional)</strong><br>
|
|
215
|
+
Falls du Router-Funktionen wie <em>Gast-WLAN</em>, <em>WPS</em>, oder
|
|
216
|
+
<em>DECT-Basis</em> als HomeKit-Tile haben willst, kannst du diese
|
|
217
|
+
unten auswählen. Standard ist <em>nichts ausgewählt</em> — wir
|
|
218
|
+
empfehlen nur die zu aktivieren die du wirklich brauchst (weniger
|
|
219
|
+
Tiles in Apple Home = übersichtlicher).
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
<div style="margin-top: 1rem;">
|
|
223
|
+
<div class="form-check" style="margin-bottom: 0.5rem;">
|
|
224
|
+
<input type="checkbox" id="router-wifi_guest" class="form-check-input router-switch" data-key="wifi_guest">
|
|
225
|
+
<label class="form-check-label" for="router-wifi_guest">
|
|
226
|
+
<strong>Gast-WLAN</strong> — schaltet das Gast-WLAN ein/aus. Empfohlen.
|
|
227
|
+
</label>
|
|
228
|
+
</div>
|
|
229
|
+
|
|
230
|
+
<div class="form-check" style="margin-bottom: 0.5rem;">
|
|
231
|
+
<input type="checkbox" id="router-wps" class="form-check-input router-switch" data-key="wps">
|
|
232
|
+
<label class="form-check-label" for="router-wps">
|
|
233
|
+
<strong>WPS</strong> — startet den WPS-Pairing-Modus (2 Min Auto-Stop). Empfohlen.
|
|
234
|
+
</label>
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
<div class="form-check" style="margin-bottom: 0.5rem;">
|
|
238
|
+
<input type="checkbox" id="router-wifi_2ghz" class="form-check-input router-switch" data-key="wifi_2ghz">
|
|
239
|
+
<label class="form-check-label" for="router-wifi_2ghz">
|
|
240
|
+
WLAN 2.4 GHz — schaltet das 2.4-GHz-Band ein/aus.
|
|
241
|
+
</label>
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
<div class="form-check" style="margin-bottom: 0.5rem;">
|
|
245
|
+
<input type="checkbox" id="router-wifi_5ghz" class="form-check-input router-switch" data-key="wifi_5ghz">
|
|
246
|
+
<label class="form-check-label" for="router-wifi_5ghz">
|
|
247
|
+
WLAN 5 GHz — schaltet das 5-GHz-Band ein/aus.
|
|
248
|
+
</label>
|
|
249
|
+
</div>
|
|
250
|
+
|
|
251
|
+
<div class="form-check" style="margin-bottom: 0.5rem;">
|
|
252
|
+
<input type="checkbox" id="router-dect" class="form-check-input router-switch" data-key="dect">
|
|
253
|
+
<label class="form-check-label" for="router-dect">
|
|
254
|
+
DECT-Basis — schaltet die DECT-Basis ein/aus. <em>Vorsicht:</em> trennt alle DECT-Geräte!
|
|
255
|
+
</label>
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
<div class="form-check" style="margin-bottom: 0.5rem;">
|
|
259
|
+
<input type="checkbox" id="router-aw" class="form-check-input router-switch" data-key="aw">
|
|
260
|
+
<label class="form-check-label" for="router-aw">
|
|
261
|
+
Anrufbeantworter — schaltet den Anrufbeantworter ein/aus.
|
|
262
|
+
</label>
|
|
263
|
+
</div>
|
|
264
|
+
|
|
265
|
+
<div class="form-check" style="margin-bottom: 0.5rem;">
|
|
266
|
+
<input type="checkbox" id="router-deflection" class="form-check-input router-switch" data-key="deflection">
|
|
267
|
+
<label class="form-check-label" for="router-deflection">
|
|
268
|
+
Rufumleitung — schaltet die Rufumleitung ein/aus.
|
|
269
|
+
</label>
|
|
270
|
+
</div>
|
|
271
|
+
|
|
272
|
+
<div class="form-check" style="margin-bottom: 0.5rem;">
|
|
273
|
+
<input type="checkbox" id="router-reconnect" class="form-check-input router-switch" data-key="reconnect">
|
|
274
|
+
<label class="form-check-label" for="router-reconnect">
|
|
275
|
+
Reconnect — erzwingt eine neue Internet-Verbindung (IP-Wechsel). Trigger-Switch.
|
|
276
|
+
</label>
|
|
277
|
+
</div>
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<details style="margin-top: 1rem;">
|
|
281
|
+
<summary style="cursor: pointer; color: #6c757d;">FritzBox-User braucht spezielle Berechtigung — Hinweis</summary>
|
|
282
|
+
<div style="margin-top: 0.5rem; padding: 0.5rem; border-left: 3px solid #6c757d;">
|
|
283
|
+
Für Router-Switches braucht dein FRITZ!Box-User die Berechtigung
|
|
284
|
+
<em>"FRITZ!Box-Einstellungen"</em> (zusätzlich zu Smart Home).
|
|
285
|
+
Setting kannst du in der FritzBox-UI prüfen unter
|
|
286
|
+
<em>System → FRITZ!Box-Benutzer → [User] → Bearbeiten</em>.
|
|
287
|
+
</div>
|
|
288
|
+
</details>
|
|
289
|
+
|
|
290
|
+
<div class="wizard-nav">
|
|
291
|
+
<button id="backTo3" class="btn btn-outline-secondary">← Zurück zu Schritt 3</button>
|
|
292
|
+
<button id="goTo5" class="btn btn-primary">Weiter zu Schritt 5 →</button>
|
|
293
|
+
</div>
|
|
294
|
+
</div>
|
|
295
|
+
|
|
296
|
+
<!-- ============ STEP 5 — Save + Apply ============ -->
|
|
297
|
+
<div class="step-pane" id="step-5">
|
|
298
|
+
<div class="alert alert-info">
|
|
299
|
+
<strong>Schritt 5 — Konfiguration speichern</strong><br>
|
|
300
|
+
Zusammenfassung deiner Auswahl. Klick auf <em>"Konfiguration speichern"</em>
|
|
301
|
+
unten um die <code>config.json</code> zu aktualisieren. Danach musst du
|
|
302
|
+
Homebridge neu starten damit die Änderungen wirksam werden.
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
<div id="saveSummary" style="margin-top: 1rem;"></div>
|
|
306
|
+
|
|
307
|
+
<details style="margin-top: 1rem;">
|
|
308
|
+
<summary style="cursor: pointer;">Generierte Plugin-Config anzeigen (JSON-Vorschau)</summary>
|
|
309
|
+
<pre id="savePreview" style="background: var(--bs-tertiary-bg, #f8f9fa); padding: 1rem; border-radius: 0.5rem; overflow-x: auto; max-height: 400px; font-size: 0.75rem; margin-top: 0.5rem;"></pre>
|
|
310
|
+
</details>
|
|
311
|
+
|
|
312
|
+
<div id="saveResult" style="margin-top: 1rem;"></div>
|
|
313
|
+
|
|
314
|
+
<div class="wizard-nav">
|
|
315
|
+
<button id="backTo4" class="btn btn-outline-secondary">← Zurück zu Schritt 4</button>
|
|
316
|
+
<button id="saveBtn" class="btn btn-success btn-lg">💾 Konfiguration speichern</button>
|
|
317
|
+
</div>
|
|
318
|
+
</div>
|
|
319
|
+
</div>
|
|
320
|
+
</div>
|
|
321
|
+
|
|
322
|
+
<script>
|
|
323
|
+
(() => {
|
|
324
|
+
// Wizard state — persists across step transitions
|
|
325
|
+
const wizardState = {
|
|
326
|
+
connection: null, // { host, port, ssl, tr064, username, password } after step 1 success
|
|
327
|
+
discoveredDevices: [], // raw discovery output from step 2 load
|
|
328
|
+
deviceSelections: {}, // { ain: { include: bool, accType: string } } after step 2
|
|
329
|
+
energyTiles: {}, // { ain: [{ obisChannel, name }, ...] } after step 3
|
|
330
|
+
routerSwitches: {}, // { wifi_guest: bool, wps: bool, ... } after step 4
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// ============ DOM References ============
|
|
334
|
+
const stepPanes = {
|
|
335
|
+
1: document.getElementById('step-1'),
|
|
336
|
+
2: document.getElementById('step-2'),
|
|
337
|
+
3: document.getElementById('step-3'),
|
|
338
|
+
4: document.getElementById('step-4'),
|
|
339
|
+
5: document.getElementById('step-5'),
|
|
340
|
+
};
|
|
341
|
+
const stepIndicators = document.querySelectorAll('.wizard-step-indicator .step');
|
|
342
|
+
|
|
343
|
+
const inputs = {
|
|
344
|
+
host: document.getElementById('host'),
|
|
345
|
+
port: document.getElementById('port'),
|
|
346
|
+
ssl: document.getElementById('ssl'),
|
|
347
|
+
tr064: document.getElementById('tr064'),
|
|
348
|
+
username: document.getElementById('username'),
|
|
349
|
+
password: document.getElementById('password'),
|
|
350
|
+
};
|
|
351
|
+
const testBtn = document.getElementById('testBtn');
|
|
352
|
+
const testResult = document.getElementById('testResult');
|
|
353
|
+
const deviceList = document.getElementById('deviceList');
|
|
354
|
+
const backTo1 = document.getElementById('backTo1');
|
|
355
|
+
const goTo3 = document.getElementById('goTo3');
|
|
356
|
+
const backTo2 = document.getElementById('backTo2');
|
|
357
|
+
|
|
358
|
+
// ============ Step navigation ============
|
|
359
|
+
function showStep(n) {
|
|
360
|
+
Object.entries(stepPanes).forEach(([k, el]) => {
|
|
361
|
+
el.classList.toggle('active', k === String(n));
|
|
362
|
+
});
|
|
363
|
+
stepIndicators.forEach((el) => {
|
|
364
|
+
const step = parseInt(el.getAttribute('data-step'), 10);
|
|
365
|
+
el.classList.toggle('active', step === n);
|
|
366
|
+
el.classList.toggle('done', step < n);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// ============ Step 1 — Connection Test ============
|
|
371
|
+
// Prefill from existing plugin config
|
|
372
|
+
(async () => {
|
|
373
|
+
try {
|
|
374
|
+
const allConfig = await homebridge.getPluginConfig();
|
|
375
|
+
const fritz = (allConfig || []).find((c) => c && c.platform === 'FritzPlatform');
|
|
376
|
+
const master = fritz && fritz.devices && fritz.devices.find((d) => d.master === true);
|
|
377
|
+
if (master) {
|
|
378
|
+
if (master.host) inputs.host.value = master.host;
|
|
379
|
+
if (master.port) inputs.port.value = master.port;
|
|
380
|
+
if (typeof master.ssl === 'boolean') inputs.ssl.checked = master.ssl;
|
|
381
|
+
if (typeof master.tr064 === 'boolean') inputs.tr064.checked = master.tr064;
|
|
382
|
+
if (master.username) inputs.username.value = master.username;
|
|
383
|
+
if (master.password) inputs.password.value = master.password;
|
|
384
|
+
}
|
|
385
|
+
} catch (err) {
|
|
386
|
+
// No config yet — keep placeholders.
|
|
387
|
+
}
|
|
388
|
+
})();
|
|
389
|
+
|
|
390
|
+
testBtn.addEventListener('click', async () => {
|
|
391
|
+
testResult.innerHTML = '';
|
|
392
|
+
|
|
393
|
+
const payload = {
|
|
394
|
+
host: inputs.host.value.trim(),
|
|
395
|
+
port: parseInt(inputs.port.value, 10) || 49000,
|
|
396
|
+
ssl: inputs.ssl.checked,
|
|
397
|
+
tr064: inputs.tr064.checked,
|
|
398
|
+
username: inputs.username.value.trim(),
|
|
399
|
+
password: inputs.password.value,
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
if (!payload.host || !payload.username || !payload.password) {
|
|
403
|
+
testResult.innerHTML =
|
|
404
|
+
'<div class="alert alert-warning">Bitte Host, User und Passwort eintragen.</div>';
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
testBtn.disabled = true;
|
|
409
|
+
testBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status"></span> Teste…';
|
|
410
|
+
|
|
411
|
+
try {
|
|
412
|
+
const response = await homebridge.request('/test-connection', payload);
|
|
413
|
+
|
|
414
|
+
if (response.ok) {
|
|
415
|
+
wizardState.connection = payload;
|
|
416
|
+
|
|
417
|
+
testResult.innerHTML =
|
|
418
|
+
'<div class="alert alert-success">' +
|
|
419
|
+
'<strong>✓ Verbindung erfolgreich</strong><br>' +
|
|
420
|
+
response.message +
|
|
421
|
+
'</div>' +
|
|
422
|
+
'<div class="text-center" style="margin-top: 1rem;">' +
|
|
423
|
+
'<button id="nextToStep2" class="btn btn-success">Weiter zu Schritt 2 →</button>' +
|
|
424
|
+
'</div>';
|
|
425
|
+
|
|
426
|
+
document.getElementById('nextToStep2').addEventListener('click', () => {
|
|
427
|
+
showStep(2);
|
|
428
|
+
loadDevices();
|
|
429
|
+
});
|
|
430
|
+
} else {
|
|
431
|
+
testResult.innerHTML =
|
|
432
|
+
'<div class="alert alert-danger">' +
|
|
433
|
+
'<strong>✗ Verbindung fehlgeschlagen</strong><br>' +
|
|
434
|
+
(response.error || 'Unbekannter Fehler') +
|
|
435
|
+
(response.code ? ' <code>(' + response.code + ')</code>' : '') +
|
|
436
|
+
(response.hint ? '<br><em>' + response.hint + '</em>' : '') +
|
|
437
|
+
'</div>';
|
|
438
|
+
}
|
|
439
|
+
} catch (err) {
|
|
440
|
+
testResult.innerHTML =
|
|
441
|
+
'<div class="alert alert-danger">' +
|
|
442
|
+
'<strong>Server-Fehler:</strong> ' + (err.message || String(err)) +
|
|
443
|
+
'</div>';
|
|
444
|
+
} finally {
|
|
445
|
+
testBtn.disabled = false;
|
|
446
|
+
testBtn.innerHTML = 'Verbindung testen';
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
// ============ Step 2 — Device Discovery ============
|
|
451
|
+
async function loadDevices() {
|
|
452
|
+
deviceList.innerHTML =
|
|
453
|
+
'<div class="text-center text-muted" style="padding: 2rem;">' +
|
|
454
|
+
'<span class="spinner-border spinner-border-sm"></span> Frage FritzBox-Geräteliste ab…' +
|
|
455
|
+
'</div>';
|
|
456
|
+
|
|
457
|
+
try {
|
|
458
|
+
const response = await homebridge.request('/discover-devices', wizardState.connection);
|
|
459
|
+
|
|
460
|
+
if (!response.ok) {
|
|
461
|
+
deviceList.innerHTML =
|
|
462
|
+
'<div class="alert alert-danger">Fehler beim Abrufen der Geräte: ' +
|
|
463
|
+
(response.error || 'unbekannt') + '</div>';
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
wizardState.discoveredDevices = response.devices || [];
|
|
468
|
+
|
|
469
|
+
if (wizardState.discoveredDevices.length === 0) {
|
|
470
|
+
deviceList.innerHTML =
|
|
471
|
+
'<div class="alert alert-warning">Keine Smart-Home-Geräte auf der FritzBox gefunden.</div>';
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
renderDevices();
|
|
476
|
+
} catch (err) {
|
|
477
|
+
deviceList.innerHTML =
|
|
478
|
+
'<div class="alert alert-danger">Server-Fehler: ' + (err.message || String(err)) + '</div>';
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function renderDevices() {
|
|
483
|
+
const accTypeOptions = [
|
|
484
|
+
{ value: 'thermostat', label: 'Thermostat (HKR)' },
|
|
485
|
+
{ value: 'lightbulb', label: 'Lampe' },
|
|
486
|
+
{ value: 'switch', label: 'Steckdose / Schalter' },
|
|
487
|
+
{ value: 'temperature', label: 'Temperatur-Sensor' },
|
|
488
|
+
{ value: 'contact', label: 'Fenster-/Tür-Sensor' },
|
|
489
|
+
{ value: 'button', label: 'Taster' },
|
|
490
|
+
{ value: 'energy-temperature', label: 'Energy-Reader (OBIS Sub-AIN)' },
|
|
491
|
+
{ value: 'energy-meter', label: 'Energy-Meter (Outlet, Eve)' },
|
|
492
|
+
{ value: 'skip', label: '— ignorieren —' },
|
|
493
|
+
];
|
|
494
|
+
|
|
495
|
+
const html = wizardState.discoveredDevices.map((d) => {
|
|
496
|
+
// Default-Selection: include if accType detected (not 'unknown' / 'skip')
|
|
497
|
+
const defaultInclude = d.accType !== 'unknown' && d.accType !== 'skip';
|
|
498
|
+
if (!wizardState.deviceSelections[d.ain]) {
|
|
499
|
+
wizardState.deviceSelections[d.ain] = {
|
|
500
|
+
include: defaultInclude,
|
|
501
|
+
accType: d.accType,
|
|
502
|
+
name: d.name,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
const sel = wizardState.deviceSelections[d.ain];
|
|
506
|
+
|
|
507
|
+
const optionsHtml = accTypeOptions.map((o) =>
|
|
508
|
+
'<option value="' + o.value + '"' + (o.value === sel.accType ? ' selected' : '') + '>' +
|
|
509
|
+
o.label + '</option>'
|
|
510
|
+
).join('');
|
|
511
|
+
|
|
512
|
+
const inactiveClass = sel.include ? '' : ' inactive';
|
|
513
|
+
|
|
514
|
+
// Build feature badges
|
|
515
|
+
const badges = [];
|
|
516
|
+
if (d.flags.hasBattery) badges.push('<span class="badge bg-secondary">Batterie</span>');
|
|
517
|
+
if (d.flags.hasTemperature) badges.push('<span class="badge bg-info">Temperatur</span>');
|
|
518
|
+
if (d.flags.hasPowermeter) badges.push('<span class="badge bg-warning text-dark">Powermeter</span>');
|
|
519
|
+
if (d.flags.hasColorcontrol) badges.push('<span class="badge bg-success">Farbe</span>');
|
|
520
|
+
if (d.flags.isObisSubain) badges.push('<span class="badge bg-primary">OBIS ' +
|
|
521
|
+
(d.flags.obisDirection === 'consumption' ? '1.x' : '2.x') + '</span>');
|
|
522
|
+
if (!d.online) badges.push('<span class="badge bg-danger">OFFLINE</span>');
|
|
523
|
+
|
|
524
|
+
return `
|
|
525
|
+
<div class="device-card${inactiveClass}" data-ain="${d.ain}">
|
|
526
|
+
<div class="device-header">
|
|
527
|
+
<div class="form-check">
|
|
528
|
+
<input type="checkbox" class="form-check-input include-toggle"
|
|
529
|
+
id="inc-${d.ain}" ${sel.include ? 'checked' : ''}>
|
|
530
|
+
</div>
|
|
531
|
+
<div class="device-name">
|
|
532
|
+
${escapeHtml(d.name)}
|
|
533
|
+
<span class="device-ain">${d.ain}</span>
|
|
534
|
+
</div>
|
|
535
|
+
<div>
|
|
536
|
+
<select class="form-select form-select-sm acctype-select" style="min-width: 200px;">
|
|
537
|
+
${optionsHtml}
|
|
538
|
+
</select>
|
|
539
|
+
</div>
|
|
540
|
+
</div>
|
|
541
|
+
<div class="device-meta">
|
|
542
|
+
${badges.join(' ')}
|
|
543
|
+
<em>${escapeHtml(d.reasonDe)}</em>
|
|
544
|
+
</div>
|
|
545
|
+
</div>
|
|
546
|
+
`;
|
|
547
|
+
}).join('');
|
|
548
|
+
|
|
549
|
+
deviceList.innerHTML = html;
|
|
550
|
+
|
|
551
|
+
// Wire up event handlers
|
|
552
|
+
deviceList.querySelectorAll('.device-card').forEach((card) => {
|
|
553
|
+
const ain = card.getAttribute('data-ain');
|
|
554
|
+
const checkbox = card.querySelector('.include-toggle');
|
|
555
|
+
const select = card.querySelector('.acctype-select');
|
|
556
|
+
|
|
557
|
+
checkbox.addEventListener('change', () => {
|
|
558
|
+
wizardState.deviceSelections[ain].include = checkbox.checked;
|
|
559
|
+
card.classList.toggle('inactive', !checkbox.checked);
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
select.addEventListener('change', () => {
|
|
563
|
+
wizardState.deviceSelections[ain].accType = select.value;
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function escapeHtml(s) {
|
|
569
|
+
return String(s || '').replace(/[&<>"']/g, (c) => ({
|
|
570
|
+
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
|
571
|
+
}[c]));
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
backTo1.addEventListener('click', () => showStep(1));
|
|
575
|
+
goTo3.addEventListener('click', () => {
|
|
576
|
+
showStep(3);
|
|
577
|
+
renderEnergy250();
|
|
578
|
+
});
|
|
579
|
+
backTo2.addEventListener('click', () => showStep(2));
|
|
580
|
+
|
|
581
|
+
const goTo4 = document.getElementById('goTo4');
|
|
582
|
+
const backTo3 = document.getElementById('backTo3');
|
|
583
|
+
goTo4.addEventListener('click', () => {
|
|
584
|
+
showStep(4);
|
|
585
|
+
hydrateRouterSwitches();
|
|
586
|
+
});
|
|
587
|
+
backTo3.addEventListener('click', () => showStep(3));
|
|
588
|
+
|
|
589
|
+
const goTo5 = document.getElementById('goTo5');
|
|
590
|
+
const backTo4 = document.getElementById('backTo4');
|
|
591
|
+
goTo5.addEventListener('click', () => {
|
|
592
|
+
showStep(5);
|
|
593
|
+
renderSavePreview();
|
|
594
|
+
});
|
|
595
|
+
backTo4.addEventListener('click', () => showStep(4));
|
|
596
|
+
|
|
597
|
+
// ============ Step 5 — Build + Save ============
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Convert the entire wizardState into a FritzPlatform config object.
|
|
601
|
+
* Layout:
|
|
602
|
+
* { platform, name, devices: [<master>], smarthome: [...], options: { polling: { timer: 30 } } }
|
|
603
|
+
* - master uses Phase 1 credentials + Phase 4 routerSwitches as master.options
|
|
604
|
+
* - smarthome[] includes Phase 2 device selections (non-OBIS, accType !== 'skip')
|
|
605
|
+
* - smarthome[] includes Phase 3 OBIS tiles (4 per Energy 250 reader, typically)
|
|
606
|
+
*/
|
|
607
|
+
function buildPluginConfig() {
|
|
608
|
+
const conn = wizardState.connection || {};
|
|
609
|
+
|
|
610
|
+
// Master FritzBox device
|
|
611
|
+
const master = {
|
|
612
|
+
active: true,
|
|
613
|
+
name: 'FritzBox',
|
|
614
|
+
host: conn.host,
|
|
615
|
+
port: conn.port || 49000,
|
|
616
|
+
username: conn.username,
|
|
617
|
+
password: conn.password,
|
|
618
|
+
ssl: conn.ssl !== false,
|
|
619
|
+
tr064: conn.tr064 !== false,
|
|
620
|
+
master: true,
|
|
621
|
+
hide: true,
|
|
622
|
+
connection: 'cable',
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// Router-Switches as master.options
|
|
626
|
+
const routerOpts = {};
|
|
627
|
+
for (const [key, enabled] of Object.entries(wizardState.routerSwitches || {})) {
|
|
628
|
+
if (enabled) routerOpts[key] = 'switch';
|
|
629
|
+
}
|
|
630
|
+
if (Object.keys(routerOpts).length > 0) {
|
|
631
|
+
master.options = routerOpts;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// Smart-Home entries
|
|
635
|
+
const smarthome = [];
|
|
636
|
+
|
|
637
|
+
// 1. Regular DECT devices from Phase 2 (non-OBIS, accType meaningful)
|
|
638
|
+
for (const [ain, sel] of Object.entries(wizardState.deviceSelections || {})) {
|
|
639
|
+
if (!sel.include || sel.accType === 'skip' || sel.accType === 'unknown') continue;
|
|
640
|
+
if (sel.accType === 'energy-temperature') continue; // OBIS handled below
|
|
641
|
+
|
|
642
|
+
const raw = wizardState.discoveredDevices.find((d) => d.ain === ain);
|
|
643
|
+
const flags = (raw && raw.flags) || {};
|
|
644
|
+
|
|
645
|
+
const entry = {
|
|
646
|
+
active: true,
|
|
647
|
+
name: sel.name || (raw && raw.name) || ain,
|
|
648
|
+
ain,
|
|
649
|
+
accType: sel.accType,
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
// Per-accType conditional fields, defaulting to sensible values
|
|
653
|
+
switch (sel.accType) {
|
|
654
|
+
case 'thermostat':
|
|
655
|
+
entry.temperature = !!flags.hasTemperature;
|
|
656
|
+
entry.window = true;
|
|
657
|
+
entry.battery = !!flags.hasBattery;
|
|
658
|
+
break;
|
|
659
|
+
case 'temperature':
|
|
660
|
+
entry.battery = !!flags.hasBattery;
|
|
661
|
+
break;
|
|
662
|
+
case 'lightbulb':
|
|
663
|
+
entry.brightness = !!flags.hasLevelcontrol;
|
|
664
|
+
entry.color = !!flags.hasColorcontrol;
|
|
665
|
+
break;
|
|
666
|
+
case 'switch':
|
|
667
|
+
entry.energy = !!flags.hasPowermeter;
|
|
668
|
+
break;
|
|
669
|
+
case 'contact':
|
|
670
|
+
entry.battery = !!flags.hasBattery;
|
|
671
|
+
break;
|
|
672
|
+
case 'button':
|
|
673
|
+
entry.battery = !!flags.hasBattery;
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
smarthome.push(entry);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// 2. OBIS Energy 250 tiles from Phase 3 (one entry per (sub-AIN x obisChannel))
|
|
681
|
+
for (const [ain, tiles] of Object.entries(wizardState.energyTiles || {})) {
|
|
682
|
+
// Only include if user kept this sub-AIN in Phase 2 (in case they went back)
|
|
683
|
+
const sel = wizardState.deviceSelections[ain];
|
|
684
|
+
if (!sel || !sel.include || sel.accType !== 'energy-temperature') continue;
|
|
685
|
+
|
|
686
|
+
for (const tile of tiles) {
|
|
687
|
+
smarthome.push({
|
|
688
|
+
active: true,
|
|
689
|
+
name: tile.name,
|
|
690
|
+
ain,
|
|
691
|
+
accType: 'energy-temperature',
|
|
692
|
+
obisChannel: tile.obisChannel,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
return {
|
|
698
|
+
platform: 'FritzPlatform',
|
|
699
|
+
name: 'FritzBox',
|
|
700
|
+
devices: [master],
|
|
701
|
+
smarthome,
|
|
702
|
+
options: {
|
|
703
|
+
polling: { timer: 30 },
|
|
704
|
+
},
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function renderSavePreview() {
|
|
709
|
+
const config = buildPluginConfig();
|
|
710
|
+
const summary = document.getElementById('saveSummary');
|
|
711
|
+
const preview = document.getElementById('savePreview');
|
|
712
|
+
|
|
713
|
+
const nDevices = config.smarthome.filter((s) => s.accType !== 'energy-temperature').length;
|
|
714
|
+
const nEnergy = config.smarthome.filter((s) => s.accType === 'energy-temperature').length;
|
|
715
|
+
const nRouter = Object.keys((config.devices[0] && config.devices[0].options) || {}).length;
|
|
716
|
+
|
|
717
|
+
// Mask password in preview for safety
|
|
718
|
+
const maskedConfig = JSON.parse(JSON.stringify(config));
|
|
719
|
+
if (maskedConfig.devices[0] && maskedConfig.devices[0].password) {
|
|
720
|
+
maskedConfig.devices[0].password = '••••••••';
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
summary.innerHTML = `
|
|
724
|
+
<div class="device-card">
|
|
725
|
+
<div style="font-weight: 600;">📦 Konfigurations-Zusammenfassung</div>
|
|
726
|
+
<ul style="margin-top: 0.5rem; margin-bottom: 0;">
|
|
727
|
+
<li><strong>FritzBox:</strong> ${escapeHtml(config.devices[0].host)} (User: ${escapeHtml(config.devices[0].username)})</li>
|
|
728
|
+
<li><strong>${nDevices}</strong> Smart-Home-Gerät(e) (Thermostate, Lampen, Sensoren, Schalter)</li>
|
|
729
|
+
<li><strong>${nEnergy}</strong> Energy-Tile(s) für FRITZ!Smart Energy 250 OBIS-Reader</li>
|
|
730
|
+
<li><strong>${nRouter}</strong> Router-Switch(es) als HomeKit-Tiles</li>
|
|
731
|
+
</ul>
|
|
732
|
+
</div>
|
|
733
|
+
`;
|
|
734
|
+
|
|
735
|
+
preview.textContent = JSON.stringify(maskedConfig, null, 2);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
const saveBtn = document.getElementById('saveBtn');
|
|
739
|
+
saveBtn.addEventListener('click', async () => {
|
|
740
|
+
const saveResult = document.getElementById('saveResult');
|
|
741
|
+
saveResult.innerHTML = '';
|
|
742
|
+
saveBtn.disabled = true;
|
|
743
|
+
saveBtn.innerHTML = '<span class="spinner-border spinner-border-sm"></span> Speichere…';
|
|
744
|
+
|
|
745
|
+
try {
|
|
746
|
+
const newConfig = buildPluginConfig();
|
|
747
|
+
|
|
748
|
+
// homebridge.updatePluginConfig expects an array of platform config objects
|
|
749
|
+
// (one plugin can register multiple platform instances, but ours is singular)
|
|
750
|
+
await homebridge.updatePluginConfig([newConfig]);
|
|
751
|
+
|
|
752
|
+
// Persist the in-memory config to disk. In standalone mode (running
|
|
753
|
+
// homebridge-config-ui-x standalone.js without hb-service), this can
|
|
754
|
+
// sometimes hang because the websocket ACK isn't sent. Race with a
|
|
755
|
+
// 3-second timeout so the UI doesn't freeze forever — the file is
|
|
756
|
+
// already written synchronously by the time savePluginConfig returns.
|
|
757
|
+
await Promise.race([
|
|
758
|
+
homebridge.savePluginConfig(),
|
|
759
|
+
new Promise((resolve) => setTimeout(resolve, 3000)),
|
|
760
|
+
]);
|
|
761
|
+
|
|
762
|
+
saveResult.innerHTML = `
|
|
763
|
+
<div class="alert alert-success">
|
|
764
|
+
<strong>✓ Konfiguration gespeichert.</strong><br>
|
|
765
|
+
Damit die Änderungen wirksam werden, muss Homebridge neu gestartet werden.
|
|
766
|
+
</div>
|
|
767
|
+
<div class="text-center" style="margin-top: 1rem;">
|
|
768
|
+
<button id="restartBtn" class="btn btn-warning btn-lg">🔄 Homebridge jetzt neu starten</button>
|
|
769
|
+
<div style="margin-top: 0.5rem;">
|
|
770
|
+
<small class="text-muted">Alternativ später via Config UI X "Restart"-Button.</small>
|
|
771
|
+
</div>
|
|
772
|
+
</div>
|
|
773
|
+
`;
|
|
774
|
+
|
|
775
|
+
document.getElementById('restartBtn').addEventListener('click', async () => {
|
|
776
|
+
try {
|
|
777
|
+
await homebridge.restartHomebridge();
|
|
778
|
+
} catch (err) {
|
|
779
|
+
// If restartHomebridge isn't available (e.g. standalone mode without
|
|
780
|
+
// hb-service), show a manual instruction.
|
|
781
|
+
saveResult.innerHTML +=
|
|
782
|
+
'<div class="alert alert-info" style="margin-top: 1rem;">' +
|
|
783
|
+
'Automatischer Restart nicht verfügbar. Bitte Homebridge manuell ' +
|
|
784
|
+
'neu starten: <code>sudo hb-service restart</code> oder über die ' +
|
|
785
|
+
'Config UI X Toolbar.' +
|
|
786
|
+
'</div>';
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
} catch (err) {
|
|
790
|
+
saveResult.innerHTML = `
|
|
791
|
+
<div class="alert alert-danger">
|
|
792
|
+
<strong>Fehler beim Speichern:</strong> ${escapeHtml(err.message || String(err))}
|
|
793
|
+
</div>
|
|
794
|
+
`;
|
|
795
|
+
} finally {
|
|
796
|
+
saveBtn.disabled = false;
|
|
797
|
+
saveBtn.innerHTML = '💾 Konfiguration speichern';
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
// ============ Step 4 — Router Switches ============
|
|
802
|
+
// Pre-fill checkboxes from existing master.options (if user is editing
|
|
803
|
+
// an existing config) and wire up change handlers to wizardState.
|
|
804
|
+
function hydrateRouterSwitches() {
|
|
805
|
+
// Read existing config to pre-check anything that was on before
|
|
806
|
+
(async () => {
|
|
807
|
+
try {
|
|
808
|
+
const allConfig = await homebridge.getPluginConfig();
|
|
809
|
+
const fritz = (allConfig || []).find((c) => c && c.platform === 'FritzPlatform');
|
|
810
|
+
const master = fritz && fritz.devices && fritz.devices.find((d) => d.master === true);
|
|
811
|
+
const opts = master && master.options;
|
|
812
|
+
|
|
813
|
+
document.querySelectorAll('.router-switch').forEach((cb) => {
|
|
814
|
+
const key = cb.getAttribute('data-key');
|
|
815
|
+
// If wizardState already has a value (user navigated back), use that
|
|
816
|
+
if (typeof wizardState.routerSwitches[key] === 'boolean') {
|
|
817
|
+
cb.checked = wizardState.routerSwitches[key];
|
|
818
|
+
} else if (opts && opts[key] === 'switch') {
|
|
819
|
+
cb.checked = true;
|
|
820
|
+
wizardState.routerSwitches[key] = true;
|
|
821
|
+
} else {
|
|
822
|
+
wizardState.routerSwitches[key] = false;
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
} catch (err) {
|
|
826
|
+
// No existing config — nothing to prefill, all stay unchecked.
|
|
827
|
+
}
|
|
828
|
+
})();
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
document.querySelectorAll('.router-switch').forEach((cb) => {
|
|
832
|
+
cb.addEventListener('change', () => {
|
|
833
|
+
const key = cb.getAttribute('data-key');
|
|
834
|
+
wizardState.routerSwitches[key] = cb.checked;
|
|
835
|
+
});
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
// ============ Step 3 — Energy 250 Special Path ============
|
|
839
|
+
function renderEnergy250() {
|
|
840
|
+
const container = document.getElementById('energy250Content');
|
|
841
|
+
|
|
842
|
+
// Find all OBIS sub-AINs the user selected as energy-temperature
|
|
843
|
+
const obisSelections = Object.entries(wizardState.deviceSelections)
|
|
844
|
+
.filter(([ain, sel]) => sel.include && sel.accType === 'energy-temperature' && /-[12]$/.test(ain));
|
|
845
|
+
|
|
846
|
+
if (obisSelections.length === 0) {
|
|
847
|
+
container.innerHTML =
|
|
848
|
+
'<div class="alert alert-secondary">' +
|
|
849
|
+
'Keine OBIS-Sub-AINs in der Geräte-Auswahl gefunden. ' +
|
|
850
|
+
'Falls du eine FRITZ!Smart Energy 250 hast und in Schritt 2 ' +
|
|
851
|
+
'die Sub-AINs (z.B. <code>XYZ-1</code> und <code>XYZ-2</code>) als ' +
|
|
852
|
+
'<em>Energy-Reader</em> markiert hast, erscheinen sie hier. ' +
|
|
853
|
+
'Sonst direkt weiter zu Schritt 4.' +
|
|
854
|
+
'</div>';
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// Group OBIS sub-AINs by their base AIN
|
|
859
|
+
const byBase = {};
|
|
860
|
+
for (const [ain, sel] of obisSelections) {
|
|
861
|
+
const baseAin = ain.replace(/-[12]$/, '');
|
|
862
|
+
const suffix = ain.endsWith('-1') ? 1 : 2;
|
|
863
|
+
if (!byBase[baseAin]) byBase[baseAin] = { ain1: null, ain2: null };
|
|
864
|
+
if (suffix === 1) byBase[baseAin].ain1 = { ain, name: sel.name };
|
|
865
|
+
else byBase[baseAin].ain2 = { ain, name: sel.name };
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// Default tile names per direction
|
|
869
|
+
const defaultNames = {
|
|
870
|
+
'-1': { current_power: 'Aktueller Verbrauch', total_energy: 'Gesamt Verbrauch' },
|
|
871
|
+
'-2': { current_power: 'Aktuelle Einspeisung', total_energy: 'Gesamt Einspeisung' },
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
// Initialize state for each OBIS AIN if not already there
|
|
875
|
+
for (const baseAin of Object.keys(byBase)) {
|
|
876
|
+
const group = byBase[baseAin];
|
|
877
|
+
for (const dir of ['-1', '-2']) {
|
|
878
|
+
const entry = dir === '-1' ? group.ain1 : group.ain2;
|
|
879
|
+
if (!entry) continue;
|
|
880
|
+
if (!wizardState.energyTiles[entry.ain]) {
|
|
881
|
+
wizardState.energyTiles[entry.ain] = [
|
|
882
|
+
{ obisChannel: 'current_power', name: defaultNames[dir].current_power },
|
|
883
|
+
{ obisChannel: 'total_energy', name: defaultNames[dir].total_energy },
|
|
884
|
+
];
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// Render each OBIS reader as a card
|
|
890
|
+
const html = Object.entries(byBase).map(([baseAin, group]) => {
|
|
891
|
+
const hasConsumption = !!group.ain1;
|
|
892
|
+
const hasFeedIn = !!group.ain2;
|
|
893
|
+
|
|
894
|
+
let warningHtml = '';
|
|
895
|
+
if (!hasConsumption || !hasFeedIn) {
|
|
896
|
+
warningHtml =
|
|
897
|
+
'<div class="alert alert-warning" style="margin-top: 0.5rem;">' +
|
|
898
|
+
'<strong>Hinweis:</strong> Nur ' +
|
|
899
|
+
(hasConsumption ? 'die Bezugs-Richtung (-1)' : 'die Einspeisungs-Richtung (-2)') +
|
|
900
|
+
' ist konfiguriert. Bei PV-Anlagen sind normalerweise beide Richtungen vorhanden. ' +
|
|
901
|
+
'Falls die andere Seite auch da sein soll: zurück zu Schritt 2, dort beide Sub-AINs ' +
|
|
902
|
+
'als <em>Energy-Reader</em> markieren.' +
|
|
903
|
+
'</div>';
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
const buildTileRow = (entry, dir) => {
|
|
907
|
+
if (!entry) return '';
|
|
908
|
+
const tiles = wizardState.energyTiles[entry.ain] || [];
|
|
909
|
+
return tiles.map((tile, idx) => {
|
|
910
|
+
const unit = tile.obisChannel === 'current_power' ? 'W' : 'kWh';
|
|
911
|
+
const channelLabel = tile.obisChannel === 'current_power' ? 'momentan' : 'kumuliert';
|
|
912
|
+
return `
|
|
913
|
+
<div class="form-row" style="display: flex; gap: 0.75rem; align-items: end;">
|
|
914
|
+
<div style="flex: 1;">
|
|
915
|
+
<label style="font-size: 0.85rem;">Tile-Name (${channelLabel}, ${unit})</label>
|
|
916
|
+
<input type="text" class="form-control form-control-sm energy-tile-name"
|
|
917
|
+
data-ain="${entry.ain}" data-idx="${idx}"
|
|
918
|
+
value="${escapeHtml(tile.name)}">
|
|
919
|
+
</div>
|
|
920
|
+
<div style="min-width: 110px; text-align: right; font-size: 0.85rem; color: #6c757d; padding-bottom: 0.5rem;">
|
|
921
|
+
${tile.obisChannel} (${unit})
|
|
922
|
+
</div>
|
|
923
|
+
</div>
|
|
924
|
+
`;
|
|
925
|
+
}).join('');
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
return `
|
|
929
|
+
<div class="device-card" style="margin-bottom: 1.5rem;">
|
|
930
|
+
<div style="font-weight: 600; margin-bottom: 0.5rem;">
|
|
931
|
+
OBIS-Reader: <code>${baseAin}</code>
|
|
932
|
+
</div>
|
|
933
|
+
${warningHtml}
|
|
934
|
+
${hasConsumption ? `
|
|
935
|
+
<div style="margin-top: 0.75rem;">
|
|
936
|
+
<div style="font-weight: 500; color: #198754;">📥 Bezug (Sub-AIN ${group.ain1.ain})</div>
|
|
937
|
+
<small class="text-muted">${escapeHtml(group.ain1.name)}</small>
|
|
938
|
+
${buildTileRow(group.ain1, '-1')}
|
|
939
|
+
</div>
|
|
940
|
+
` : ''}
|
|
941
|
+
${hasFeedIn ? `
|
|
942
|
+
<div style="margin-top: 0.75rem;">
|
|
943
|
+
<div style="font-weight: 500; color: #6610f2;">📤 Einspeisung (Sub-AIN ${group.ain2.ain})</div>
|
|
944
|
+
<small class="text-muted">${escapeHtml(group.ain2.name)}</small>
|
|
945
|
+
${buildTileRow(group.ain2, '-2')}
|
|
946
|
+
</div>
|
|
947
|
+
` : ''}
|
|
948
|
+
</div>
|
|
949
|
+
`;
|
|
950
|
+
}).join('');
|
|
951
|
+
|
|
952
|
+
container.innerHTML =
|
|
953
|
+
'<div class="alert alert-success">' +
|
|
954
|
+
'<strong>✓ ' + Object.keys(byBase).length + ' OBIS-Reader erkannt</strong><br>' +
|
|
955
|
+
'Pro Sub-AIN werden 2 Tiles angelegt (aktuelle Leistung in W + kumulierte Energie in kWh). ' +
|
|
956
|
+
'Du kannst die Tile-Namen unten anpassen. Apple Home zeigt °C als Einheit, der Zahlenwert ist aber W bzw. kWh.' +
|
|
957
|
+
'</div>' +
|
|
958
|
+
html;
|
|
959
|
+
|
|
960
|
+
// Wire up name-input change handlers
|
|
961
|
+
container.querySelectorAll('.energy-tile-name').forEach((input) => {
|
|
962
|
+
input.addEventListener('input', () => {
|
|
963
|
+
const ain = input.getAttribute('data-ain');
|
|
964
|
+
const idx = parseInt(input.getAttribute('data-idx'), 10);
|
|
965
|
+
if (wizardState.energyTiles[ain] && wizardState.energyTiles[ain][idx]) {
|
|
966
|
+
wizardState.energyTiles[ain][idx].name = input.value;
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
})();
|
|
972
|
+
</script>
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom UI Server for @pellebot/homebridge-fritz-platform-hb2
|
|
5
|
+
*
|
|
6
|
+
* Runs inside Homebridge Config UI X when the user opens the plugin's
|
|
7
|
+
* settings page. Exposes endpoints that the frontend in public/index.html
|
|
8
|
+
* calls via window.homebridge.request(endpoint, payload).
|
|
9
|
+
*
|
|
10
|
+
* Endpoints:
|
|
11
|
+
* /ping — server health check (returns plugin metadata)
|
|
12
|
+
* /test-connection — verify TR-064 + AHA-API reachability of a FritzBox
|
|
13
|
+
* /discover-devices — list smart-home devices with auto-detected accType
|
|
14
|
+
*
|
|
15
|
+
* Later phases will add:
|
|
16
|
+
* /probe-energy-250 — group HAN-FUN OBIS sub-AINs into Energy 250 setup
|
|
17
|
+
* /save-config — persist the wizard output back to config.json
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const { HomebridgePluginUiServer } = require('@homebridge/plugin-ui-utils');
|
|
21
|
+
const { version } = require('../package.json');
|
|
22
|
+
const Fritzbox = require('@seydx/fritzbox');
|
|
23
|
+
|
|
24
|
+
class UiServer extends HomebridgePluginUiServer {
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
|
|
28
|
+
this.onRequest('/ping', () => this.handlePing());
|
|
29
|
+
this.onRequest('/test-connection', (payload) => this.handleTestConnection(payload));
|
|
30
|
+
this.onRequest('/discover-devices', (payload) => this.handleDiscoverDevices(payload));
|
|
31
|
+
|
|
32
|
+
this.ready();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async handlePing() {
|
|
36
|
+
return {
|
|
37
|
+
ok: true,
|
|
38
|
+
plugin: '@pellebot/homebridge-fritz-platform-hb2',
|
|
39
|
+
version,
|
|
40
|
+
timestamp: new Date().toISOString(),
|
|
41
|
+
message: 'Custom UI server is alive.',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
makeFritzbox(payload) {
|
|
46
|
+
return new Fritzbox({
|
|
47
|
+
host: payload.host,
|
|
48
|
+
port: parseInt(payload.port, 10) > 0 ? parseInt(payload.port, 10) : 49000,
|
|
49
|
+
username: payload.username,
|
|
50
|
+
password: payload.password,
|
|
51
|
+
ssl: payload.ssl !== false,
|
|
52
|
+
tr064: payload.tr064 !== false,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async handleTestConnection(payload = {}) {
|
|
57
|
+
if (!payload.host || !payload.username || !payload.password) {
|
|
58
|
+
return { ok: false, error: 'Host, Username und Password sind Pflichtfelder.' };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const fb = this.makeFritzbox(payload);
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const list = await fb.getSmarthomeDevices();
|
|
65
|
+
const devices = (list && list.devices) || [];
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
ok: true,
|
|
69
|
+
message: `Verbindung erfolgreich. ${devices.length} Smart-Home-Gerät(e) auf der FritzBox gefunden.`,
|
|
70
|
+
deviceCount: devices.length,
|
|
71
|
+
productNames: [...new Set(devices.map((d) => d.productname).filter(Boolean))],
|
|
72
|
+
};
|
|
73
|
+
} catch (err) {
|
|
74
|
+
return this.formatConnectionError(err);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
formatConnectionError(err) {
|
|
79
|
+
const code = err && err.code;
|
|
80
|
+
let hint = '';
|
|
81
|
+
if (code === 'ECONNREFUSED') {
|
|
82
|
+
hint = ' Tipp: TR-064-Zugriff in der FritzBox-UI unter Heimnetz → Netzwerk → Netzwerkeinstellungen aktivieren.';
|
|
83
|
+
} else if (code === 'ENETUNREACH' || code === 'EHOSTUNREACH') {
|
|
84
|
+
hint = ' Tipp: Host-Adresse stimmt nicht — ist die FritzBox unter dieser IP erreichbar (Ping testen)?';
|
|
85
|
+
} else if (code === 'ETIMEDOUT') {
|
|
86
|
+
hint = ' Tipp: Network-Firewall blockiert Port? Standardports sind 49000 (HTTP) und 49443 (HTTPS).';
|
|
87
|
+
} else if (err && err.message && /401|unauthor/i.test(err.message)) {
|
|
88
|
+
hint = ' Tipp: User oder Passwort stimmen nicht. FritzBox-User braucht "Smart Home"-Berechtigung.';
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
error: (err && err.message) || String(err),
|
|
93
|
+
code: code || null,
|
|
94
|
+
hint,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Discover all smart-home devices on the FritzBox and infer a recommended
|
|
100
|
+
* accType per device, plus a list of supporting feature flags so the
|
|
101
|
+
* frontend can render appropriate conditional checkboxes (temperature,
|
|
102
|
+
* window, battery, brightness, color).
|
|
103
|
+
*
|
|
104
|
+
* Detection rules (priority order):
|
|
105
|
+
* 1. device has .hkr → 'thermostat'
|
|
106
|
+
* 2. device has .colorcontrol or .levelcontrol → 'lightbulb'
|
|
107
|
+
* 3. device has .switch + .powermeter → 'switch' with energy
|
|
108
|
+
* 4. device has .switch → 'switch'
|
|
109
|
+
* 5. AIN ends with -1 or -2 (OBIS sub-AIN) → 'energy-temperature'
|
|
110
|
+
* 6. device has .powermeter (no switch, e.g. HAN-FUN gateway base)
|
|
111
|
+
* → mark as 'skip' (group with OBIS)
|
|
112
|
+
* 7. device has .alarm → 'contact' (window/door)
|
|
113
|
+
* 8. device has .temperature → 'temperature'
|
|
114
|
+
* 9. else → 'unknown' (mark inactive)
|
|
115
|
+
*/
|
|
116
|
+
detectAccType(d) {
|
|
117
|
+
// @seydx/fritzbox normalizes AVM AHA device structure as follows:
|
|
118
|
+
// d.thermostat = { current, target, windowOpen } or false
|
|
119
|
+
// d.light = { state, brightness, color } or false
|
|
120
|
+
// d.switch = { state, mode, lock, devicelock } or false
|
|
121
|
+
// d.powermeter = { power, energy, voltage } or false
|
|
122
|
+
// d.temperature = { value, offset } or false
|
|
123
|
+
// d.humidity = { value } or false
|
|
124
|
+
// d.button = { name, ... } or false
|
|
125
|
+
// d.blind = { ... } or false
|
|
126
|
+
// d.battery = { value, low } or false
|
|
127
|
+
// d.alert = (boolean) — alarm sensor triggered
|
|
128
|
+
//
|
|
129
|
+
// Always-present keys; missing-feature is signaled by `false` (not absence).
|
|
130
|
+
const ainSuffix = (d.ain || '').match(/-([12])$/);
|
|
131
|
+
const isObj = (x) => x && typeof x === 'object';
|
|
132
|
+
|
|
133
|
+
const flags = {
|
|
134
|
+
hasThermostat: isObj(d.thermostat),
|
|
135
|
+
hasLight: isObj(d.light),
|
|
136
|
+
hasSwitch: isObj(d.switch),
|
|
137
|
+
hasPowermeter: isObj(d.powermeter),
|
|
138
|
+
hasTemperature: isObj(d.temperature),
|
|
139
|
+
hasHumidity: isObj(d.humidity),
|
|
140
|
+
hasButton: isObj(d.button),
|
|
141
|
+
hasBlind: isObj(d.blind),
|
|
142
|
+
hasBattery: isObj(d.battery),
|
|
143
|
+
hasAlert: d.alert === true,
|
|
144
|
+
hasColorcontrol: !!(d.light && d.light.color),
|
|
145
|
+
hasLevelcontrol: !!(d.light && d.light.brightness),
|
|
146
|
+
isObisSubain: !!ainSuffix,
|
|
147
|
+
obisDirection: ainSuffix ? (ainSuffix[1] === '1' ? 'consumption' : 'feed-in') : null,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Priority order: physical features take precedence over the AIN -1/-2
|
|
151
|
+
// suffix. DECT 500 lightbulbs and other HAN-FUN sub-units also use the
|
|
152
|
+
// -1 suffix even though they are not OBIS readers.
|
|
153
|
+
let accType = 'unknown';
|
|
154
|
+
let reasonDe = 'Gerätetyp nicht eindeutig erkannt';
|
|
155
|
+
|
|
156
|
+
if (flags.hasThermostat) {
|
|
157
|
+
accType = 'thermostat';
|
|
158
|
+
reasonDe = 'Heizkörper-Thermostat (HKR)';
|
|
159
|
+
} else if (flags.hasLight) {
|
|
160
|
+
accType = 'lightbulb';
|
|
161
|
+
const extras = [];
|
|
162
|
+
if (flags.hasColorcontrol) extras.push('Farbe');
|
|
163
|
+
if (flags.hasLevelcontrol) extras.push('Helligkeit');
|
|
164
|
+
reasonDe = 'DECT-Lampe' + (extras.length ? ' (' + extras.join(' + ') + ')' : '');
|
|
165
|
+
} else if (flags.hasSwitch && flags.hasPowermeter) {
|
|
166
|
+
accType = 'switch';
|
|
167
|
+
reasonDe = 'Schaltbare Steckdose mit Energiemessung';
|
|
168
|
+
} else if (flags.hasSwitch) {
|
|
169
|
+
accType = 'switch';
|
|
170
|
+
reasonDe = 'Schaltbare Steckdose';
|
|
171
|
+
} else if (flags.hasBlind) {
|
|
172
|
+
accType = 'blind';
|
|
173
|
+
reasonDe = 'Rolllade';
|
|
174
|
+
} else if (flags.isObisSubain && flags.hasPowermeter) {
|
|
175
|
+
// OBIS sub-AIN of a Smart Energy 250 reader: powermeter present, no
|
|
176
|
+
// other interactive features. Recommend energy-temperature so Apple
|
|
177
|
+
// Home shows the numeric values natively.
|
|
178
|
+
accType = 'energy-temperature';
|
|
179
|
+
reasonDe = `OBIS-Reader Sub-AIN (${flags.obisDirection === 'consumption' ? 'Bezug 1.x' : 'Einspeisung 2.x'}) — 4-Tiles-Setup in Schritt 3`;
|
|
180
|
+
} else if (flags.hasButton) {
|
|
181
|
+
accType = 'button';
|
|
182
|
+
reasonDe = 'DECT-Taster';
|
|
183
|
+
} else if (flags.hasAlert) {
|
|
184
|
+
accType = 'contact';
|
|
185
|
+
reasonDe = 'Alarm-/Fenster-Sensor';
|
|
186
|
+
} else if (flags.hasTemperature) {
|
|
187
|
+
accType = 'temperature';
|
|
188
|
+
reasonDe = 'Temperatur-Sensor';
|
|
189
|
+
} else if (flags.hasPowermeter) {
|
|
190
|
+
// HAN-FUN gateway base AIN (no sub-AIN) — typically the Smart Energy 250 base.
|
|
191
|
+
accType = 'skip';
|
|
192
|
+
reasonDe = 'HAN-FUN-Gateway (z.B. Smart Energy 250 Basis) — wird in Schritt 3 verarbeitet';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return { accType, reasonDe, flags };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async handleDiscoverDevices(payload = {}) {
|
|
199
|
+
if (!payload.host || !payload.username || !payload.password) {
|
|
200
|
+
return { ok: false, error: 'Host, Username und Password sind Pflichtfelder.' };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const fb = this.makeFritzbox(payload);
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
const list = await fb.getSmarthomeDevices();
|
|
207
|
+
const rawDevices = (list && list.devices) || [];
|
|
208
|
+
|
|
209
|
+
const devices = rawDevices.map((d) => {
|
|
210
|
+
const detection = this.detectAccType(d);
|
|
211
|
+
return {
|
|
212
|
+
ain: d.ain,
|
|
213
|
+
name: d.name,
|
|
214
|
+
productname: d.productname || '',
|
|
215
|
+
functionbitmask: d.functionbitmask || null,
|
|
216
|
+
online: d.online !== false,
|
|
217
|
+
...detection,
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
ok: true,
|
|
223
|
+
message: `${devices.length} Gerät(e) gefunden.`,
|
|
224
|
+
devices,
|
|
225
|
+
};
|
|
226
|
+
} catch (err) {
|
|
227
|
+
return this.formatConnectionError(err);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
(() => new UiServer())();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pellebot/homebridge-fritz-platform-hb2",
|
|
3
3
|
"displayName": "Homebridge FRITZ!Box Platform (HB2)",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"description": "Homebridge 2.0 plugin for AVM FRITZ!DECT devices (thermostats, lamps, sensors, OBIS smart-meter readers) and FRITZ!Box router switches (Guest WLAN, WPS). Node 22 / 24 ready.",
|
|
6
6
|
"icon": "https://raw.githubusercontent.com/PelleBot/homebridge-fritz-platform-ng/main/branding/Icon.png",
|
|
7
7
|
"type": "module",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"homebridge": "^1.6.0 || ^2.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@homebridge/plugin-ui-utils": "^2.0.0",
|
|
52
53
|
"@seydx/fritzbox": "^2.3.1",
|
|
53
54
|
"fakegato-history": "0.6.2",
|
|
54
55
|
"form-data": "^4.0.0",
|