fix: support Symcon numeric dimmers and independent blind slat controls
This commit is contained in:
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}`;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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}>
|
||||
|
||||
@@ -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"));
|
||||
});
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user