Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
334 lines (289 loc) · 11 KB
/
Copy pathindex.html
File metadata and controls
334 lines (289 loc) · 11 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Siedle QR-Code Scanner</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
max-width: 500px;
width: 100%;
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 24px;
margin-bottom: 10px;
}
.header p {
font-size: 14px;
opacity: 0.9;
}
.content {
padding: 30px;
}
#qr-reader {
width: 100%;
border-radius: 10px;
overflow: hidden;
background: #f0f0f0;
position: relative;
}
#qr-reader video {
width: 100%;
height: auto;
display: block;
}
.status {
margin-top: 20px;
padding: 15px;
border-radius: 10px;
text-align: center;
font-size: 14px;
}
.status.info {
background: #e3f2fd;
color: #1976d2;
}
.status.success {
background: #e8f5e9;
color: #388e3c;
}
.status.error {
background: #ffebee;
color: #d32f2f;
}
.status.warning {
background: #fff3e0;
color: #f57c00;
}
.spinner {
border: 3px solid #f3f3f3;
border-top: 3px solid #667eea;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 3px solid #667eea;
border-radius: 10px;
pointer-events: none;
}
.scan-line {
position: absolute;
width: 100%;
height: 2px;
background: linear-gradient(90deg, transparent, #667eea, transparent);
animation: scan 2s linear infinite;
}
@keyframes scan {
0% { top: 0; }
100% { top: 100%; }
}
button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 12px 30px;
border-radius: 25px;
font-size: 16px;
cursor: pointer;
margin-top: 15px;
width: 100%;
transition: transform 0.2s;
}
button:hover {
transform: translateY(-2px);
}
button:active {
transform: translateY(0);
}
button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔐 Siedle QR-Code Scanner</h1>
<p>Scannen Sie Ihren Siedle QR-Code</p>
</div>
<div class="content">
<div id="qr-reader"></div>
<div id="status" class="status info">
<div class="spinner"></div>
Kamera wird initialisiert...
</div>
<button id="retry-btn" style="display: none;">Erneut versuchen</button>
</div>
</div>
<script src="https://unpkg.com/html5-qrcode@2.3.8/html5-qrcode.min.js"></script>
<script>
// URL Parameter auslesen
const urlParams = new URLSearchParams(window.location.search);
const configFlowId = urlParams.get('config_flow_id');
const callbackUrl = urlParams.get('callback_url');
const statusDiv = document.getElementById('status');
const retryBtn = document.getElementById('retry-btn');
let html5QrCode = null;
let isScanning = false;
function updateStatus(message, type = 'info', showSpinner = false) {
statusDiv.className = `status ${type}`;
statusDiv.innerHTML = showSpinner
? `<div class="spinner"></div>${message}`
: message;
}
function onScanSuccess(decodedText, decodedResult) {
if (isScanning) {
return; // Verhindere mehrfache Scans
}
isScanning = true;
updateStatus('✅ QR-Code erfolgreich gescannt!', 'success');
// Scanner stoppen
html5QrCode.stop().then(() => {
// Zu Home Assistant weiterleiten
if (callbackUrl && configFlowId) {
updateStatus('🔄 Weiterleitung zu Home Assistant...', 'info', true);
// URL-encode den QR-Code Inhalt
const encodedResult = encodeURIComponent(decodedText);
const redirectUrl = `${callbackUrl}?config_flow_id=${configFlowId}&result=${encodedResult}`;
setTimeout(() => {
window.location.href = redirectUrl;
}, 1000);
} else {
updateStatus('❌ Fehlende Parameter: callback_url oder config_flow_id', 'error');
retryBtn.style.display = 'block';
}
}).catch(err => {
console.error('Error stopping scanner:', err);
});
}
function onScanError(errorMessage) {
// Ignoriere normale Scan-Fehler (keine QR-Code gefunden)
// Diese werden bei jedem Frame ausgelöst, wenn kein Code gefunden wird
}
function startScanner() {
// Parameter prüfen
if (!callbackUrl || !configFlowId) {
updateStatus('❌ Fehler: Fehlende URL-Parameter (callback_url oder config_flow_id)', 'error');
retryBtn.style.display = 'block';
return;
}
updateStatus('📷 Kameraberechtigung wird angefordert...', 'info', true);
retryBtn.style.display = 'none';
html5QrCode = new Html5Qrcode("qr-reader");
// Kamera-Konfiguration: Bevorzuge rückwärtige Kamera
const config = {
fps: 10,
qrbox: { width: 250, height: 250 },
aspectRatio: 1.0
};
// Versuche zuerst die rückwärtige Kamera
html5QrCode.start(
{ facingMode: "environment" },
config,
onScanSuccess,
onScanError
).then(() => {
updateStatus('📸 Bereit zum Scannen - Halten Sie den QR-Code vor die Kamera', 'info');
// Scan-Animation hinzufügen
const reader = document.getElementById('qr-reader');
const overlay = document.createElement('div');
overlay.className = 'overlay';
const scanLine = document.createElement('div');
scanLine.className = 'scan-line';
overlay.appendChild(scanLine);
reader.appendChild(overlay);
}).catch(err => {
console.error('Camera error:', err);
// Fallback: Versuche irgendeine Kamera
Html5Qrcode.getCameras().then(cameras => {
if (cameras && cameras.length > 0) {
updateStatus('🔄 Starte Kamera...', 'warning', true);
// Verwende die erste verfügbare Kamera
html5QrCode.start(
cameras[0].id,
config,
onScanSuccess,
onScanError
).then(() => {
updateStatus('📸 Bereit zum Scannen - Halten Sie den QR-Code vor die Kamera', 'info');
const reader = document.getElementById('qr-reader');
const overlay = document.createElement('div');
overlay.className = 'overlay';
const scanLine = document.createElement('div');
scanLine.className = 'scan-line';
overlay.appendChild(scanLine);
reader.appendChild(overlay);
}).catch(err2 => {
console.error('Fallback camera error:', err2);
updateStatus('❌ Kamera konnte nicht gestartet werden. Bitte erlauben Sie den Kamerazugriff.', 'error');
retryBtn.style.display = 'block';
});
} else {
updateStatus('❌ Keine Kamera gefunden', 'error');
retryBtn.style.display = 'block';
}
}).catch(err2 => {
console.error('Get cameras error:', err2);
updateStatus('❌ Fehler beim Zugriff auf die Kamera: ' + err2, 'error');
retryBtn.style.display = 'block';
});
});
}
// Retry Button
retryBtn.addEventListener('click', () => {
isScanning = false;
if (html5QrCode) {
html5QrCode.stop().then(() => {
startScanner();
}).catch(() => {
startScanner();
});
} else {
startScanner();
}
});
// Automatisch starten wenn Seite geladen ist
window.addEventListener('load', () => {
setTimeout(startScanner, 500);
});
</script>
</body>
</html>