feat: improve Symcon designer controls and KNX temperature selection
This commit is contained in:
1 parent
804f2d0494
commit
b934f78b9a
24 files changed
+908
-562
No files matched your search
@@ -68,7 +68,7 @@ export class SymconBridge {
|
||||
private stateRevision = -1;
|
||||
private buildingRevision = -1;
|
||||
private objectsSignature = "";
|
||||
private refreshing = false;
|
||||
private refreshTask: Promise<void> | undefined;
|
||||
private states: Record<string, HassEntity> = {};
|
||||
private entities: Record<string, HassEntityEntry> = {};
|
||||
private areas: Record<string, HassArea> = {};
|
||||
@@ -80,6 +80,7 @@ export class SymconBridge {
|
||||
entities: this.entities,
|
||||
areas: this.areas,
|
||||
symconObjects: [],
|
||||
symconRefresh: () => this.refresh(true),
|
||||
config: { unit_system: { temperature: "°C" } },
|
||||
themes: { darkMode: window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? true },
|
||||
services: {},
|
||||
@@ -106,7 +107,7 @@ export class SymconBridge {
|
||||
this.apply(initial);
|
||||
this.stateRevision = initial.state_revision;
|
||||
this.buildingRevision = initial.building_revision;
|
||||
this.timer = setInterval(() => void this.refresh(), 800);
|
||||
this.timer = setInterval(() => void this.refresh().catch(() => undefined), 800);
|
||||
return this.snapshot();
|
||||
}
|
||||
|
||||
@@ -125,24 +126,27 @@ export class SymconBridge {
|
||||
return { ...this.facade, states: { ...this.states }, entities: { ...this.entities }, areas: { ...this.areas } };
|
||||
}
|
||||
|
||||
private async refresh(): Promise<void> {
|
||||
if (this.refreshing) return;
|
||||
this.refreshing = true;
|
||||
try {
|
||||
const next = await call<VariableSnapshot>(this.settings, "variables/snapshot", { revision: this.stateRevision });
|
||||
if (next.state_revision !== this.stateRevision && next.variables) {
|
||||
this.stateRevision = next.state_revision;
|
||||
this.apply({ variables: next.variables, areas: next.areas, objects: next.objects });
|
||||
for (const listener of this.changeListeners) listener();
|
||||
}
|
||||
if (next.building_revision !== this.buildingRevision) {
|
||||
this.buildingRevision = next.building_revision;
|
||||
for (const listener of this.buildingListeners) listener(next.building_revision);
|
||||
}
|
||||
} catch {
|
||||
// A temporary unavailable WebHook must not blank a running visualization. The next poll retries.
|
||||
} finally {
|
||||
this.refreshing = false;
|
||||
private refresh(force = false): Promise<void> {
|
||||
// A manual reload waits for an in-flight poll, then requests a complete fresh tree.
|
||||
if (this.refreshTask) return force ? this.refreshTask.catch(() => undefined).then(() => this.refresh(true)) : this.refreshTask;
|
||||
const task = this.loadSnapshot(force).finally(() => {
|
||||
if (this.refreshTask === task) this.refreshTask = undefined;
|
||||
});
|
||||
this.refreshTask = task;
|
||||
return task;
|
||||
}
|
||||
|
||||
private async loadSnapshot(force: boolean): Promise<void> {
|
||||
const next = force ? await call<Bootstrap>(this.settings, "bootstrap")
|
||||
: await call<VariableSnapshot>(this.settings, "variables/snapshot", { revision: this.stateRevision });
|
||||
if ((force || next.state_revision !== this.stateRevision) && next.variables) {
|
||||
this.stateRevision = next.state_revision;
|
||||
this.apply({ variables: next.variables, areas: next.areas, objects: next.objects });
|
||||
for (const listener of this.changeListeners) listener();
|
||||
}
|
||||
if (next.building_revision !== this.buildingRevision) {
|
||||
this.buildingRevision = next.building_revision;
|
||||
for (const listener of this.buildingListeners) listener(next.building_revision);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user