fix: support Symcon numeric dimmers and independent blind slat controls

This commit is contained in:
jhartworks committed 2026-11-09 15:24:59 +01:00
1 parent b934f78b9a
commit 24188f96f7
36 files changed
+1105 -683

No files matched your search

@@ -8,6 +8,7 @@ export interface EntityOption {
label: string;
/** A human-readable location, e.g. the path of an IP-Symcon variable in the object tree. */
detail?: string;
sourceEntity?: string;
}
/** Entities that carry a number: sensors and the number helpers. */
@@ -45,6 +46,7 @@ export function entityOptions(hass: HomeAssistant | undefined, accept: (id: stri
// In Symcon this is the complete object-tree path. The browser only uses the synthetic id internally;
// a person always picks a named variable from the tree path, never types an object id.
if (path) option.detail = `Objektbaum: ${path}`;
if (typeof state?.attributes.symcon_source_entity === "string") option.sourceEntity = state.attributes.symcon_source_entity;
return option;
})
.sort((a, b) => a.label.localeCompare(b.label));
@@ -7,7 +7,8 @@ import { iconPath } from "../../../icons.ts";
import { ceilingAt, FURNITURE_TYPES, isLamp, type LampMount, type Placement } from "../../../model.ts";
import { packItemLabel, packLabel } from "../../../furniture-names.ts";
import { isClimateFurniture, isElectric, isPackType, packType, type FurniturePack } from "../../../packs.ts";
import { checkField, deviceIcon, glowField, iconField, markerField, pinShiftField, numberField, selectField, textField } from "../fields.ts";
import { checkField, deviceIcon, entityField, glowField, iconField, markerField, pinShiftField, numberField, selectField, textField } from "../fields.ts";
import { entityOptions } from "../entities.ts";
import type { EditorHost } from "../host.ts";
import { lightEffectFields } from "../light-effect-fields.ts";
import { pluginDeviceSettings, pluginText, settingsWithDefaults } from "../../../plugins/registry.ts";
@@ -96,6 +97,7 @@ export function renderDeviceForm(host: EditorHost, placed: Placement, actions: D
${entityName(host.hass, placed.entity_id)}
</p>
<div class="nf-form">
${kind === "cover" ? entityField(host, t("cover_tilt_entity"), placed.cover_tilt ?? null, undefined, entityOptions(host.hass, (id) => id.startsWith("cover.")), (v) => set({ cover_tilt: v && v !== "none" ? v : null })) : nothing}
${light ? html`${selectField(host, t("lamp_mount"), mount, lampMounts, mountChange, { wide: true })}${glowField(host, placed.glow_scale, (v) => set({ glow_scale: v }))}` : nothing}
${light ? lightEffectFields(host, placed, host.hass?.states[placed.entity_id]?.attributes.effect_list, set) : nothing}
${placed.entity_id.startsWith("media_player.") ? glowField(host, placed.sound_rings, (v) => set({ sound_rings: v }), { label: "sound_rings", hint: "sound_rings_hint", lowest: 0 }) : nothing}
@@ -167,7 +167,9 @@ function blindFields(host: EditorHost, o: Opening, actions: OpeningActions, list
const window = o.type === "window";
const automatic = automaticLink(host, o, "cover");
const hasBlind = o.cover !== "none" && (o.cover || automatic);
return html`${entityField(host, t(window ? "cover_entity" : "door_cover"), o.cover, automatic, lists.covers, (v) => actions.update({ cover: v }))}
const symcon = host.hass?.symconObjects !== undefined;
return html`${entityField(host, t(symcon ? "symcon_cover_position" : window ? "cover_entity" : "door_cover"), o.cover, automatic, lists.covers, (v) => actions.update({ cover: v }))}
${symcon || (hasBlind && o.blind === "venetian") ? entityField(host, t("cover_tilt_entity"), o.cover_tilt ?? null, undefined, lists.covers, (v) => actions.update({ cover_tilt: noneAsNull(v) })) : nothing}
${hasBlind
? html`${entityField(host, t("cover_position_entity"), o.position ?? null, undefined, lists.positions, (v) => actions.update({ position: noneAsNull(v) }))}
${o.position ? checkField(host, t("cover_position_invert"), !!o.position_inverted, (on) => actions.update({ position_inverted: on })) : nothing}
@@ -177,6 +179,7 @@ function blindFields(host: EditorHost, o: Opening, actions: OpeningActions, list
${entityField(host, t("cover2_entity"), o.cover2 ?? null, undefined, lists.covers, (v) => actions.update({ cover2: noneAsNull(v) }))}`
: nothing}
${!window && o.type !== "garage" ? entityField(host, t("cover2_entity"), o.cover2 ?? null, undefined, lists.covers, (v) => actions.update({ cover2: noneAsNull(v) })) : nothing}
${o.cover2 && o.cover2 !== "none" ? entityField(host, t("cover2_tilt_entity"), o.cover2_tilt ?? null, undefined, lists.covers, (v) => actions.update({ cover2_tilt: noneAsNull(v) })) : nothing}
${numberField(host, t("cover_my"), o.my_position ?? 0, (v) => actions.update({ my_position: v > 0 ? Math.min(100, Math.round(v)) : null }), 5, 0)}
${hint(t("blind_hint"), "nf-wide")}`
: nothing}`;
+2
View File
@@ -12,6 +12,8 @@ export interface PickerOption {
label: string;
/** Secondary, non-editable context such as an IP-Symcon object-tree path. */
detail?: string;
/** Native variable entity behind an explicit Symcon light/cover role. */
sourceEntity?: string;
}
const MAX_SHOWN = 40;
+8 -4
View File
@@ -7,6 +7,7 @@ import { translate, type I18nKey } from "../i18n.ts";
import { openMoreInfo, stateText } from "../markers.ts";
import { tokens } from "../styles.ts";
import type { HassEntity, HomeAssistant } from "../types.ts";
import { coverWithTilt } from "../entities/covers.ts";
const COLORS: [number, number, number][] = [
[255, 181, 71],
@@ -45,6 +46,7 @@ export class NfQuickMenu extends LitElement {
presets: { attribute: false },
confirmSwitch: { type: Boolean },
myPosition: { attribute: false },
tiltEntity: { attribute: false },
low: { type: Boolean, reflect: true },
};
@@ -58,6 +60,7 @@ export class NfQuickMenu extends LitElement {
declare confirmSwitch: boolean;
/** Blinds: the favourite position (Somfy's "My", %), a button in the ring moves there; null = none. */
declare myPosition: number | null;
declare tiltEntity: string | null;
/** Tablet level: no blur behind the menu. */
declare low: boolean;
private t(key: I18nKey, vars?: Record<string, string | number>): string {
@@ -125,6 +128,7 @@ export class NfQuickMenu extends LitElement {
}
private renderCover(st: HassEntity) {
st = coverWithTilt(this.hass, st, this.tiltEntity);
const pos = typeof st.attributes.current_position === "number" ? (st.attributes.current_position as number) : null;
const moving = st.state === "opening" || st.state === "closing";
const setPos = coverPositionable(st);
@@ -138,9 +142,9 @@ export class NfQuickMenu extends LitElement {
...(setPos ? [75, 50].map((p) => slot(`${p}`, `${p} %`, () => this.ask() && this.call("cover", "set_cover_position", { position: p }), at(p))) : []),
slot("▼", this.t("cover_close"), () => this.ask() && this.call("cover", "close_cover"), at(0)),
...(setPos ? [25].map((p) => slot(`${p}`, `${p} %`, () => this.ask() && this.call("cover", "set_cover_position", { position: p }), at(p))) : []),
slot("■", this.t("cover_stop"), () => this.call("cover", "stop_cover"), moving),
...(Number(st.attributes.supported_features ?? 0) & 8 ? [slot("■", this.t("cover_stop"), () => this.call("cover", "stop_cover"), moving)] : []),
// the favourite position: a cover that sets positions goes there; a Somfy RTS motor without feedback goes to its own "My" on stop
...(this.myPosition != null
...(this.myPosition != null && (setPos || Number(st.attributes.supported_features ?? 0) & 8)
? [slot("My", this.t("cover_my_go", { p: this.myPosition }), () => this.ask() && (setPos ? this.call("cover", "set_cover_position", { position: this.myPosition }) : this.call("cover", "stop_cover")), at(this.myPosition))]
: []),
];
@@ -181,7 +185,7 @@ export class NfQuickMenu extends LitElement {
const tilt = typeof st.attributes.current_tilt_position === "number" ? (st.attributes.current_tilt_position as number) : null;
if (features & COVER_SET_TILT && tilt !== null)
return html`<label class="qm-tilt"
><span>${this.t("cover_tilt")} · ${tilt} %</span>
><span>${this.t("cover_tilt")} · ${Math.round(tilt)} %</span>
<input
class="qm-slider"
type="range"
@@ -189,7 +193,7 @@ export class NfQuickMenu extends LitElement {
max="100"
.value=${String(tilt)}
aria-label=${this.t("cover_tilt")}
@change=${(e: Event) => this.call("cover", "set_cover_tilt_position", { tilt_position: Number((e.target as HTMLInputElement).value) })}
@change=${(e: Event) => this.call("cover", "set_cover_tilt_position", { entity_id: this.tiltEntity || this.entity, tilt_position: Number((e.target as HTMLInputElement).value) })}
/></label>`;
if (features & (COVER_OPEN_TILT | COVER_CLOSE_TILT))
return html`<div class="qm-tilt-buttons">
+5 -2
View File
@@ -21,6 +21,7 @@ import { hassAt, loadHistory } from "../live/time-travel.ts";
import { curvePath } from "../live/day-curves.ts";
import { controls, tokens } from "../styles.ts";
import type { HassEntity, HomeAssistant } from "../types.ts";
import { coverTiltEntity, coverWithTilt } from "../entities/covers.ts";
const COVER_SET_POSITION = 4;
const COVER_STOP = 8;
@@ -676,7 +677,7 @@ export class NfRoomPanel extends LitElement {
${this.nameButton(id)}
<span class="nf-rp-state">${this.stateOf(st)}</span>
${this.toggle(st, on, () => this.call("light", "toggle", { entity_id: id }))}
${on && dimmable && !simple
${dimmable && !simple
? html`<label class="nf-rp-slider"
><span>${this.t("brightness")}</span>
<input
@@ -715,6 +716,8 @@ export class NfRoomPanel extends LitElement {
}
private coverRow(st: HassEntity) {
const tiltEntity = coverTiltEntity(this.hass, this.building?.floors ?? [], st.entity_id);
st = coverWithTilt(this.hass, st, tiltEntity);
const a = st.attributes;
const features = (a.supported_features as number | undefined) ?? 0;
const id = st.entity_id;
@@ -752,7 +755,7 @@ export class NfRoomPanel extends LitElement {
max="100"
?disabled=${na}
.value=${String(a.current_tilt_position)}
@change=${(e: Event) => this.call("cover", "set_cover_tilt_position", { entity_id: id, tilt_position: Number((e.target as HTMLInputElement).value) })}
@change=${(e: Event) => this.call("cover", "set_cover_tilt_position", { entity_id: tiltEntity ?? id, tilt_position: Number((e.target as HTMLInputElement).value) })}
/></label>`
: features & 48
? html`<div class="nf-rp-buttons">
@@ -28,6 +28,7 @@ export class SymconObjectPicker extends LitElement {
private declare _selected: number | null;
private tree: SymconTree = indexSymconTree([]);
private allowed = new Map<string, PickerOption>();
private allowedSources = new Map<string, string>();
constructor() {
super();
@@ -46,13 +47,17 @@ export class SymconObjectPicker extends LitElement {
protected willUpdate(changed: PropertyValues): void {
if (changed.has("objects")) this.tree = indexSymconTree(this.objects);
if (changed.has("options") || changed.has("fixed")) this.allowed = new Map([...this.fixed, ...this.options].map((option) => [option.id, option]));
if (changed.has("options") || changed.has("fixed")) {
this.allowed = new Map([...this.fixed, ...this.options].map((option) => [option.id, option]));
this.allowedSources = new Map(this.options.filter((o) => o.sourceEntity).map((o) => [o.sourceEntity!, o.id]));
}
}
private get dialog(): HTMLDialogElement | null { return this.renderRoot.querySelector("dialog"); }
private variableNode(entity: string | null): SymconObject | undefined {
const native = this.objects.find((node) => node.entity_id === entity && node.object_type === 2);
const source = this.allowed.get(entity ?? "")?.sourceEntity ?? entity;
const native = this.objects.find((node) => node.entity_id === source && node.object_type === 2);
return native ? this.tree.nodes.get(native.object_id) : undefined;
}
@@ -91,12 +96,18 @@ export class SymconObjectPicker extends LitElement {
private select(node: SymconObject): void {
this._active = node.object_id;
if (node.entity_id && this.allowed.has(node.entity_id)) {
this._pending = node.entity_id;
const entity = this.entityFor(node);
if (entity) {
this._pending = entity;
this._selected = node.object_id;
}
}
private entityFor(node: SymconObject): string | undefined {
if (!node.entity_id) return undefined;
return this.allowed.has(node.entity_id) ? node.entity_id : this.allowedSources.get(node.entity_id);
}
private async onTreeKey(event: KeyboardEvent): Promise<void> {
const rows = symconTreeRows(this.tree, this._expanded, this._query);
const i = Math.max(0, rows.findIndex((row) => row.node.object_id === this._active));
@@ -115,7 +126,7 @@ export class SymconObjectPicker extends LitElement {
else next = Math.max(0, rows.findIndex((item) => item.node.object_id === row.node.parent_id));
} else if (event.key === " " || event.key === "Enter") {
this.select(row.node);
if (event.key === "Enter" && row.node.entity_id && this.allowed.has(row.node.entity_id)) this.commit();
if (event.key === "Enter" && this.entityFor(row.node)) this.commit();
} else return;
event.preventDefault();
if (next !== i || this._active === null) this._active = rows[next].node.object_id;
@@ -138,11 +149,12 @@ export class SymconObjectPicker extends LitElement {
private renderRow(row: SymconTreeRow) {
const { node } = row;
const selectable = !!node.entity_id && this.allowed.has(node.entity_id);
const entity = this.entityFor(node);
const selectable = !!entity;
return html`<div id="object-${node.object_id}" role="treeitem"
aria-level=${row.depth + 1} aria-posinset=${row.index} aria-setsize=${row.siblings}
aria-expanded=${row.hasChildren ? String(row.expanded) : nothing}
aria-selected=${selectable ? String(node.object_id === this._selected && node.entity_id === this._pending) : nothing}
aria-selected=${selectable ? String(node.object_id === this._selected && entity === this._pending) : nothing}
aria-disabled=${node.entity_id && !selectable ? "true" : nothing}
class="node ${selectable ? "selectable" : ""} ${node.hidden ? "hidden-object" : ""} ${this._active === node.object_id ? "active" : ""}"
style=${`--depth:${row.depth}`} title=${node.path}
@@ -154,7 +166,7 @@ export class SymconObjectPicker extends LitElement {
</button>
${this.icon(node.object_type)}<span class="node-name">${node.name || "(Ohne Namen)"}</span>
<small>${node.virtual ? "Systembereich" : (TYPES[node.object_type] ?? "Objekt")}${node.hidden ? " · ausgeblendet" : ""}</small>
${selectable && node.object_id === this._selected && node.entity_id === this._pending ? html`<span class="selected-mark" aria-hidden="true">✓</span>` : nothing}
${selectable && node.object_id === this._selected && entity === this._pending ? html`<span class="selected-mark" aria-hidden="true">✓</span>` : nothing}
</div>`;
}
@@ -163,7 +175,7 @@ export class SymconObjectPicker extends LitElement {
const selectedNode = this.variableNode(this.value);
const pending = this.allowed.get(this._pending ?? "");
const selectedObject = this._selected === null ? undefined : this.tree.nodes.get(this._selected);
const pendingNode = (selectedObject?.entity_id === this._pending ? selectedObject : undefined) ?? this.variableNode(this._pending);
const pendingNode = (selectedObject && this.entityFor(selectedObject) === this._pending ? selectedObject : undefined) ?? this.variableNode(this._pending);
const rows = symconTreeRows(this.tree, this._expanded, this._query);
const active = rows.find((row) => row.node.object_id === this._active);
return html`<button type="button" class="trigger" ?disabled=${this.disabled} aria-haspopup="dialog" @click=${this.open}>
+2
View File
@@ -48,6 +48,7 @@ import { load3d } from "../load3d.ts";
import { scaleGlow, buildMarkers, openMoreInfo, stateText, toggleEntity, withPluginPatch } from "../markers.ts";
import { fanSpin } from "../entities/fans.ts";
import { fixtureGlow } from "../entities/kinds.ts";
import { coverTiltEntity } from "../entities/covers.ts";
import { furnitureShown, hiddenFurniture, withoutHidden } from "../entities/visibility.ts";
import { pictureUrl } from "../entities/pictures.ts";
import { fetchImage } from "../api.ts";
@@ -2282,6 +2283,7 @@ export class NfView3d extends LitElement {
.presets=${(this.building?.settings.media_presets ?? []).filter((p) => !p.speakers?.length || p.speakers.includes(m.entity))}
?confirmSwitch=${this.confirmSet.has(m.entity)}
.myPosition=${this.myPositionOf(m.entity)}
.tiltEntity=${coverTiltEntity(this.hass, this.building?.floors ?? [], m.entity)}
@close=${() => (this._menu = null)}
></nf-quick-menu>`;
}
@@ -37,7 +37,13 @@ test("the sensors of the rooms' areas are only watched when the heat map or room
});
test("opening links bring their blinds, contacts and positions along", () => {
const links = new Map([["o1", { cover: "cover.blind", contact: "binary_sensor.window", tilt: null, contact2: "binary_sensor.second", position: "sensor.pos" }]]);
const links = new Map([["o1", { cover: "cover.blind", coverTilt: "cover.slats", cover2Tilt: "cover.slats2", contact: "binary_sensor.window", tilt: null, contact2: "binary_sensor.second", position: "sensor.pos" }]]);
const ids = watchedEntities(inputs({ openingLinks: links as never }));
for (const id of ["cover.blind", "binary_sensor.window", "binary_sensor.second", "sensor.pos"]) assert.ok(ids.includes(id), id);
for (const id of ["cover.blind", "cover.slats", "cover.slats2", "binary_sensor.window", "binary_sensor.second", "sensor.pos"]) assert.ok(ids.includes(id), id);
});
test("a standalone blind's separate slat position is watched", () => {
const b = building();
b.floors[0].placements.push({ entity_id: "cover.blind", cover_tilt: "cover.slats", x: 2, z: 2, y: null });
assert.ok(watchedEntities(inputs({ building: b })).includes("cover.slats"));
});
+2 -1
View File
@@ -30,7 +30,7 @@ const furnitureOf = (b: Building) => b.floors.flatMap((f) => f.furniture);
/** The sensors and entities behind the openings: blinds, contacts, tilt, positions. */
function openingIds(links: WatchInputs["openingLinks"]): MaybeId[] {
return [...links.values()].flatMap((e) => [e.cover, e.cover2, e.contact, e.tilt, e.contact2, e.tilt2, e.position, e.tiltAngle]);
return [...links.values()].flatMap((e) => [e.cover, e.cover2, e.coverTilt, e.cover2Tilt, e.contact, e.tilt, e.contact2, e.tilt2, e.position, e.tiltAngle]);
}
/** What furniture is linked to besides its device: state lights, doors and thermometers of a fridge, battery, status, charge, export, pictures. */
@@ -62,6 +62,7 @@ export function watchedEntities(inputs: WatchInputs): string[] {
const sensorsOfRooms = inputs.needsRoomSensors ? roomsOf(b).flatMap((r) => roomEntities(hass, r).filter((id) => id.startsWith("sensor.") || id.startsWith("climate."))) : [];
const ids: MaybeId[] = [
...placed,
...b.floors.flatMap((f) => f.placements.map((p) => p.cover_tilt)),
...openingIds(inputs.openingLinks),
...placed.map((id) => powerSensorFor(hass, id)),
// what plugins draw for a device may follow further entities (a camera's motion sensor)
+15 -2
View File
@@ -1,10 +1,23 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { entity, hassOf } from "./fixtures.ts";
import { coverPosition, coverReaches } from "./covers.ts";
import { box, entity, floorWith, hassOf, opening } from "./fixtures.ts";
import { coverPosition, coverReaches, coverTiltEntity, coverWithTilt } from "./covers.ts";
import { emptyBuilding, newFloor, type Furniture } from "../model.ts";
import { setPacks, type PackItem } from "../packs.ts";
test("separate slat sources are resolved per blind and enrich only its control state", () => {
const hass = hassOf([entity("cover.height", "open", { current_position: 40, supported_features: 4 }), entity("cover.slats", "open", { current_position: 75 })]);
const floor = floorWith([box("r", 0, 0, 4, 4)], { openings: [opening("w", "r", "window", { cover: "cover.height", cover_tilt: "cover.slats" })] });
assert.equal(coverTiltEntity(hass, [floor], "cover.height"), "cover.slats");
const state = coverWithTilt(hass, hass.states["cover.height"], "cover.slats");
assert.equal(state.attributes.current_position, 40);
assert.equal(state.attributes.current_tilt_position, 75);
assert.equal(state.attributes.supported_features, 132);
assert.equal(hass.states["cover.height"].attributes.current_tilt_position, undefined, "one opening's mapping must not mutate a shared source");
const placed = floorWith([], { placements: [{ entity_id: "cover.height", cover_tilt: "cover.slats", x: 1, z: 1, y: null }] });
assert.equal(coverTiltEntity(hass, [placed], "cover.height"), "cover.slats", "standalone placed blinds also support a separate slat variable");
});
test("a cover's position comes from its attribute, else from open / closed", () => {
const hass = hassOf([
entity("cover.a", "open", { current_position: 40 }),
+21 -2
View File
@@ -1,9 +1,28 @@
// Pack items with moving parts (curtains, roller screens, awnings, gates) and the cover entity they follow.
import type { Building } from "../model.ts";
import type { Building, Floor } from "../model.ts";
import { coverReach, hasMovingParts, packItem } from "../packs.ts";
import type { HomeAssistant } from "../types.ts";
import type { HassEntity, HomeAssistant } from "../types.ts";
import { isUnavailable } from "./kinds.ts";
import { openingEntities } from "./openings.ts";
/** The separately selected slat variable of either blind of an opening. */
export function coverTiltEntity(hass: HomeAssistant, floors: readonly Floor[], id: string): string | null {
for (const f of floors) for (const p of f.placements) if (p.entity_id === id && p.cover_tilt && p.cover_tilt !== "none") return p.cover_tilt;
for (const e of openingEntities(hass, floors).values()) {
if (e.cover === id && e.coverTilt) return e.coverTilt;
if (e.cover2 === id && e.cover2Tilt) return e.cover2Tilt;
}
return null;
}
export function coverWithTilt(hass: HomeAssistant, st: HassEntity, tilt: string | null | undefined): HassEntity {
if (!tilt) return st;
const a = hass.states[tilt]?.attributes;
const position = a?.current_tilt_position ?? a?.current_position;
if (typeof position !== "number") return st;
return { ...st, attributes: { ...st.attributes, current_tilt_position: position, supported_features: Number(st.attributes.supported_features ?? 0) | 128 } };
}
/** How far open a cover is in percent: its position, else 100 / 0 from open / closed (moving counts half). Null when unknown. */
export function coverPosition(hass: HomeAssistant, id: string | null | undefined): number | null {
+1 -1
View File
@@ -248,7 +248,7 @@ export function roomPanelEntities(hass: HomeAssistant, floor: Floor, room: Room)
.filter((o) => o.room_id === room.id)
.flatMap((o) => {
const e = openingLinks.get(o.id);
return e ? [e.cover, e.contact, e.tilt, e.contact2] : [];
return e ? [e.cover, e.cover2, e.contact, e.tilt, e.contact2] : [];
}),
...(room.panel ?? []),
];
+13
View File
@@ -184,3 +184,16 @@ test("a wide window's second blind and a venetian blind's slats", () => {
assert.equal(state.slats, 0.3);
assert.equal(openingState(hass, { cover: "cover.right", contact: null, tilt: null }).cover2, undefined, "no second blind");
});
test("a separate integer slat variable changes the 3D slats independently of the blind height", () => {
const hass = hassOf([
entity("cover.height", "open", { current_position: 40 }),
entity("cover.slats", "open", { current_position: 75 }),
]);
const state = openingState(hass, { cover: "cover.height", coverTilt: "cover.slats", contact: null, tilt: null });
assert.equal(state.cover, 0.6);
assert.equal(state.slats, 0.75);
const double = openingState(hass, { cover: "cover.height", coverTilt: "cover.slats", cover2: "cover.slats", cover2Tilt: "cover.height", contact: null, tilt: null });
assert.equal(double.slats, 0.75);
assert.equal(double.slats2, 0.4);
});
+17 -5
View File
@@ -7,6 +7,7 @@ import { roomEntities } from "./registry.ts";
export interface OpeningEntities {
cover: string | null;
coverTilt?: string | null;
contact: string | null;
tilt: string | null;
/** Contact and tilt sensor of the second leaf of a double door or window. */
@@ -28,6 +29,7 @@ export interface OpeningEntities {
lock?: string | null;
/** A second blind of a wide window (its right half, seen from the room). */
cover2?: string | null;
cover2Tilt?: string | null;
}
const BLIND_CLASSES = new Set([undefined, "shutter", "blind", "awning", "shade", "curtain", "window"]);
@@ -91,6 +93,8 @@ export function openingEntities(hass: HomeAssistant, floors: readonly Floor[]):
angled: o.type === "door" && !!o.open_angle,
lock: o.type === "door" ? unlessNone(o.lock) : null,
cover2: o.type === "garage" ? null : unlessNone(o.cover2),
coverTilt: unlessNone(o.cover_tilt),
cover2Tilt: unlessNone(o.cover2_tilt),
});
}
}
@@ -146,8 +150,9 @@ function coverClosed(hass: HomeAssistant, id: string | null | undefined): number
}
/** How far the slats of a venetian blind are open (0 shut, 1 level), from its tilt position; null when it reports none. */
function slatsOpen(hass: HomeAssistant, id: string | null | undefined): number | null {
const tilt = id ? hass.states[id]?.attributes.current_tilt_position : undefined;
function slatsOpen(hass: HomeAssistant, id: string | null | undefined, separate?: string | null): number | null {
const a = hass.states[separate || id || ""]?.attributes;
const tilt = a?.current_tilt_position ?? (separate ? a?.current_position : undefined);
return typeof tilt === "number" ? Math.min(100, Math.max(0, tilt)) / 100 : null;
}
@@ -185,6 +190,7 @@ export interface OpeningState {
cover2?: number | null;
/** Venetian blinds: how far the slats are open (0 shut, 1 level), from the cover's tilt position. */
slats?: number | null;
slats2?: number | null;
}
/**
@@ -196,12 +202,19 @@ export function openingState(hass: HomeAssistant, e: OpeningEntities, type: Open
const isKnown = (id: string | null | undefined) => !!id && !!hass.states[id] && !isUnavailable(hass.states[id]);
const positionOf = (id: string | null | undefined) => (id ? windowPosition(hass.states[id]) : null);
const cover = blindClosedFraction(hass, e);
const slats = slatsOpen(hass, e.cover, e.coverTilt);
const slats2 = slatsOpen(hass, e.cover2, e.cover2Tilt);
const blindState = {
...(e.cover2 ? { cover2: coverClosed(hass, e.cover2) } : {}),
...(slats !== null ? { slats } : {}),
...(slats2 !== null ? { slats2 } : {}),
};
if (type === "door") {
// a door with a roller shutter (front door, patio door): the blind comes down over it
const leaf = positionOf(e.contact);
const open = leaf === null ? (e.shut ? 0 : e.angled ? 1 : DOOR_DEFAULT_OPEN) : leaf === "closed" ? 0 : 1;
return { open, open2: positionOf(e.contact2) === "open" ? 1 : 0, tilt: 0, tilt2: 0, cover, sensed: leaf !== null || cover !== null, unlocked: isUnlocked(hass, e.lock), assumed: leaf === null };
return { open, open2: positionOf(e.contact2) === "open" ? 1 : 0, tilt: 0, tilt2: 0, cover, ...blindState, sensed: leaf !== null || cover !== null, unlocked: isUnlocked(hass, e.lock), assumed: leaf === null };
}
if (type === "garage") {
// a garage door without a cover shows its contact: open or closed; so does one whose cover cannot tell (a remote without
@@ -231,7 +244,6 @@ export function openingState(hass: HomeAssistant, e: OpeningEntities, type: Open
tilt2: secondTilted ? 1 : 0,
cover,
sensed: isKnown(e.contact) || isKnown(e.tilt) || Number.isFinite(rawAngle),
...(e.cover2 ? { cover2: coverClosed(hass, e.cover2) } : {}),
...(slatsOpen(hass, e.cover) !== null ? { slats: slatsOpen(hass, e.cover) } : {}),
...blindState,
};
}
+6
View File
@@ -24,6 +24,9 @@ const DE = {
needs_reload: "Diese Seite zeigt noch NextFloor {frontend}, Home Assistant hat schon {backend}. Bitte die Seite neu laden; in der Companion-App: Einstellungen → Companion-App → Frontend-Cache zurücksetzen.",
reload_page: "Neu laden",
symcon_variables_reload: "Variablen neu laden",
symcon_cover_position: "Position (Behang)",
cover_tilt_entity: "Lamellenposition",
cover2_tilt_entity: "Lamellenposition (zweiter Behang)",
symcon_variables_loading: "Variablen werden geladen …",
symcon_variables_loaded: "Variablen und Objektbaum wurden neu geladen.",
symcon_variables_error: "Variablen konnten nicht neu geladen werden: {error}",
@@ -2047,6 +2050,9 @@ const EN: Record<Key, string> = {
needs_reload: "This page still shows NextFloor {frontend}, Home Assistant already has {backend}. Please reload the page; in the companion app: Settings → Companion app → Reset frontend cache.",
reload_page: "Reload",
symcon_variables_reload: "Reload variables",
symcon_cover_position: "Blind position",
cover_tilt_entity: "Slat position",
cover2_tilt_entity: "Slat position (second blind)",
symcon_variables_loading: "Loading variables …",
symcon_variables_loaded: "Variables and object tree reloaded.",
symcon_variables_error: "Could not reload variables: {error}",
+5
View File
@@ -158,8 +158,11 @@ export interface Opening {
/** Ask before moving the blind or garage door; it then does not follow a swipe either. */
confirm?: boolean;
cover: EntityRef;
/** Separate numeric control for the venetian blind's slat position. */
cover_tilt?: EntityRef;
/** Windows and doors: a second blind for the right half (seen from the room) of a wide window. */
cover2?: string | null;
cover2_tilt?: EntityRef;
/** The kind of blind: a roller shutter outside (null, default), a venetian blind (Raffstore) outside with slats, or a roller blind inside. */
blind?: "roller" | "venetian" | "inside" | null;
/** The favourite position of the blind (%, open = 100) – Somfy's "My": a button in its menu moves it there. */
@@ -336,6 +339,8 @@ export interface Placement extends LightEffectConfig {
confirm?: boolean;
/** Lights: only the switch in the room panel, without brightness, colour temperature and colours. */
simple?: boolean;
/** A placed blind's separate slat position control. */
cover_tilt?: EntityRef;
/** Its marker in 3D: automatic (null), always shown, shown without watts, or hidden. */
marker?: MarkerShow | null;
/** An own symbol for the marker: a Material Design icon name without "mdi:" (null = by kind). */
+20
View File
@@ -1,6 +1,8 @@
import assert from "node:assert/strict";
import { test, type TestContext } from "node:test";
import { SymconBridge } from "./symcon-bridge.ts";
import { entityOptions } from "./components/editor/entities.ts";
import { areaEntities } from "./entities/registry.ts";
function mockWindow(context: TestContext): void {
const previous = Object.getOwnPropertyDescriptor(globalThis, "window");
@@ -11,6 +13,24 @@ function mockWindow(context: TestContext): void {
});
}
test("numeric control roles stay selectable in the real tree without duplicating automatic device lists", async (context) => {
mockWindow(context);
context.mock.method(globalThis, "fetch", async () => new Response(JSON.stringify({ state_revision: 1, building_revision: 1, areas: [{ area_id: "room", name: "Raum" }],
variables: [{ entity_id: "sensor.6", name: "Dimmerwert", path: "Haus / KNX / Dimmerwert", state: "128", area_id: "room",
attributes: { symcon_id: 6, symcon_variable_type: 1, symcon_numeric_value: 128, symcon_min: 0, symcon_max: 255 } }],
objects: [{ object_id: 6, parent_id: 0, entity_id: "sensor.6", name: "Dimmerwert", object_type: 2 }] })));
const bridge = new SymconBridge();
try {
const hass = await bridge.start();
assert.equal(hass.states["light.6"].attributes.brightness, 128);
assert.equal(hass.states["cover.6"].attributes.current_position, 128 / 255 * 100);
assert.equal(entityOptions(hass, (id) => id.startsWith("light."))[0].sourceEntity, "sensor.6");
assert.ok(!areaEntities(hass, "room").includes("light.6"));
assert.ok(!areaEntities(hass, "room").includes("cover.6"));
assert.equal(hass.symconObjects?.length, 1, "no artificial duplicate nodes in the native object tree");
} finally { bridge.stop(); }
});
test("manual reload waits for polling, replaces removed variables and reloads the whole tree", async (context) => {
mockWindow(context);
const variable = (id: number) => ({ entity_id: `sensor.${id}`, name: "KNX Wert", path: "Haus / KNX / Wert", state: "21.75", attributes: { unit_of_measurement: "°C" } });
+10
View File
@@ -6,6 +6,7 @@
import type { HassArea, HassEntity, HassEntityEntry, HomeAssistant, SymconObject } from "./types.ts";
import { callSymcon as call } from "./symcon-api.ts";
import { symconControl } from "./symcon-controls.ts";
interface SymconConfig {
endpoint: string;
@@ -172,6 +173,15 @@ export class SymconBridge {
} satisfies HassEntityEntry,
]),
);
// Role aliases are offered only when deliberately choosing a control. They never pollute automatic room lists.
for (const state of Object.values(this.states)) {
for (const role of ["light", "cover"] as const) {
const control = symconControl(state, role);
if (!control || control.entity_id === state.entity_id || this.states[control.entity_id]) continue;
this.states[control.entity_id] = control;
this.entities[control.entity_id] = { ...this.entities[state.entity_id], entity_id: control.entity_id, hidden: true };
}
}
if (data.areas) this.areas = Object.fromEntries(data.areas.map((area) => [area.area_id, area]));
this.facade.states = this.states;
this.facade.entities = this.entities;
+18
View File
@@ -0,0 +1,18 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { symconControl, symconPercent } from "./symcon-controls.ts";
import { entity } from "./entities/fixtures.ts";
test("integer dimmers, normalized floats and separate blind variables preserve their native ranges", () => {
const integer = entity("cover.6", "open", { symcon_id: 6, symcon_numeric_value: 128, symcon_min: 0, symcon_max: 255 });
const light = symconControl(integer, "light")!;
assert.equal(light.entity_id, "light.6");
assert.equal(light.attributes.brightness, 128);
assert.deepEqual(light.attributes.supported_color_modes, ["brightness"]);
assert.equal(light.attributes.symcon_source_entity, "cover.6");
const fraction = entity("sensor.7", "0.4", { symcon_id: 7, symcon_numeric_value: 0.4, symcon_min: 0, symcon_max: 1 });
assert.equal(symconControl(fraction, "light")!.attributes.brightness, 102);
assert.equal(symconControl(fraction, "cover")!.attributes.current_position, 40);
assert.equal(symconPercent(entity("sensor.low", "10", { symcon_numeric_value: 10, symcon_min: 10, symcon_max: 110 })), 0);
assert.equal(symconControl(entity("switch.8", "on", { symcon_id: 8, symcon_variable_type: 0 }), "light"), null, "a boolean switch cannot pretend to dim");
});
+25
View File
@@ -0,0 +1,25 @@
// A Symcon numeric variable can be explicitly used as a light or a blind, regardless of its inferred domain.
import type { HassEntity } from "./types.ts";
export function symconPercent(st: HassEntity): number | null {
const a = st.attributes;
if (typeof a.symcon_numeric_value !== "number") return null;
const min = typeof a.symcon_min === "number" ? a.symcon_min : 0;
const max = typeof a.symcon_max === "number" && a.symcon_max > min ? a.symcon_max : 100;
return Math.max(0, Math.min(100, (a.symcon_numeric_value - min) / (max - min) * 100));
}
export function symconControl(st: HassEntity, role: "light" | "cover"): HassEntity | null {
const percent = symconPercent(st);
const id = st.attributes.symcon_id;
if (percent === null || typeof id !== "number") return null;
return {
...st, entity_id: `${role}.${id}`,
state: role === "light" ? (percent > 0 ? "on" : "off") : (percent > 0 ? "open" : "closed"),
attributes: { ...st.attributes,
...(role === "light" ? { brightness: Math.round(percent * 2.55), color_mode: "brightness", supported_color_modes: ["brightness"] }
: { current_position: percent, supported_features: 4 }),
...(st.entity_id !== `${role}.${id}` ? { symcon_source_entity: st.entity_id } : {}),
},
};
}
+5 -3
View File
@@ -26,13 +26,15 @@ export function blind(c: Ctx): void {
// the cassette above the opening: a big box outside, a slim one on the room side for an inside blind
if (kind === "inside") splitBox(c.frames, frame, { x0: -0.03, x1: W + 0.03, n0: inside, n1: inside + 0.07, y0: T - 0.02, y1: T + 0.07 }, new Color(0xf2f2f2), new Color(0xf7f7f7), fold);
else splitBox(c.frames, frame, { x0: -0.05, x1: W + 0.05, n0: outside - 0.15, n1: outside, y0: T, y1: T + 0.2 }, new Color(BLIND_BOX), new Color(FRAME_TOP), fold);
const halves: [number, number, number][] = state.cover2 != null ? [[0, W / 2, state.cover], [W / 2, W, state.cover2]] : [[0, W, state.cover]];
for (const [x0, x1, cover] of halves) {
const halves: [number, number, number, number][] = state.cover2 != null
? [[0, W / 2, state.cover, state.slats ?? 0], [W / 2, W, state.cover2, state.slats2 ?? state.slats ?? 0]]
: [[0, W, state.cover, state.slats ?? 0]];
for (const [x0, x1, cover, tilt] of halves) {
const closed = Math.min(1, Math.max(0, cover));
if (closed <= 0.01) continue;
const bottom = T - closed * (T - S);
if (kind === "inside") panel(c.blinds, frame, x0 + 0.01, x1 - 0.01, inside + 0.04, bottom, T - 0.02, new Color(FABRIC), fold);
else if (kind === "venetian") slats(c, x0, x1, outside - 0.07, bottom, T, state.slats ?? 0);
else if (kind === "venetian") slats(c, x0, x1, outside - 0.07, bottom, T, tilt);
else panel(c.blinds, frame, x0, x1, outside - 0.07, bottom, T, new Color(SHUTTER), fold, 0.045);
}
}
@@ -17,6 +17,15 @@ const triangles = (g: { getAttribute(n: string): { count: number } | undefined }
const build = (opening: Partial<Opening>, state: Partial<OpeningState> = {}, cut = 1.2) => buildOpeningParts(infosFor(opening), new Map([["o", { ...CLOSED, ...state }]]), cut);
const positions = (g: { getAttribute(n: string): { array: ArrayLike<number> } | undefined }) => Array.from(g.getAttribute("position")?.array ?? []);
test("each half of a venetian blind turns only its own slats", () => {
const shut = positions(build({ blind: "venetian" }, { cover: 1, cover2: 1, slats: 0, slats2: 0 }).blinds);
const rightOpen = positions(build({ blind: "venetian" }, { cover: 1, cover2: 1, slats: 0, slats2: 1 }).blinds);
const left = (values: number[]) => values.flatMap((_, i) => i % 3 === 0 && values[i] < 1.5 - 1e-4 ? values.slice(i, i + 3) : []);
assert.ok(left(shut).length > 0);
assert.deepEqual(left(shut), left(rightOpen), "the other half must stay still");
assert.notDeepEqual(shut, rightOpen);
});
test("a window has frame parts and glass, and no blind without a cover", () => {
const parts = build({});
assert.ok(triangles(parts.frames) > 20);
+1
View File
@@ -21,6 +21,7 @@ export interface OpeningState {
cover2?: number | null;
/** Venetian blinds: how far the slats are open (0 shut, 1 level). */
slats?: number | null;
slats2?: number | null;
}
export const CLOSED: OpeningState = { open: 0, open2: 0, tilt: 0, tilt2: 0, cover: null };