@matter-server/dashboard 1.5.1 → 1.5.3
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/dist/esm/client/models/descriptions.d.ts.map +1 -1
- package/dist/esm/client/models/descriptions.js +380 -0
- package/dist/esm/client/models/descriptions.js.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.d.ts +27 -0
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.js +428 -7
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.js.map +1 -1
- package/dist/esm/util/thermostat-preset-edit.d.ts +68 -0
- package/dist/esm/util/thermostat-preset-edit.d.ts.map +1 -0
- package/dist/esm/util/thermostat-preset-edit.js +174 -0
- package/dist/esm/util/thermostat-preset-edit.js.map +6 -0
- package/dist/esm/util/thermostat-schedule.d.ts +4 -0
- package/dist/esm/util/thermostat-schedule.d.ts.map +1 -1
- package/dist/esm/util/thermostat-schedule.js +5 -1
- package/dist/esm/util/thermostat-schedule.js.map +1 -1
- package/dist/web/js/{attribute-write-dialog-BYIrK0s9.js → attribute-write-dialog-C-KBqyuJ.js} +1 -1
- package/dist/web/js/{command-invoke-dialog-sgrlMSYh.js → command-invoke-dialog-C4HMf49Q.js} +1 -1
- package/dist/web/js/{commission-node-dialog-C7n9Vdcz.js → commission-node-dialog-Driu7kGn.js} +5 -5
- package/dist/web/js/{commission-node-existing-DfTkRkfm.js → commission-node-existing-Dth2CY1e.js} +1 -1
- package/dist/web/js/{commission-node-thread-B4_kOd4o.js → commission-node-thread-CnixX2gX.js} +1 -1
- package/dist/web/js/{commission-node-wifi-B37hLRjk.js → commission-node-wifi-8im5zNEv.js} +1 -1
- package/dist/web/js/{dialog-box-CRK6qCOH.js → dialog-box-Daj8_--D.js} +1 -1
- package/dist/web/js/{fabric-label-dialog-CtRCSYxX.js → fabric-label-dialog-Bk6lPNvk.js} +1 -1
- package/dist/web/js/main.js +1 -1
- package/dist/web/js/{matter-dashboard-app-DkWZ4ibd.js → matter-dashboard-app-BdO9wWRC.js} +907 -18
- package/dist/web/js/{node-acl-add-dialog-BSKJrvir.js → node-acl-add-dialog-OeLLubXq.js} +1 -1
- package/dist/web/js/{node-binding-dialog-DmhjB76G.js → node-binding-dialog-DQ9R0KrP.js} +1 -1
- package/dist/web/js/{node-label-dialog-DmrPo80W.js → node-label-dialog-IVEQrmsg.js} +1 -1
- package/dist/web/js/{settings-dialog-DxeXrD5U.js → settings-dialog-gcsO83Jl.js} +1 -1
- package/package.json +3 -3
- package/src/client/models/descriptions.ts +380 -0
- package/src/pages/cluster-commands/clusters/thermostat-commands.ts +486 -7
- package/src/util/thermostat-preset-edit.ts +289 -0
- package/src/util/thermostat-schedule.ts +6 -2
|
@@ -9,10 +9,13 @@ import "@material/web/iconbutton/outlined-icon-button";
|
|
|
9
9
|
import type { MatterNode } from "@matter-server/ws-client";
|
|
10
10
|
import {
|
|
11
11
|
mdiCheck,
|
|
12
|
+
mdiCheckCircleOutline,
|
|
12
13
|
mdiClockOutline,
|
|
14
|
+
mdiClose,
|
|
13
15
|
mdiFire,
|
|
14
16
|
mdiLightbulbOnOutline,
|
|
15
17
|
mdiPaletteSwatchOutline,
|
|
18
|
+
mdiPencilOutline,
|
|
16
19
|
mdiPlus,
|
|
17
20
|
mdiSnowflake,
|
|
18
21
|
mdiTrashCanOutline,
|
|
@@ -21,8 +24,23 @@ import { css, type CSSResultGroup, html, nothing, type TemplateResult } from "li
|
|
|
21
24
|
import { customElement, state } from "lit/decorators.js";
|
|
22
25
|
import { live } from "lit/directives/live.js";
|
|
23
26
|
import "../../../components/ha-svg-icon.js";
|
|
24
|
-
import { showAlertDialog } from "../../../components/dialog-box/show-dialog-box.js";
|
|
27
|
+
import { showAlertDialog, showPromptDialog } from "../../../components/dialog-box/show-dialog-box.js";
|
|
25
28
|
import { handleAsync } from "../../../util/async-handler.js";
|
|
29
|
+
import {
|
|
30
|
+
applyPresetEdit,
|
|
31
|
+
formatSetpointInput,
|
|
32
|
+
isPresetUsedBySchedule,
|
|
33
|
+
parseSetpointInput,
|
|
34
|
+
presetNameConflict,
|
|
35
|
+
presetTypeSupportsNames,
|
|
36
|
+
readNumberOfPresets,
|
|
37
|
+
readPresetTypes,
|
|
38
|
+
setActivePreset,
|
|
39
|
+
type ThermostatPresetEdit,
|
|
40
|
+
type ThermostatPresetType,
|
|
41
|
+
toPresetEdit,
|
|
42
|
+
writeThermostatPresets,
|
|
43
|
+
} from "../../../util/thermostat-preset-edit.js";
|
|
26
44
|
import {
|
|
27
45
|
buildDaySegments,
|
|
28
46
|
compareTransitionsForDisplay,
|
|
@@ -40,6 +58,7 @@ import {
|
|
|
40
58
|
readActiveScheduleHandle,
|
|
41
59
|
readPresets,
|
|
42
60
|
pickSetpointForMode,
|
|
61
|
+
PRESET_SCENARIO_LABELS,
|
|
43
62
|
readSchedules,
|
|
44
63
|
resolveScheduleDefaults,
|
|
45
64
|
resolveTransitionLabel,
|
|
@@ -67,6 +86,10 @@ const HOUR_TICKS = [0, 4, 8, 12, 16, 20, 24];
|
|
|
67
86
|
|
|
68
87
|
const DEFAULT_EXPIRATION_MINUTES = 60;
|
|
69
88
|
|
|
89
|
+
/** PresetStruct setpoint fallbacks (spec §4.3.10.23), in centidegrees. */
|
|
90
|
+
const DEFAULT_PRESET_HEATING_SETPOINT = 2000;
|
|
91
|
+
const DEFAULT_PRESET_COOLING_SETPOINT = 2600;
|
|
92
|
+
|
|
70
93
|
@customElement("thermostat-cluster-commands")
|
|
71
94
|
class ThermostatClusterCommands extends BaseClusterCommands {
|
|
72
95
|
@state() private _selectedHandle: string | null = null;
|
|
@@ -77,12 +100,25 @@ class ThermostatClusterCommands extends BaseClusterCommands {
|
|
|
77
100
|
@state() private _addExpirationMinutes = DEFAULT_EXPIRATION_MINUTES;
|
|
78
101
|
@state() private _addExpirationInput = String(DEFAULT_EXPIRATION_MINUTES);
|
|
79
102
|
|
|
103
|
+
@state() private _editingPresetHandle: string | null = null;
|
|
104
|
+
@state() private _editName = "";
|
|
105
|
+
@state() private _editHeating = "";
|
|
106
|
+
@state() private _editCooling = "";
|
|
107
|
+
|
|
108
|
+
@state() private _creatingPreset = false;
|
|
109
|
+
@state() private _newPresetScenario: number | null = null;
|
|
110
|
+
@state() private _newPresetName = "";
|
|
111
|
+
@state() private _newPresetHeating = "";
|
|
112
|
+
@state() private _newPresetCooling = "";
|
|
113
|
+
|
|
80
114
|
/**
|
|
81
115
|
* In-flight invokes, identified by operation id rather than a boolean: the panel is reused across
|
|
82
116
|
* navigations, so a settling promise must only clear the flag it set itself.
|
|
83
117
|
*/
|
|
84
118
|
@state() private _addOperation: number | null = null;
|
|
85
119
|
@state() private _removeOperations: Record<number, number> = {};
|
|
120
|
+
@state() private _presetWriteOperation: number | null = null;
|
|
121
|
+
@state() private _activateOperation: number | null = null;
|
|
86
122
|
private _operationCounter = 0;
|
|
87
123
|
|
|
88
124
|
override willUpdate(changedProperties: Map<string, unknown>) {
|
|
@@ -97,6 +133,14 @@ class ThermostatClusterCommands extends BaseClusterCommands {
|
|
|
97
133
|
this._addExpirationInput = String(DEFAULT_EXPIRATION_MINUTES);
|
|
98
134
|
this._addOperation = null;
|
|
99
135
|
this._removeOperations = {};
|
|
136
|
+
this._editingPresetHandle = null;
|
|
137
|
+
this._creatingPreset = false;
|
|
138
|
+
this._newPresetScenario = null;
|
|
139
|
+
this._newPresetName = "";
|
|
140
|
+
this._newPresetHeating = "";
|
|
141
|
+
this._newPresetCooling = "";
|
|
142
|
+
this._presetWriteOperation = null;
|
|
143
|
+
this._activateOperation = null;
|
|
100
144
|
}
|
|
101
145
|
this._scheduleContext = context;
|
|
102
146
|
}
|
|
@@ -318,6 +362,10 @@ class ThermostatClusterCommands extends BaseClusterCommands {
|
|
|
318
362
|
private _renderPresetsPanel(): TemplateResult {
|
|
319
363
|
const presets = readPresets(this.node, this.endpoint);
|
|
320
364
|
const activeHandle = readActivePresetHandle(this.node, this.endpoint);
|
|
365
|
+
const presetTypes = readPresetTypes(this.node, this.endpoint);
|
|
366
|
+
const heatActive = isFeatureActive(this.node, this.endpoint, "HEAT");
|
|
367
|
+
const coolActive = isFeatureActive(this.node, this.endpoint, "COOL");
|
|
368
|
+
const busy = this._presetWriteOperation !== null;
|
|
321
369
|
|
|
322
370
|
return html`
|
|
323
371
|
<details class="command-panel" open>
|
|
@@ -334,16 +382,40 @@ class ThermostatClusterCommands extends BaseClusterCommands {
|
|
|
334
382
|
? html`<p class="empty">No presets configured.</p>`
|
|
335
383
|
: html`
|
|
336
384
|
<ul class="preset-list">
|
|
337
|
-
${presets.map(p =>
|
|
385
|
+
${presets.map(p =>
|
|
386
|
+
this._editingPresetHandle === p.handle
|
|
387
|
+
? this._renderPresetEditRow(
|
|
388
|
+
p,
|
|
389
|
+
presets,
|
|
390
|
+
presetTypes ?? [],
|
|
391
|
+
heatActive,
|
|
392
|
+
coolActive,
|
|
393
|
+
busy,
|
|
394
|
+
)
|
|
395
|
+
: this._renderPresetRow(p, p.handle === activeHandle, busy),
|
|
396
|
+
)}
|
|
338
397
|
</ul>
|
|
339
398
|
`
|
|
340
399
|
}
|
|
400
|
+
${
|
|
401
|
+
presets === undefined
|
|
402
|
+
? nothing
|
|
403
|
+
: this._renderAddPresetForm(presets, presetTypes, heatActive, coolActive, busy)
|
|
404
|
+
}
|
|
341
405
|
</div>
|
|
342
406
|
</details>
|
|
343
407
|
`;
|
|
344
408
|
}
|
|
345
409
|
|
|
346
|
-
private _renderPresetRow(preset: ThermostatPreset, isActive: boolean): TemplateResult {
|
|
410
|
+
private _renderPresetRow(preset: ThermostatPreset, isActive: boolean, busy: boolean): TemplateResult {
|
|
411
|
+
const activating = this._activateOperation !== null;
|
|
412
|
+
const removeBlockedReason = preset.builtIn
|
|
413
|
+
? "Built-in presets cannot be removed"
|
|
414
|
+
: isActive
|
|
415
|
+
? "The active preset cannot be removed"
|
|
416
|
+
: isPresetUsedBySchedule(readSchedules(this.node, this.endpoint) ?? [], preset.handle)
|
|
417
|
+
? "A schedule uses this preset"
|
|
418
|
+
: null;
|
|
347
419
|
return html`
|
|
348
420
|
<li class="preset-row">
|
|
349
421
|
<span class="preset-label">${formatPresetLabel(preset)}</span>
|
|
@@ -354,16 +426,264 @@ class ThermostatClusterCommands extends BaseClusterCommands {
|
|
|
354
426
|
${preset.builtIn ? html`<span class="chip-handle">Built-in</span>` : nothing}
|
|
355
427
|
${
|
|
356
428
|
isActive
|
|
357
|
-
? html
|
|
358
|
-
<
|
|
359
|
-
|
|
360
|
-
|
|
429
|
+
? html`
|
|
430
|
+
<span class="active-badge">
|
|
431
|
+
<ha-svg-icon .path=${mdiCheck}></ha-svg-icon>
|
|
432
|
+
Active
|
|
433
|
+
</span>
|
|
434
|
+
<md-outlined-icon-button
|
|
435
|
+
title="Clear active preset"
|
|
436
|
+
aria-label="Clear active preset"
|
|
437
|
+
?disabled=${activating || busy}
|
|
438
|
+
@click=${handleAsync(() => this._handleSetActivePreset(null))}
|
|
439
|
+
>
|
|
440
|
+
<ha-svg-icon .path=${mdiClose}></ha-svg-icon>
|
|
441
|
+
</md-outlined-icon-button>
|
|
442
|
+
`
|
|
443
|
+
: html`
|
|
444
|
+
<md-outlined-icon-button
|
|
445
|
+
title="Set as active preset"
|
|
446
|
+
aria-label="Set as active preset"
|
|
447
|
+
?disabled=${activating || busy}
|
|
448
|
+
@click=${handleAsync(() => this._handleSetActivePreset(preset.handle))}
|
|
449
|
+
>
|
|
450
|
+
<ha-svg-icon .path=${mdiCheckCircleOutline}></ha-svg-icon>
|
|
451
|
+
</md-outlined-icon-button>
|
|
452
|
+
`
|
|
453
|
+
}
|
|
454
|
+
<md-outlined-icon-button
|
|
455
|
+
title="Edit preset"
|
|
456
|
+
aria-label="Edit preset"
|
|
457
|
+
?disabled=${busy}
|
|
458
|
+
@click=${() => this._startEditPreset(preset)}
|
|
459
|
+
>
|
|
460
|
+
<ha-svg-icon .path=${mdiPencilOutline}></ha-svg-icon>
|
|
461
|
+
</md-outlined-icon-button>
|
|
462
|
+
<md-outlined-icon-button
|
|
463
|
+
title=${removeBlockedReason ?? "Remove preset"}
|
|
464
|
+
aria-label="Remove preset"
|
|
465
|
+
?disabled=${busy || activating || removeBlockedReason !== null}
|
|
466
|
+
@click=${handleAsync(() => this._handleDeletePreset(preset))}
|
|
467
|
+
>
|
|
468
|
+
<ha-svg-icon .path=${mdiTrashCanOutline}></ha-svg-icon>
|
|
469
|
+
</md-outlined-icon-button>
|
|
470
|
+
</li>
|
|
471
|
+
`;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
private _renderPresetEditRow(
|
|
475
|
+
preset: ThermostatPreset,
|
|
476
|
+
presets: ThermostatPreset[],
|
|
477
|
+
presetTypes: ThermostatPresetType[],
|
|
478
|
+
heatActive: boolean,
|
|
479
|
+
coolActive: boolean,
|
|
480
|
+
busy: boolean,
|
|
481
|
+
): TemplateResult {
|
|
482
|
+
const edited = applyPresetEdit(preset, presetTypes, {
|
|
483
|
+
name: this._editName,
|
|
484
|
+
heating: this._editHeating,
|
|
485
|
+
cooling: this._editCooling,
|
|
486
|
+
});
|
|
487
|
+
const nameConflict = presetNameConflict(presets, edited.presetScenario, edited.name, preset.handle);
|
|
488
|
+
const scenarioLabel = PRESET_SCENARIO_LABELS[preset.scenario ?? -1] ?? formatHandleShort(preset.handle);
|
|
489
|
+
return html`
|
|
490
|
+
<li class="preset-row preset-row-editing">
|
|
491
|
+
<span class="preset-label">${scenarioLabel}</span>
|
|
492
|
+
${
|
|
493
|
+
presetTypeSupportsNames(presetTypes, preset.scenario)
|
|
494
|
+
? html`
|
|
495
|
+
<label for="editPresetName">Name:</label>
|
|
496
|
+
<input
|
|
497
|
+
id="editPresetName"
|
|
498
|
+
type="text"
|
|
499
|
+
maxlength="64"
|
|
500
|
+
placeholder="(unnamed)"
|
|
501
|
+
.value=${live(this._editName)}
|
|
502
|
+
@input=${(e: Event) => {
|
|
503
|
+
this._editName = (e.target as HTMLInputElement).value;
|
|
504
|
+
}}
|
|
505
|
+
/>
|
|
506
|
+
`
|
|
507
|
+
: nothing
|
|
508
|
+
}
|
|
509
|
+
${
|
|
510
|
+
heatActive
|
|
511
|
+
? html`
|
|
512
|
+
<label for="editPresetHeat">Heat:</label>
|
|
513
|
+
<input
|
|
514
|
+
id="editPresetHeat"
|
|
515
|
+
type="number"
|
|
516
|
+
step="0.01"
|
|
517
|
+
.value=${live(this._editHeating)}
|
|
518
|
+
@input=${(e: Event) => {
|
|
519
|
+
this._editHeating = (e.target as HTMLInputElement).value;
|
|
520
|
+
}}
|
|
521
|
+
/>
|
|
522
|
+
`
|
|
361
523
|
: nothing
|
|
362
524
|
}
|
|
525
|
+
${
|
|
526
|
+
coolActive
|
|
527
|
+
? html`
|
|
528
|
+
<label for="editPresetCool">Cool:</label>
|
|
529
|
+
<input
|
|
530
|
+
id="editPresetCool"
|
|
531
|
+
type="number"
|
|
532
|
+
step="0.01"
|
|
533
|
+
.value=${live(this._editCooling)}
|
|
534
|
+
@input=${(e: Event) => {
|
|
535
|
+
this._editCooling = (e.target as HTMLInputElement).value;
|
|
536
|
+
}}
|
|
537
|
+
/>
|
|
538
|
+
`
|
|
539
|
+
: nothing
|
|
540
|
+
}
|
|
541
|
+
<md-outlined-icon-button
|
|
542
|
+
title=${nameConflict ?? "Save"}
|
|
543
|
+
aria-label="Save"
|
|
544
|
+
?disabled=${busy || nameConflict !== null}
|
|
545
|
+
@click=${handleAsync(() => this._handleSavePreset(preset.handle))}
|
|
546
|
+
>
|
|
547
|
+
<ha-svg-icon .path=${mdiCheck}></ha-svg-icon>
|
|
548
|
+
</md-outlined-icon-button>
|
|
549
|
+
<md-outlined-icon-button
|
|
550
|
+
title="Cancel"
|
|
551
|
+
aria-label="Cancel"
|
|
552
|
+
?disabled=${busy}
|
|
553
|
+
@click=${() => this._cancelEditPreset()}
|
|
554
|
+
>
|
|
555
|
+
<ha-svg-icon .path=${mdiClose}></ha-svg-icon>
|
|
556
|
+
</md-outlined-icon-button>
|
|
363
557
|
</li>
|
|
364
558
|
`;
|
|
365
559
|
}
|
|
366
560
|
|
|
561
|
+
private _renderAddPresetForm(
|
|
562
|
+
presets: ThermostatPreset[],
|
|
563
|
+
presetTypes: ThermostatPresetType[] | undefined,
|
|
564
|
+
heatActive: boolean,
|
|
565
|
+
coolActive: boolean,
|
|
566
|
+
busy: boolean,
|
|
567
|
+
): TemplateResult {
|
|
568
|
+
if (!this._creatingPreset) {
|
|
569
|
+
return html`
|
|
570
|
+
<md-outlined-button ?disabled=${busy} @click=${() => this._openAddPresetForm(presetTypes ?? [])}>
|
|
571
|
+
<ha-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon>
|
|
572
|
+
Add preset
|
|
573
|
+
</md-outlined-button>
|
|
574
|
+
`;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const countByScenario = new Map<number, number>();
|
|
578
|
+
for (const p of presets) {
|
|
579
|
+
if (p.scenario !== null) countByScenario.set(p.scenario, (countByScenario.get(p.scenario) ?? 0) + 1);
|
|
580
|
+
}
|
|
581
|
+
const totalLimit = readNumberOfPresets(this.node, this.endpoint);
|
|
582
|
+
const availableTypes =
|
|
583
|
+
totalLimit !== null && presets.length >= totalLimit
|
|
584
|
+
? []
|
|
585
|
+
: (presetTypes ?? []).filter(
|
|
586
|
+
t =>
|
|
587
|
+
(countByScenario.get(t.scenario) ?? 0) < t.numberOfPresets &&
|
|
588
|
+
(t.supportsNames || presetNameConflict(presets, t.scenario, null, null) === null),
|
|
589
|
+
);
|
|
590
|
+
const selectedType =
|
|
591
|
+
availableTypes.find(t => t.scenario === this._newPresetScenario) ?? availableTypes[0] ?? null;
|
|
592
|
+
const nameConflict =
|
|
593
|
+
selectedType === null
|
|
594
|
+
? null
|
|
595
|
+
: presetNameConflict(presets, selectedType.scenario, this._newPresetNameFor(selectedType), null);
|
|
596
|
+
|
|
597
|
+
return html`
|
|
598
|
+
<div class="transitions-header">ADD PRESET</div>
|
|
599
|
+
${
|
|
600
|
+
presetTypes === undefined
|
|
601
|
+
? html`<p class="empty">PresetTypes attribute not available.</p>`
|
|
602
|
+
: availableTypes.length === 0
|
|
603
|
+
? html`<p class="empty">The device has no room left for another preset.</p>`
|
|
604
|
+
: html`
|
|
605
|
+
<div class="command-row">
|
|
606
|
+
<label for="newPresetScenario">Scenario:</label>
|
|
607
|
+
<select
|
|
608
|
+
id="newPresetScenario"
|
|
609
|
+
@change=${(e: Event) => {
|
|
610
|
+
this._newPresetScenario = Number((e.target as HTMLSelectElement).value);
|
|
611
|
+
}}
|
|
612
|
+
>
|
|
613
|
+
${availableTypes.map(
|
|
614
|
+
t => html`
|
|
615
|
+
<option
|
|
616
|
+
value=${t.scenario}
|
|
617
|
+
.selected=${t.scenario === selectedType?.scenario}
|
|
618
|
+
>
|
|
619
|
+
${PRESET_SCENARIO_LABELS[t.scenario] ?? `Scenario ${t.scenario}`}
|
|
620
|
+
</option>
|
|
621
|
+
`,
|
|
622
|
+
)}
|
|
623
|
+
</select>
|
|
624
|
+
${
|
|
625
|
+
selectedType?.supportsNames
|
|
626
|
+
? html`
|
|
627
|
+
<label for="newPresetName">Name:</label>
|
|
628
|
+
<input
|
|
629
|
+
id="newPresetName"
|
|
630
|
+
type="text"
|
|
631
|
+
maxlength="64"
|
|
632
|
+
.value=${live(this._newPresetName)}
|
|
633
|
+
@input=${(e: Event) => {
|
|
634
|
+
this._newPresetName = (e.target as HTMLInputElement).value;
|
|
635
|
+
}}
|
|
636
|
+
/>
|
|
637
|
+
`
|
|
638
|
+
: nothing
|
|
639
|
+
}
|
|
640
|
+
${
|
|
641
|
+
heatActive
|
|
642
|
+
? html`
|
|
643
|
+
<label for="newPresetHeat">Heat:</label>
|
|
644
|
+
<input
|
|
645
|
+
id="newPresetHeat"
|
|
646
|
+
type="number"
|
|
647
|
+
step="0.01"
|
|
648
|
+
.value=${live(this._newPresetHeating)}
|
|
649
|
+
@input=${(e: Event) => {
|
|
650
|
+
this._newPresetHeating = (e.target as HTMLInputElement).value;
|
|
651
|
+
}}
|
|
652
|
+
/>
|
|
653
|
+
`
|
|
654
|
+
: nothing
|
|
655
|
+
}
|
|
656
|
+
${
|
|
657
|
+
coolActive
|
|
658
|
+
? html`
|
|
659
|
+
<label for="newPresetCool">Cool:</label>
|
|
660
|
+
<input
|
|
661
|
+
id="newPresetCool"
|
|
662
|
+
type="number"
|
|
663
|
+
step="0.01"
|
|
664
|
+
.value=${live(this._newPresetCooling)}
|
|
665
|
+
@input=${(e: Event) => {
|
|
666
|
+
this._newPresetCooling = (e.target as HTMLInputElement).value;
|
|
667
|
+
}}
|
|
668
|
+
/>
|
|
669
|
+
`
|
|
670
|
+
: nothing
|
|
671
|
+
}
|
|
672
|
+
<md-outlined-button
|
|
673
|
+
title=${nameConflict ?? nothing}
|
|
674
|
+
?disabled=${busy || selectedType === null || nameConflict !== null}
|
|
675
|
+
@click=${handleAsync(() => this._handleAddPreset(selectedType))}
|
|
676
|
+
>
|
|
677
|
+
<ha-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon>
|
|
678
|
+
Add
|
|
679
|
+
</md-outlined-button>
|
|
680
|
+
</div>
|
|
681
|
+
`
|
|
682
|
+
}
|
|
683
|
+
<md-outlined-button ?disabled=${busy} @click=${() => this._cancelAddPreset()}>Cancel</md-outlined-button>
|
|
684
|
+
`;
|
|
685
|
+
}
|
|
686
|
+
|
|
367
687
|
private _renderSuggestionsPanel(): TemplateResult {
|
|
368
688
|
const maxSuggestions = readMaxThermostatSuggestions(this.node, this.endpoint);
|
|
369
689
|
const suggestions = readThermostatSuggestions(this.node, this.endpoint);
|
|
@@ -571,6 +891,142 @@ class ThermostatClusterCommands extends BaseClusterCommands {
|
|
|
571
891
|
}
|
|
572
892
|
}
|
|
573
893
|
|
|
894
|
+
private _startEditPreset(preset: ThermostatPreset) {
|
|
895
|
+
this._creatingPreset = false;
|
|
896
|
+
this._editingPresetHandle = preset.handle;
|
|
897
|
+
this._editName = preset.name ?? "";
|
|
898
|
+
this._editHeating = formatSetpointInput(preset.heatingSetpoint);
|
|
899
|
+
this._editCooling = formatSetpointInput(preset.coolingSetpoint);
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
private _cancelEditPreset() {
|
|
903
|
+
this._editingPresetHandle = null;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
private _openAddPresetForm(presetTypes: ThermostatPresetType[]) {
|
|
907
|
+
this._editingPresetHandle = null;
|
|
908
|
+
this._creatingPreset = true;
|
|
909
|
+
this._newPresetScenario = presetTypes[0]?.scenario ?? null;
|
|
910
|
+
this._newPresetName = "";
|
|
911
|
+
this._newPresetHeating = formatSetpointInput(DEFAULT_PRESET_HEATING_SETPOINT);
|
|
912
|
+
this._newPresetCooling = formatSetpointInput(DEFAULT_PRESET_COOLING_SETPOINT);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
private _cancelAddPreset() {
|
|
916
|
+
this._creatingPreset = false;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
private _newPresetNameFor(type: ThermostatPresetType): string | null {
|
|
920
|
+
const name = this._newPresetName.trim();
|
|
921
|
+
return type.supportsNames && name.length > 0 ? name : null;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
private async _handleSavePreset(presetHandle: string) {
|
|
925
|
+
const input = { name: this._editName, heating: this._editHeating, cooling: this._editCooling };
|
|
926
|
+
await this._runPresetWrite(
|
|
927
|
+
"Saving preset failed",
|
|
928
|
+
(current, presetTypes) => {
|
|
929
|
+
const preset = current.find(p => p.handle === presetHandle);
|
|
930
|
+
if (!preset) throw new Error("The preset no longer exists on the device");
|
|
931
|
+
const edited = applyPresetEdit(preset, presetTypes, input);
|
|
932
|
+
const conflict = presetNameConflict(current, edited.presetScenario, edited.name, presetHandle);
|
|
933
|
+
if (conflict !== null) throw new Error(conflict);
|
|
934
|
+
return current.map(p => (p.handle === presetHandle ? edited : toPresetEdit(p)));
|
|
935
|
+
},
|
|
936
|
+
() => {
|
|
937
|
+
if (this._editingPresetHandle === presetHandle) this._editingPresetHandle = null;
|
|
938
|
+
},
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
private async _handleAddPreset(selectedType: ThermostatPresetType | null) {
|
|
943
|
+
const node = this.node;
|
|
944
|
+
if (!node || selectedType === null) return;
|
|
945
|
+
const added: ThermostatPresetEdit = {
|
|
946
|
+
presetHandle: null,
|
|
947
|
+
presetScenario: selectedType.scenario,
|
|
948
|
+
name: this._newPresetNameFor(selectedType),
|
|
949
|
+
heatingSetpoint: isFeatureActive(node, this.endpoint, "HEAT")
|
|
950
|
+
? parseSetpointInput(this._newPresetHeating, DEFAULT_PRESET_HEATING_SETPOINT)
|
|
951
|
+
: null,
|
|
952
|
+
coolingSetpoint: isFeatureActive(node, this.endpoint, "COOL")
|
|
953
|
+
? parseSetpointInput(this._newPresetCooling, DEFAULT_PRESET_COOLING_SETPOINT)
|
|
954
|
+
: null,
|
|
955
|
+
builtIn: false,
|
|
956
|
+
};
|
|
957
|
+
await this._runPresetWrite(
|
|
958
|
+
"Adding preset failed",
|
|
959
|
+
current => {
|
|
960
|
+
const conflict = presetNameConflict(current, added.presetScenario, added.name, null);
|
|
961
|
+
if (conflict !== null) throw new Error(conflict);
|
|
962
|
+
return [...current.map(toPresetEdit), added];
|
|
963
|
+
},
|
|
964
|
+
() => {
|
|
965
|
+
this._creatingPreset = false;
|
|
966
|
+
},
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
private async _handleDeletePreset(preset: ThermostatPreset) {
|
|
971
|
+
const node = this.node;
|
|
972
|
+
const endpoint = this.endpoint;
|
|
973
|
+
if (!node || this._presetWriteOperation !== null) return;
|
|
974
|
+
|
|
975
|
+
const confirmed = await showPromptDialog({
|
|
976
|
+
title: "Remove preset",
|
|
977
|
+
text: `Remove "${formatPresetLabel(preset)}"? This cannot be undone.`,
|
|
978
|
+
confirmText: "Remove",
|
|
979
|
+
});
|
|
980
|
+
if (!confirmed || !this.isSameContext(node, endpoint)) return;
|
|
981
|
+
|
|
982
|
+
await this._runPresetWrite("Removing preset failed", current =>
|
|
983
|
+
current.filter(p => p.handle !== preset.handle).map(toPresetEdit),
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* Runs one Presets replacement for the shown node. `buildNext` gets the list as the device reports it; `onSuccess`
|
|
989
|
+
* runs only while the panel still shows this operation.
|
|
990
|
+
*/
|
|
991
|
+
private async _runPresetWrite(
|
|
992
|
+
failureTitle: string,
|
|
993
|
+
buildNext: (current: ThermostatPreset[], presetTypes: ThermostatPresetType[]) => ThermostatPresetEdit[],
|
|
994
|
+
onSuccess?: () => void,
|
|
995
|
+
) {
|
|
996
|
+
const node = this.node;
|
|
997
|
+
const endpoint = this.endpoint;
|
|
998
|
+
if (!node || this._presetWriteOperation !== null) return;
|
|
999
|
+
const presetTypes = readPresetTypes(node, endpoint) ?? [];
|
|
1000
|
+
|
|
1001
|
+
const operation = ++this._operationCounter;
|
|
1002
|
+
this._presetWriteOperation = operation;
|
|
1003
|
+
try {
|
|
1004
|
+
await writeThermostatPresets(this.client, node.node_id, endpoint, current =>
|
|
1005
|
+
buildNext(current, presetTypes),
|
|
1006
|
+
);
|
|
1007
|
+
if (this._presetWriteOperation === operation) onSuccess?.();
|
|
1008
|
+
} catch (err) {
|
|
1009
|
+
this._reportInvokeFailure(failureTitle, err, node, endpoint);
|
|
1010
|
+
} finally {
|
|
1011
|
+
if (this._presetWriteOperation === operation) this._presetWriteOperation = null;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
private async _handleSetActivePreset(presetHandle: string | null) {
|
|
1016
|
+
const node = this.node;
|
|
1017
|
+
const endpoint = this.endpoint;
|
|
1018
|
+
if (!node || this._activateOperation !== null) return;
|
|
1019
|
+
const operation = ++this._operationCounter;
|
|
1020
|
+
this._activateOperation = operation;
|
|
1021
|
+
try {
|
|
1022
|
+
await setActivePreset(this.client, node.node_id, endpoint, presetHandle);
|
|
1023
|
+
} catch (err) {
|
|
1024
|
+
this._reportInvokeFailure("Setting active preset failed", err, node, endpoint);
|
|
1025
|
+
} finally {
|
|
1026
|
+
if (this._activateOperation === operation) this._activateOperation = null;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
|
|
574
1030
|
/** Only alerts while the panel still shows the node the invoke was sent to; the dialog names no device. */
|
|
575
1031
|
private _reportInvokeFailure(title: string, err: unknown, node: MatterNode, endpoint: number) {
|
|
576
1032
|
if (!this.isSameContext(node, endpoint)) {
|
|
@@ -890,6 +1346,29 @@ class ThermostatClusterCommands extends BaseClusterCommands {
|
|
|
890
1346
|
flex-shrink: 0;
|
|
891
1347
|
}
|
|
892
1348
|
|
|
1349
|
+
.preset-row-editing {
|
|
1350
|
+
flex-wrap: wrap;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
.preset-row-editing label {
|
|
1354
|
+
font-size: 0.8rem;
|
|
1355
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
.preset-row-editing input[type="text"],
|
|
1359
|
+
.preset-row-editing input[type="number"] {
|
|
1360
|
+
padding: 6px 8px;
|
|
1361
|
+
border: 1px solid var(--md-sys-color-outline);
|
|
1362
|
+
border-radius: 4px;
|
|
1363
|
+
background: var(--md-sys-color-surface);
|
|
1364
|
+
color: var(--md-sys-color-on-surface);
|
|
1365
|
+
font: inherit;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
.preset-row-editing input[type="number"] {
|
|
1369
|
+
width: 70px;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
893
1372
|
.command-row select {
|
|
894
1373
|
padding: 8px;
|
|
895
1374
|
border: 1px solid var(--md-sys-color-outline);
|