-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator-hmi-card.js
More file actions
768 lines (691 loc) · 26 KB
/
generator-hmi-card.js
File metadata and controls
768 lines (691 loc) · 26 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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
/**
* Generator HMI Card - ISA-101 High Performance Design
* Based on ISA-101 Human Machine Interface standards
*
* @version 2.2.0
* @author Claude Code
*/
const CARD_VERSION = '2.3.2';
console.info(
`%c GENERATOR-HMI-CARD %c v${CARD_VERSION} %c ISA-101 `,
'color: #333; font-weight: bold; background: #d0d0d0',
'color: #d0d0d0; font-weight: bold; background: #333',
'color: #fff; font-weight: bold; background: #0066cc'
);
class GeneratorHMICard extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this._config = {};
this._hass = null;
this._initialized = false;
this._entityStates = {};
}
set hass(hass) {
this._hass = hass;
if (this._initialized) {
this._updateValues();
} else {
this._buildCard();
this._initialized = true;
}
}
setConfig(config) {
// Build entity prefixes from device_name if provided
let entityPrefix = 'sensor.generator_';
let buttonPrefix = 'button.generator_';
if (config.device_name) {
const normalizedName = config.device_name.toLowerCase().replace(/\s+/g, '_');
entityPrefix = `sensor.${normalizedName}_`;
buttonPrefix = `button.${normalizedName}_`;
}
this._config = {
title: 'GENERATOR',
entity_prefix: entityPrefix,
button_prefix: buttonPrefix,
show_controls: true,
show_maintenance: true,
// Setpoints for analog indicators
voltage_nominal: 240,
voltage_min: 220,
voltage_max: 260,
frequency_nominal: 60,
frequency_min: 59,
frequency_max: 61,
battery_nominal: 13.2,
battery_min: 11.5,
battery_max: 14.5,
...config,
};
// Re-apply device_name derived prefixes if not explicitly overridden
if (config.device_name && !config.entity_prefix) {
this._config.entity_prefix = entityPrefix;
}
if (config.device_name && !config.button_prefix) {
this._config.button_prefix = buttonPrefix;
}
this._initialized = false;
}
getCardSize() { return 6; }
static getStubConfig() {
return {
title: 'GENERATOR',
device_name: 'generator',
};
}
_getState(entitySuffix) {
const entityId = this._config.entity_prefix + entitySuffix;
return this._hass?.states[entityId]?.state || '--';
}
_getButtonEntity(buttonSuffix) {
return this._config.button_prefix + buttonSuffix;
}
_handleButtonClick(buttonEntity, confirmText) {
if (confirm(confirmText)) {
this._hass.callService('button', 'press', { entity_id: buttonEntity });
}
}
_showMoreInfo(entitySuffix) {
const entityId = this._config.entity_prefix + entitySuffix;
const event = new CustomEvent('hass-more-info', {
bubbles: true,
composed: true,
detail: { entityId }
});
this.dispatchEvent(event);
}
// ISA-101: Determine status level (0=normal, 1=abnormal, 2=warning, 3=alarm)
_getEngineStatus() {
const state = this._getState('engine_state').toLowerCase();
if (state.includes('alarm') || state.includes('fault')) return { level: 3, text: 'ALARM' };
if (state.includes('running')) return { level: 1, text: 'RUNNING' };
if (state.includes('ready') || state.includes('off') || state.includes('standby')) return { level: 0, text: 'STANDBY' };
return { level: 0, text: state.toUpperCase() };
}
_getOutageStatus() {
const state = this._getState('system_in_outage').toLowerCase();
if (state === 'yes' || state === 'true' || state === 'on' || (state.includes('outage') && !state.includes('no'))) {
return { level: 3, text: 'OUTAGE' };
}
return { level: 0, text: 'NORMAL' };
}
_getSwitchStatus() {
const state = this._getState('switch_state').toLowerCase();
if (state.includes('generator')) return { level: 1, text: 'GENERATOR' };
return { level: 0, text: 'UTILITY' };
}
// Calculate bar percentage and status for analog values
_getAnalogStatus(value, min, nominal, max) {
const num = parseFloat(value);
if (isNaN(num)) return { percent: 0, level: 0 };
const range = max - min;
const percent = Math.max(0, Math.min(100, ((num - min) / range) * 100));
// Determine status based on deviation from nominal
const lowWarn = min + (nominal - min) * 0.3;
const highWarn = nominal + (max - nominal) * 0.7;
let level = 0; // Normal
if (num < min || num > max) level = 3; // Alarm
else if (num < lowWarn || num > highWarn) level = 2; // Warning
return { percent, level, value: num };
}
_getMaintenanceStatus(value) {
if (!value || value === '--' || value === 'unavailable' || value === 'unknown') {
return { level: 0, text: '--' };
}
const lower = value.toLowerCase();
// Check for explicit OK
if (lower === 'ok' || lower.includes('ok')) return { level: 0, text: 'OK' };
// Check for overdue/due now
if (lower.includes('overdue') || lower.includes('due now')) {
return { level: 3, text: 'OVERDUE' };
}
// Parse Genmon format: "142 hrs or 05/27/2027"
const hrsMatch = value.match(/^(\d+)\s*hrs?\s/i);
if (hrsMatch) {
const hours = parseInt(hrsMatch[1], 10);
if (hours <= 0) return { level: 3, text: 'DUE' };
if (hours <= 20) return { level: 2, text: hours + 'h' };
if (hours <= 50) return { level: 1, text: hours + 'h' };
return { level: 0, text: 'OK' };
}
// Generic due check
if (lower.includes('due')) return { level: 2, text: 'DUE' };
// Unknown format - show abbreviated value
return { level: 1, text: value.substring(0, 8) };
}
_updateValues() {
if (!this._hass || !this.shadowRoot) return;
// Status indicators
const engineStatus = this._getEngineStatus();
const outageStatus = this._getOutageStatus();
const switchStatus = this._getSwitchStatus();
this._updateStatusIndicator('engine', engineStatus);
this._updateStatusIndicator('outage', outageStatus);
this._updateStatusIndicator('switch', switchStatus);
// Analog values
const outputV = this._getState('output_voltage');
const utilityV = this._getState('utility_voltage');
const freq = this._getState('frequency');
const battery = this._getState('battery_voltage');
this._updateAnalogBar('output-voltage', outputV,
this._config.voltage_min, this._config.voltage_nominal, this._config.voltage_max, 'V');
this._updateAnalogBar('utility-voltage', utilityV,
this._config.voltage_min, this._config.voltage_nominal, this._config.voltage_max, 'V');
this._updateAnalogBar('frequency', freq,
this._config.frequency_min, this._config.frequency_nominal, this._config.frequency_max, 'Hz');
this._updateAnalogBar('battery', battery,
this._config.battery_min, this._config.battery_nominal, this._config.battery_max, 'V');
// Simple values
this._updateSimpleValue('rpm', this._getState('rpm'));
this._updateSimpleValue('run-hours', this._getState('total_run_hours'));
// Maintenance indicators
if (this._config.show_maintenance) {
this._updateMaintenanceIndicator('oil', this._getMaintenanceStatus(this._getState('oil_service')));
this._updateMaintenanceIndicator('air-filter', this._getMaintenanceStatus(this._getState('air_filter_service')));
this._updateMaintenanceIndicator('spark-plug', this._getMaintenanceStatus(this._getState('spark_plug_service')));
this._updateMaintenanceIndicator('battery-svc', this._getMaintenanceStatus(this._getState('battery_service')));
}
// Update button states based on running status
this._updateButtonStates();
// Footer
const footer = this.shadowRoot.getElementById('footer-info');
if (footer) {
const exercise = this._getState('exercise_time');
footer.textContent = `Next Exercise: ${exercise}`;
}
}
_updateStatusIndicator(id, status) {
const el = this.shadowRoot.getElementById(`${id}-status`);
const indicator = this.shadowRoot.getElementById(`${id}-indicator`);
if (el) el.textContent = status.text;
if (indicator) {
indicator.className = 'status-indicator level-' + status.level;
}
}
_updateAnalogBar(id, value, min, nominal, max, unit) {
const status = this._getAnalogStatus(value, min, nominal, max);
const bar = this.shadowRoot.getElementById(`${id}-bar`);
const valueEl = this.shadowRoot.getElementById(`${id}-value`);
const container = this.shadowRoot.getElementById(`${id}-container`);
if (bar) {
bar.style.width = status.percent + '%';
bar.className = 'analog-bar-fill level-' + status.level;
}
if (valueEl) {
const displayValue = (value === '--' || value === 'unavailable' || value === 'unknown') ? '--' : `${value} ${unit}`; valueEl.textContent = displayValue;
valueEl.className = 'analog-value level-' + status.level;
}
if (container) {
container.className = 'analog-container level-' + status.level;
}
}
_updateSimpleValue(id, value) {
const el = this.shadowRoot.getElementById(id);
if (el) el.textContent = value;
}
_updateMaintenanceIndicator(id, status) {
const el = this.shadowRoot.getElementById(`${id}-status`);
const indicator = this.shadowRoot.getElementById(`${id}-indicator`);
if (el) el.textContent = status.text;
if (indicator) indicator.className = 'maint-indicator level-' + status.level;
}
_updateButtonStates() {
if (!this._config.show_controls) return;
const state = this._getState('engine_state').toLowerCase();
const isNotRunning = state.includes('off') || state.includes('ready') || state.includes('standby');
const startBtn = this.shadowRoot.querySelector('.ctrl-btn.start');
const stopBtn = this.shadowRoot.querySelector('.ctrl-btn.stop');
const transferBtn = this.shadowRoot.querySelector('.ctrl-btn.transfer');
const exerciseBtn = this.shadowRoot.querySelector('.ctrl-btn.exercise');
if (startBtn) startBtn.classList.toggle('disabled', !isNotRunning);
if (stopBtn) stopBtn.classList.toggle('disabled', isNotRunning);
if (transferBtn) transferBtn.classList.toggle('disabled', !isNotRunning);
if (exerciseBtn) exerciseBtn.classList.toggle('disabled', !isNotRunning);
}
_buildCard() {
if (!this._hass) return;
const styles = `
<style>
:host {
/* ISA-101 Color Palette */
--isa-bg: #d4d4d4;
--isa-bg-panel: #e8e8e8;
--isa-bg-dark: #b8b8b8;
--isa-border: #999999;
--isa-text: #1a1a1a;
--isa-text-dim: #666666;
/* Status Colors - ISA-101 compliant */
--isa-normal: #808080; /* Gray - normal operation */
--isa-abnormal: #0088cc; /* Blue - abnormal but not alarming */
--isa-warning: #cc8800; /* Amber - warning, attention needed */
--isa-alarm: #cc0000; /* Red - alarm, action required */
font-family: 'Segoe UI', 'Arial', sans-serif;
font-size: 13px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
.hmi-container {
background: var(--isa-bg);
border: 1px solid var(--isa-border);
border-radius: 4px;
padding: 8px;
}
/* Header */
.hmi-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 10px;
background: var(--isa-bg-dark);
border: 1px solid var(--isa-border);
margin-bottom: 8px;
}
.hmi-title {
font-size: 14px;
font-weight: 600;
color: var(--isa-text);
letter-spacing: 1px;
}
.hmi-timestamp {
font-size: 11px;
color: var(--isa-text-dim);
}
/* Status Row */
.status-row {
display: flex;
gap: 6px;
margin-bottom: 8px;
}
.status-block {
flex: 1;
background: var(--isa-bg-panel);
border: 1px solid var(--isa-border);
padding: 8px;
text-align: center;
box-sizing: border-box;
}
.status-label {
font-size: 10px;
color: var(--isa-text-dim);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 4px;
}
.status-indicator {
display: inline-block;
padding: 4px 12px;
font-size: 12px;
font-weight: 600;
border-radius: 2px;
min-width: 80px;
}
/* ISA-101 Status Levels */
.level-0 { background: var(--isa-normal); color: #fff; }
.level-1 { background: var(--isa-abnormal); color: #fff; }
.level-2 { background: var(--isa-warning); color: #fff; }
.level-3 { background: var(--isa-alarm); color: #fff; animation: alarm-flash 1s infinite; }
@keyframes alarm-flash {
0%, 100% { opacity: 1; }
50% { opacity: 0.7; }
}
/* Analog Indicators */
.analog-section {
background: var(--isa-bg-panel);
border: 1px solid var(--isa-border);
padding: 10px;
margin-bottom: 8px;
}
.analog-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 12px;
}
.analog-item {
display: flex;
flex-direction: column;
}
.analog-label {
font-size: 10px;
color: var(--isa-text-dim);
text-transform: uppercase;
margin-bottom: 2px;
}
.analog-container {
position: relative;
height: 24px;
background: #fff;
border: 1px solid var(--isa-border);
overflow: hidden;
}
.analog-bar-fill {
height: 100%;
transition: width 0.3s ease;
}
.analog-bar-fill.level-0 { background: var(--isa-normal); }
.analog-bar-fill.level-1 { background: var(--isa-abnormal); }
.analog-bar-fill.level-2 { background: var(--isa-warning); }
.analog-bar-fill.level-3 { background: var(--isa-alarm); }
.analog-value {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 12px;
font-weight: 600;
color: #fff;
text-shadow: 1px 1px 2px rgba(0,0,0,0.8), -1px -1px 2px rgba(0,0,0,0.8);
}
.analog-scale {
display: flex;
justify-content: space-between;
font-size: 9px;
color: var(--isa-text-dim);
margin-top: 1px;
}
/* Clickable elements */
.clickable {
cursor: pointer;
}
.clickable:hover {
filter: brightness(0.95);
}
.clickable:active {
filter: brightness(0.9);
}
/* Simple Values */
.values-row {
display: flex;
gap: 8px;
margin-bottom: 8px;
}
.value-block {
flex: 1;
background: var(--isa-bg-panel);
border: 1px solid var(--isa-border);
padding: 8px;
text-align: center;
}
.value-label {
font-size: 10px;
color: var(--isa-text-dim);
text-transform: uppercase;
}
.value-display {
font-size: 18px;
font-weight: 600;
color: var(--isa-text);
}
.value-unit {
font-size: 11px;
color: var(--isa-text-dim);
}
/* Maintenance Section */
.maint-section {
background: var(--isa-bg-panel);
border: 1px solid var(--isa-border);
padding: 8px;
margin-bottom: 8px;
}
.maint-title {
font-size: 10px;
color: var(--isa-text-dim);
text-transform: uppercase;
margin-bottom: 6px;
border-bottom: 1px solid var(--isa-border);
padding-bottom: 4px;
}
.maint-grid {
display: flex;
gap: 6px;
}
.maint-item {
flex: 1;
text-align: center;
}
.maint-label {
font-size: 9px;
color: var(--isa-text-dim);
margin-bottom: 2px;
}
.maint-indicator {
display: inline-block;
padding: 2px 8px;
font-size: 10px;
font-weight: 600;
border-radius: 2px;
}
/* Control Buttons - ISA-101 style */
.controls-section {
display: flex;
gap: 6px;
margin-bottom: 8px;
}
.ctrl-btn {
flex: 1;
padding: 10px 8px;
border: 2px solid;
background: var(--isa-bg-panel);
cursor: pointer;
text-align: center;
transition: all 0.15s ease;
}
.ctrl-btn:hover {
filter: brightness(0.95);
}
.ctrl-btn:active {
transform: scale(0.98);
}
.ctrl-btn-icon {
font-size: 20px;
margin-bottom: 4px;
}
.ctrl-btn-label {
font-size: 10px;
font-weight: 600;
text-transform: uppercase;
}
.ctrl-btn.start {
border-color: #228822;
color: #228822;
}
.ctrl-btn.stop {
border-color: #aa2222;
color: #aa2222;
}
.ctrl-btn.transfer {
border-color: #886600;
color: #886600;
}
.ctrl-btn.exercise {
border-color: #225588;
color: #225588;
}
.ctrl-btn.disabled {
opacity: 0.4;
cursor: not-allowed;
pointer-events: none;
}
/* Footer */
.hmi-footer {
font-size: 10px;
color: var(--isa-text-dim);
text-align: center;
padding-top: 4px;
border-top: 1px solid var(--isa-border);
}
</style>
`;
const html = `
<ha-card>
<div class="hmi-container">
<div class="hmi-header">
<span class="hmi-title">${this._config.title}</span>
</div>
<!-- Primary Status -->
<div class="status-row">
<div class="status-block clickable" data-entity="engine_state">
<div class="status-label">Engine</div>
<span class="status-indicator level-0" id="engine-indicator">
<span id="engine-status">--</span>
</span>
</div>
<div class="status-block clickable" data-entity="system_in_outage">
<div class="status-label">Utility</div>
<span class="status-indicator level-0" id="outage-indicator">
<span id="outage-status">--</span>
</span>
</div>
<div class="status-block clickable" data-entity="switch_state">
<div class="status-label">Load Source</div>
<span class="status-indicator level-0" id="switch-indicator">
<span id="switch-status">--</span>
</span>
</div>
</div>
<!-- Analog Indicators -->
<div class="analog-section">
<div class="analog-grid">
<div class="analog-item clickable" data-entity="output_voltage">
<div class="analog-label">Output Voltage</div>
<div class="analog-container" id="output-voltage-container">
<div class="analog-bar-fill level-0" id="output-voltage-bar" style="width: 0%"></div>
<span class="analog-value" id="output-voltage-value">--</span>
</div>
<div class="analog-scale">
<span>${this._config.voltage_min}</span>
<span>${this._config.voltage_nominal}</span>
<span>${this._config.voltage_max}</span>
</div>
</div>
<div class="analog-item clickable" data-entity="utility_voltage">
<div class="analog-label">Utility Voltage</div>
<div class="analog-container" id="utility-voltage-container">
<div class="analog-bar-fill level-0" id="utility-voltage-bar" style="width: 0%"></div>
<span class="analog-value" id="utility-voltage-value">--</span>
</div>
<div class="analog-scale">
<span>${this._config.voltage_min}</span>
<span>${this._config.voltage_nominal}</span>
<span>${this._config.voltage_max}</span>
</div>
</div>
<div class="analog-item clickable" data-entity="output_frequency">
<div class="analog-label">Frequency</div>
<div class="analog-container" id="frequency-container">
<div class="analog-bar-fill level-0" id="frequency-bar" style="width: 0%"></div>
<span class="analog-value" id="frequency-value">--</span>
</div>
<div class="analog-scale">
<span>${this._config.frequency_min}</span>
<span>${this._config.frequency_nominal}</span>
<span>${this._config.frequency_max}</span>
</div>
</div>
<div class="analog-item clickable" data-entity="battery_voltage">
<div class="analog-label">Battery</div>
<div class="analog-container" id="battery-container">
<div class="analog-bar-fill level-0" id="battery-bar" style="width: 0%"></div>
<span class="analog-value" id="battery-value">--</span>
</div>
<div class="analog-scale">
<span>${this._config.battery_min}</span>
<span>${this._config.battery_nominal}</span>
<span>${this._config.battery_max}</span>
</div>
</div>
</div>
</div>
<!-- Simple Values -->
<div class="values-row">
<div class="value-block clickable" data-entity="rpm">
<div class="value-label">RPM</div>
<div class="value-display"><span id="rpm">--</span></div>
</div>
<div class="value-block clickable" data-entity="total_run_hours">
<div class="value-label">Run Hours</div>
<div class="value-display"><span id="run-hours">--</span></div>
</div>
</div>
${this._config.show_maintenance ? `
<!-- Maintenance -->
<div class="maint-section">
<div class="maint-title">Maintenance Status</div>
<div class="maint-grid">
<div class="maint-item clickable" data-entity="oil_and_filter_service_due">
<div class="maint-label">Oil</div>
<span class="maint-indicator level-0" id="oil-indicator"><span id="oil-status">--</span></span>
</div>
<div class="maint-item clickable" data-entity="air_filter_service_due">
<div class="maint-label">Air Filter</div>
<span class="maint-indicator level-0" id="air-filter-indicator"><span id="air-filter-status">--</span></span>
</div>
<div class="maint-item clickable" data-entity="spark_plug_service_due">
<div class="maint-label">Spark Plug</div>
<span class="maint-indicator level-0" id="spark-plug-indicator"><span id="spark-plug-status">--</span></span>
</div>
<div class="maint-item clickable" data-entity="battery_service_due">
<div class="maint-label">Battery</div>
<span class="maint-indicator level-0" id="battery-svc-indicator"><span id="battery-svc-status">--</span></span>
</div>
</div>
</div>
` : ''}
${this._config.show_controls ? `
<!-- Controls -->
<div class="controls-section">
<div class="ctrl-btn start" data-action="start">
<div class="ctrl-btn-icon"><ha-icon icon="mdi:play"></ha-icon></div>
<div class="ctrl-btn-label">Start</div>
</div>
<div class="ctrl-btn stop" data-action="stop">
<div class="ctrl-btn-icon"><ha-icon icon="mdi:stop"></ha-icon></div>
<div class="ctrl-btn-label">Stop</div>
</div>
<div class="ctrl-btn transfer" data-action="start_transfer">
<div class="ctrl-btn-icon"><ha-icon icon="mdi:swap-horizontal"></ha-icon></div>
<div class="ctrl-btn-label">Transfer</div>
</div>
<div class="ctrl-btn exercise" data-action="start_exercise">
<div class="ctrl-btn-icon"><ha-icon icon="mdi:rotate-right"></ha-icon></div>
<div class="ctrl-btn-label">Exercise</div>
</div>
</div>
` : ''}
<div class="hmi-footer">
<span id="footer-info">--</span>
</div>
</div>
</ha-card>
`;
this.shadowRoot.innerHTML = styles + html;
// Add button handlers
if (this._config.show_controls) {
const confirmTexts = {
start: 'Start the generator?',
stop: 'Stop the generator?',
start_transfer: 'Start and transfer load?',
start_exercise: 'Run exercise cycle?'
};
this.shadowRoot.querySelectorAll('.ctrl-btn').forEach((btn) => {
const action = btn.dataset.action;
btn.addEventListener('click', () => {
this._handleButtonClick(this._getButtonEntity(action), confirmTexts[action]);
});
});
}
// Add click handlers for sensor more-info dialogs
this.shadowRoot.querySelectorAll('.clickable[data-entity]').forEach((el) => {
el.addEventListener('click', () => {
this._showMoreInfo(el.dataset.entity);
});
});
this._updateValues();
}
}
customElements.define('generator-hmi-card', GeneratorHMICard);
window.customCards = window.customCards || [];
window.customCards.push({
type: 'generator-hmi-card',
name: 'Generator HMI Card',
description: 'ISA-101 compliant high-performance HMI for Genmon',
preview: true,
});