feat: improve Symcon controls, device readings and designer help
This commit is contained in:
1 parent
ff54f4461a
commit
00fca890de
50 files changed
+2447
-1840
No files matched your search
@@ -1,6 +1,8 @@
|
||||
// 2D editor: floors, rooms (rectangles and free shapes), snapping, undo, background template.
|
||||
|
||||
import { html, LitElement, nothing, svg, type PropertyValues, type TemplateResult } from "lit";
|
||||
import { withCoverControls } from "../entities/cover-controls.ts";
|
||||
import { hint } from "./editor/fields.ts";
|
||||
import { fetchImage, importPack, storeImage } from "../api.ts";
|
||||
import { defaultHeight, entityName, kindOf, roomEntities } from "../devices.ts";
|
||||
import { closeGaps, suggestedThickness } from "../geometry/gaps.ts";
|
||||
@@ -1043,7 +1045,7 @@ export class NfEditor extends LitElement {
|
||||
</div>`}
|
||||
${this.render3dBar()}
|
||||
<nf-view3d
|
||||
.hass=${this.hass}
|
||||
.hass=${this.hass ? withCoverControls(this.hass, this._doc3d.floors) : undefined}
|
||||
.building=${this._doc3d}
|
||||
.floorId=${this.houseTool ? null : this._floorId}
|
||||
.roomId=${null}
|
||||
@@ -3210,7 +3212,7 @@ export class NfEditor extends LitElement {
|
||||
${this.planLayers(floor, walls?.walls ?? null)}
|
||||
</svg>
|
||||
${this.renderContext()}
|
||||
<p class="nf-hint ${this._fixedHint ? "nf-hint-fixed" : ""}">${this._pick ? this.t("robot_cal_doing") : !floor ? this.t("hint_empty") : this._fixedHint ? this.t("fixed_drag_hint") : this.t(`hint_${this._tool}` as I18nKey)}</p>
|
||||
${this._pick || this._fixedHint ? html`<p class="nf-hint ${this._fixedHint ? "nf-hint-fixed" : ""}">${this._pick ? this.t("robot_cal_doing") : this.t("fixed_drag_hint")}</p>` : html`<div class="nf-hint">${hint(!floor ? this.t("hint_empty") : this.t(`hint_${this._tool}` as I18nKey))}</div>`}
|
||||
<button class="nf-keys-open" title=${this.t("keys_title")} aria-label=${this.t("keys_title")} @click=${() => (this._keys = true)}>?</button>
|
||||
${this.isAdmin
|
||||
? renderTour((k, vars) => this.t(k, vars), this._tour, (step) => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { LitElement, html, nothing, type PropertyValues } from "lit";
|
||||
import { uid, type BleFingerprint, type BleTag } from "../../model.ts";
|
||||
import { fingerprintsOf, locate, RECORD_SECONDS, replaceRoom, signalLevel, type Reading } from "./ops/ble.ts";
|
||||
import type { EditorHost } from "./host.ts";
|
||||
import { hint } from "./fields.ts";
|
||||
|
||||
interface Scan {
|
||||
address: string | null;
|
||||
@@ -187,7 +188,7 @@ export class NfBleLocate extends LitElement {
|
||||
<span class="nf-ble-track"><span class="nf-ble-fill" style="width:${Math.round(signalLevel(r.rssi) * 100)}%"></span></span>
|
||||
<span class="nf-ble-db">${Math.round(r.rssi)}</span>
|
||||
</div>`)}
|
||||
${entries.length === 1 ? html`<p class="nf-sub">${t("ble_one_scanner")}</p>` : nothing}
|
||||
${entries.length === 1 ? hint(t("ble_one_scanner")) : nothing}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
@@ -215,7 +216,7 @@ export class NfBleLocate extends LitElement {
|
||||
</button>
|
||||
${this._room && count(this._room) ? html`<button class="nf-btn" ?disabled=${recording} @click=${() => this.update2(tag.id, (x) => (x.prints = x.prints.filter((p) => p.room !== this._room)))}>${t("ble_forget_room")}</button>` : nothing}
|
||||
</div>
|
||||
<p class="nf-sub">${t("ble_learn_hint")}</p>`;
|
||||
${hint(t("ble_learn_hint"))}`;
|
||||
}
|
||||
|
||||
protected render() {
|
||||
@@ -238,7 +239,7 @@ export class NfBleLocate extends LitElement {
|
||||
<button class="nf-btn" title=${t("delete")} @click=${() => this.removeTag(x.id)}>✕</button>
|
||||
</div>`,
|
||||
)}
|
||||
${tag ? html`<div class="nf-ble-learn">${this.learn(tag)}<p class="nf-sub">${t("ble_sensor_hint", { name: tag.name })}</p></div>` : nothing}
|
||||
${tag ? html`<div class="nf-ble-learn">${this.learn(tag)}${hint(t("ble_sensor_hint", { name: tag.name }))}</div>` : nothing}
|
||||
<div class="nf-form">
|
||||
<label class="nf-field nf-wide">${t("ble_add")}
|
||||
<select .value=${this._pick} @change=${(e: Event) => (this._pick = (e.target as HTMLSelectElement).value)}>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { html, type TemplateResult } from "lit";
|
||||
import { uid, type DeviceValueLink } from "../../model.ts";
|
||||
import { valueSymbol } from "../../entities/device-values.ts";
|
||||
import { entityOptions } from "./entities.ts";
|
||||
import { entityField, hint, textField } from "./fields.ts";
|
||||
import type { EditorHost } from "./host.ts";
|
||||
|
||||
export function renderDeviceValues(host: EditorHost, links: readonly DeviceValueLink[] = [], set: (next: DeviceValueLink[] | undefined) => void): TemplateResult {
|
||||
const options = entityOptions(host.hass, (id) => !host.hass?.states[id]?.attributes.symcon_source_entity || links.some((l) => l.entity === id));
|
||||
const patch = (id: string, change: Partial<DeviceValueLink>) => set(links.map((l) => l.id === id ? { ...l, ...change } : l));
|
||||
return html`<div class="nf-value-links nf-wide">
|
||||
<div class="nf-h3row"><h4>${host.t("device_values")}</h4><button class="nf-btn nf-value-add" title=${host.t("device_value_add")} aria-label=${host.t("device_value_add")} ?disabled=${!host.admin} @click=${() => set([...links, { id: uid("value"), entity: null }])}>+</button></div>
|
||||
${links.map((l, i) => html`<div class="nf-form nf-value-link" data-value=${l.id}>
|
||||
${entityField(host, `${host.t("device_value")} ${i + 1}`, l.entity, undefined, options, (v) => patch(l.id, { entity: v === "none" ? null : v }))}
|
||||
${textField(host, host.t("device_value_icon"), l.icon ?? "", (icon) => patch(l.id, { icon: icon || null }), { maxlength: 16, placeholder: valueSymbol(l.entity ? host.hass?.states[l.entity] : undefined) })}
|
||||
${textField(host, host.t("device_value_label"), l.label ?? "", (label) => patch(l.id, { label: label || null }), { maxlength: 60 })}
|
||||
<button class="nf-link nf-value-remove nf-wide" ?disabled=${!host.admin} @click=${() => { const next = links.filter((v) => v.id !== l.id); set(next.length ? next : undefined); }}>× ${host.t("device_value_remove")}</button>
|
||||
</div>`)}
|
||||
${hint(host.t("device_values_hint"))}
|
||||
</div>`;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import type { EntityOption } from "./entities.ts";
|
||||
import type { EditorHost } from "./host.ts";
|
||||
import { pluginMdiIcon } from "../../plugins/registry.ts";
|
||||
import "../entity-picker.ts";
|
||||
import "../help-popup.ts";
|
||||
|
||||
const valueOf = (e: Event) => (e.target as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement).value;
|
||||
|
||||
@@ -150,7 +151,7 @@ export function pinShiftField(host: EditorHost, value: PinOffset | null | undefi
|
||||
<div class="nf-form">
|
||||
${numberField(host, "↔ x", v.x ?? 0, set("x"), 0.05)} ${numberField(host, "↕ z", v.z ?? 0, set("z"), 0.05)} ${numberField(host, host.t("pin_shift_up"), v.y ?? 0, set("y"), 0.05)}
|
||||
${value ? html`<button class="nf-btn nf-field-btn" ?disabled=${!host.admin} @click=${() => onChange(null)}>${host.t("height_auto")}</button>` : nothing}
|
||||
<p class="nf-sub nf-wide">${host.t("pin_shift_hint")}</p>
|
||||
${hint(host.t("pin_shift_hint"), "nf-wide")}
|
||||
</div>
|
||||
</details>`;
|
||||
}
|
||||
@@ -158,8 +159,8 @@ export function pinShiftField(host: EditorHost, value: PinOffset | null | undefi
|
||||
/** A row of buttons at the bottom of a form. */
|
||||
export const actions = (...buttons: (TemplateResult | typeof nothing)[]): TemplateResult => html`<div class="nf-actions">${buttons}</div>`;
|
||||
|
||||
/** A help line under a form. */
|
||||
export const hint = (text: string, extraClass = ""): TemplateResult => html`<p class="nf-sub ${extraClass}">${text}</p>`;
|
||||
/** A compact information button that opens the explanation in a dialog. */
|
||||
export const hint = (text: string, extraClass = ""): TemplateResult => html`<nf-help-popup class=${extraClass} .text=${text}></nf-help-popup>`;
|
||||
|
||||
/** A percentage between 10 and 150 for how strongly a lamp glows. 100 % is stored as "no value of its own". */
|
||||
export function glowField(host: EditorHost, value: number | null | undefined, onChange: (v: number | null) => void, o: { label?: I18nKey; hint?: I18nKey; lowest?: number } = {}): TemplateResult {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// fields or the furniture; only what depends on the compass follows (the sun's light, wind, the compass labels of roof faces).
|
||||
|
||||
import { html, svg, type TemplateResult } from "lit";
|
||||
import { numberField } from "../fields.ts";
|
||||
import { hint, numberField } from "../fields.ts";
|
||||
import type { EditorHost } from "../host.ts";
|
||||
import { turnedNorth } from "../ops/settings.ts";
|
||||
|
||||
@@ -29,7 +29,7 @@ export function renderCompass(host: EditorHost, north: number, set: (north: numb
|
||||
<button class="nf-btn" ?disabled=${!host.admin} @click=${turn(-90)}>↺ 90°</button>
|
||||
<button class="nf-btn" ?disabled=${!host.admin} @click=${turn(90)}>↻ 90°</button>
|
||||
</div>
|
||||
<span class="nf-sub">${t("compass_hint")}</span>
|
||||
${hint(t("compass_hint"))}
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ export function renderRoomClimate(host: EditorHost, room: Room, patch: (patch: P
|
||||
};
|
||||
return html`<details class="nf-points" ?open=${chosen || !!room.climate_card}>
|
||||
<summary>${host.t("climate")}</summary>
|
||||
<div class="nf-form">${field("temperature", host.t("climate_temperature"))} ${field("humidity", host.t("climate_humidity"))} ${field("co2", host.t("climate_co2"))}</div>
|
||||
<div class="nf-form">${field("temperature", host.t("climate_temperature"))} ${field("humidity", host.t("climate_humidity"))} ${field("co2", host.t("climate_co2"))} ${field("illuminance", host.t("climate_illuminance"))}</div>
|
||||
${checkField(host, host.t("climate_card"), !!room.climate_card, (on) => patch({ climate_card: on || undefined }))}
|
||||
${hint(host.t("climate_card_hint"))}
|
||||
${hint(host.t("climate_hint"))}
|
||||
|
||||
@@ -9,6 +9,8 @@ import { packItemLabel, packLabel } from "../../../furniture-names.ts";
|
||||
import { isClimateFurniture, isElectric, isPackType, packType, type FurniturePack } from "../../../packs.ts";
|
||||
import { checkField, deviceIcon, entityField, glowField, iconField, markerField, pinShiftField, numberField, selectField, textField } from "../fields.ts";
|
||||
import { entityOptions } from "../entities.ts";
|
||||
import { isPositionVariable } from "../../../entities/position-value.ts";
|
||||
import { renderDeviceValues } from "../device-values.ts";
|
||||
import type { EditorHost } from "../host.ts";
|
||||
import { lightEffectFields } from "../light-effect-fields.ts";
|
||||
import { pluginDeviceSettings, pluginText, settingsWithDefaults } from "../../../plugins/registry.ts";
|
||||
@@ -98,6 +100,11 @@ export function renderDeviceForm(host: EditorHost, placed: Placement, actions: D
|
||||
</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}
|
||||
${kind === "cover" ? html`
|
||||
${checkField(host, t("cover_direction_invert"), !!placed.cover_inverted, (on) => set({ cover_inverted: on || undefined }))}
|
||||
${checkField(host, t("cover_tilt_direction_invert"), !!placed.cover_tilt_inverted, (on) => set({ cover_tilt_inverted: on || undefined }))}
|
||||
${entityField(host, t("cover_position_entity"), placed.position ?? null, undefined, entityOptions(host.hass, (id) => isPositionVariable(host.hass, id)), (v) => set({ position: v && v !== "none" ? v : null }))}
|
||||
${placed.position ? checkField(host, t("cover_position_invert"), !!placed.position_inverted, (on) => set({ position_inverted: on || undefined })) : nothing}` : 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}
|
||||
@@ -113,6 +120,7 @@ export function renderDeviceForm(host: EditorHost, placed: Placement, actions: D
|
||||
${placed.name ? checkField(host, t("show_name"), !!placed.show_name, (on) => set({ show_name: on || undefined })) : nothing}
|
||||
${iconField(host, placed.icon, (v) => set({ icon: v }))}
|
||||
${pluginFields(host, placed, set)}
|
||||
${renderDeviceValues(host, placed.values, (values) => set({ values }))}
|
||||
</div>
|
||||
${host.admin
|
||||
? html`<div class="nf-actions">
|
||||
|
||||
@@ -11,6 +11,7 @@ import { checkField, entityField, glowField, hint, iconField, markerField, pinSh
|
||||
import type { EditorHost } from "../host.ts";
|
||||
import { lightEffectFields } from "../light-effect-fields.ts";
|
||||
import { lightEffectSource } from "../../../light-effects.ts";
|
||||
import { renderDeviceValues } from "../device-values.ts";
|
||||
import { calibrationFrom, calibrationFromRooms, gridPlaces, gridRooms, mapCamera, nudgeCalibration, type CalibrationNudge, type Place } from "../../../live/vacuum-map.ts";
|
||||
|
||||
/** What the forms of a piece of furniture make the editor do. */
|
||||
@@ -313,5 +314,6 @@ export function furnitureLinks(host: EditorHost, item: Furniture, actions: Furni
|
||||
? html`${linkBlock(entityField(host, t("furn_door_left"), item.door_left ?? null, undefined, doors, (v) => actions.update({ door_left: v })), entityField(host, t("furn_door_right"), item.door_right ?? null, undefined, doors, (v) => actions.update({ door_right: v })))}
|
||||
${hint(t("fridge_hint"))}`
|
||||
: nothing}
|
||||
${renderDeviceValues(host, item.values, (values) => actions.update({ values }))}
|
||||
${hint(t(hintKey))}`;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { entityName, openingEntities, windowPosition } from "../../../devices.ts
|
||||
import type { I18nKey } from "../../../i18n.ts";
|
||||
import { DOOR_STYLES, OPENING_PRESETS, openingPreset, openingStyle, WINDOW_OPENINGS, WINDOW_STYLES, type Opening, type OpeningPreset, type OpeningStyle } from "../../../model.ts";
|
||||
import { entityOptions, isNumeric } from "../entities.ts";
|
||||
import { isPositionVariable } from "../../../entities/position-value.ts";
|
||||
import { checkField, entityField, hint, numberField, selectField } from "../fields.ts";
|
||||
import type { EditorHost } from "../host.ts";
|
||||
|
||||
@@ -41,7 +42,7 @@ function choices(host: EditorHost) {
|
||||
return {
|
||||
covers: entityOptions(hass, (id) => id.startsWith("cover.")),
|
||||
// numbers that can report where a blind is
|
||||
positions: entityOptions(hass, (id) => /^(sensor|number|input_number)\./.test(id) && Number.isFinite(Number(stateOf(id)?.state))),
|
||||
positions: entityOptions(hass, (id) => isPositionVariable(hass, id)),
|
||||
// plain contacts, and handle sensors with three states (open, tilted, closed)
|
||||
contacts: entityOptions(hass, (id) => isContact(id) || (isNumeric(id) && windowPosition(stateOf(id)) !== null)),
|
||||
plainContacts: entityOptions(hass, isContact),
|
||||
@@ -171,7 +172,9 @@ function blindFields(host: EditorHost, o: Opening, actions: OpeningActions, list
|
||||
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) }))}
|
||||
? html`${checkField(host, t("cover_direction_invert"), !!o.cover_inverted, (on) => actions.update({ cover_inverted: on || undefined }))}
|
||||
${o.cover_tilt || o.blind === "venetian" ? checkField(host, t("cover_tilt_direction_invert"), !!o.cover_tilt_inverted, (on) => actions.update({ cover_tilt_inverted: on || undefined })) : nothing}
|
||||
${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}
|
||||
${checkField(host, t("device_confirm"), !!o.confirm, (on) => actions.update({ confirm: on }), { title: t("cover_confirm_hint") })}
|
||||
${window
|
||||
@@ -180,6 +183,7 @@ function blindFields(host: EditorHost, o: Opening, actions: OpeningActions, list
|
||||
: 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}
|
||||
${o.cover2 && o.cover2 !== "none" ? html`${checkField(host, t("cover2_direction_invert"), !!o.cover2_inverted, (on) => actions.update({ cover2_inverted: on || undefined }))}${checkField(host, t("cover2_tilt_direction_invert"), !!o.cover2_tilt_inverted, (on) => actions.update({ cover2_tilt_inverted: on || undefined }))}` : 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}`;
|
||||
|
||||
@@ -113,7 +113,7 @@ function ceilingField(host: EditorHost, room: Room, floor: Floor, actions: RoomA
|
||||
${room.ceiling != null ? html`<button class="nf-btn nf-field-btn" ?disabled=${!host.admin} @click=${() => actions.patch({ ceiling: null })}>${t("height_auto")}</button>` : nothing}
|
||||
${hint(t("room_ceiling_tip"), "nf-wide")}
|
||||
${room.ceiling != null && room.ceiling > floor.height + 0.005
|
||||
? html`<p class="nf-sub nf-wide">${t("room_ceiling_through", { ceiling: formatNumber(host.hass, room.ceiling, 2), floor: formatNumber(host.hass, floor.height, 2) })}</p>`
|
||||
? hint(t("room_ceiling_through", { ceiling: formatNumber(host.hass, room.ceiling, 2), floor: formatNumber(host.hass, floor.height, 2) }), "nf-wide")
|
||||
: nothing}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { html, nothing, type TemplateResult } from "lit";
|
||||
import { LIGHT_ANIMATIONS, type LightEffectConfig } from "../../light-effects.ts";
|
||||
import { pluginLightAnimationNames } from "../../plugins/registry.ts";
|
||||
import type { EditorHost } from "./host.ts";
|
||||
import { hint } from "./fields.ts";
|
||||
|
||||
/** A small local-only mapping editor. Unknown stored identifiers remain untouched until edited. */
|
||||
export function lightEffectFields(host: EditorHost, config: LightEffectConfig, effects: unknown, update: (patch: LightEffectConfig) => void): TemplateResult {
|
||||
@@ -32,7 +33,7 @@ export function lightEffectFields(host: EditorHost, config: LightEffectConfig, e
|
||||
};
|
||||
return html`<details class="nf-wide">
|
||||
<summary>${host.t("light_effects")}</summary>
|
||||
<p class="nf-sub">${host.t("light_effects_hint")}</p>
|
||||
${hint(host.t("light_effects_hint"))}
|
||||
<label class="nf-check"><input type="checkbox" .checked=${config.animations_enabled !== false} ?disabled=${!host.admin}
|
||||
@change=${(e: Event) => update({ animations_enabled: (e.target as HTMLInputElement).checked })} />${host.t("light_effects_enabled")}</label>
|
||||
${names.map((name) => html`<label class="nf-field nf-wide">${name}
|
||||
@@ -46,6 +47,7 @@ export function lightEffectFields(host: EditorHost, config: LightEffectConfig, e
|
||||
<label class="nf-field nf-wide">${host.t("light_effect_add")}<input type="text" ?disabled=${!host.admin} placeholder="Regenbogen"
|
||||
@input=${(e: Event) => (e.target as HTMLInputElement).setCustomValidity("")}
|
||||
@change=${(e: Event) => { const input = e.target as HTMLInputElement; if (set(input.value, "none", input, true)) input.value = ""; }} /></label>
|
||||
<p class="nf-sub" data-effect-feedback role="status" aria-live="polite">${host.t("light_effect_name_limit")} ${host.t("light_effect_count_limit")}</p>
|
||||
${hint(`${host.t("light_effect_name_limit")} ${host.t("light_effect_count_limit")}`)}
|
||||
<p class="nf-sub" data-effect-feedback role="status" aria-live="polite"></p>
|
||||
</details>`;
|
||||
}
|
||||
@@ -2,6 +2,9 @@ import { css } from "lit";
|
||||
|
||||
/** The editor's own styles: the plan canvas, the side panel with its forms and libraries, the 3D pane and the phone layout. */
|
||||
export const editorStyles = css`
|
||||
.nf-value-links h4 { margin: 12px 0; }
|
||||
.nf-value-add { min-width: 30px; font-size: 18px; padding: 3px 8px; }
|
||||
.nf-value-link { padding: 8px 0; border-bottom: 1px solid var(--nf-line); }
|
||||
:host {
|
||||
display: block;
|
||||
height: 100%;
|
||||
|
||||
@@ -9,6 +9,7 @@ import { openingPreset } from "../../model.ts";
|
||||
import type { EditorHost } from "./host.ts";
|
||||
import { furnitureAt, openingAt, wallElevation, wallFrame, type ElevationBox } from "./ops/wall-view.ts";
|
||||
import { formatLength } from "../../units.ts";
|
||||
import { hint } from "./fields.ts";
|
||||
|
||||
const SNAP = 0.01;
|
||||
const snap = (v: number) => Math.round(v / SNAP) * SNAP;
|
||||
@@ -172,7 +173,7 @@ export class NfWallView extends LitElement {
|
||||
<input type="number" step="0.01" min="0" .value=${sel.y0.toFixed(2)} ?disabled=${!this.host.admin} @change=${(e: Event) => this.place(sel, sel.x0, Number((e.target as HTMLInputElement).value))}
|
||||
/></label>`
|
||||
: nothing}`
|
||||
: html`<span class="muted">${t("wall_view_hint")}</span>`}
|
||||
: hint(t("wall_view_hint"))}
|
||||
</footer>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { css, html, LitElement } from "lit";
|
||||
import { tokens } from "../styles.ts";
|
||||
|
||||
/** Explanations stay reachable by keyboard without taking space in the form. */
|
||||
export class NfHelpPopup extends LitElement {
|
||||
static properties = { text: { attribute: false } };
|
||||
declare text: string;
|
||||
constructor() { super(); this.text = ""; }
|
||||
private get dialog() { return this.renderRoot.querySelector<HTMLDialogElement>("dialog"); }
|
||||
render() {
|
||||
return html`<button class="info" type="button" aria-label="Information anzeigen" aria-haspopup="dialog" title="Information" @click=${() => this.dialog?.showModal()}>ⓘ</button>
|
||||
<dialog aria-label="Information" @keydown=${(event: KeyboardEvent) => event.stopPropagation()} @click=${(event: MouseEvent) => {
|
||||
if (event.target !== event.currentTarget) return;
|
||||
const r = this.dialog!.getBoundingClientRect();
|
||||
if (event.clientX < r.left || event.clientX > r.right || event.clientY < r.top || event.clientY > r.bottom) this.dialog?.close();
|
||||
}}>
|
||||
<header><b>Information</b><button class="close" type="button" aria-label="Schließen" @click=${() => this.dialog?.close()}>×</button></header>
|
||||
<p>${this.text}</p>
|
||||
</dialog>`;
|
||||
}
|
||||
static styles = [tokens, css`
|
||||
:host { display:inline-block; margin:4px 0; vertical-align:middle; }
|
||||
button { font:inherit; cursor:pointer; color:var(--nf-muted); background:transparent; border:1px solid var(--nf-line); border-radius:50%; pointer-events:auto; }
|
||||
.info { width:26px; height:26px; padding:0; font-size:18px; line-height:24px; }
|
||||
button:hover { color:var(--nf-accent); }
|
||||
button:focus-visible { outline:2px solid var(--nf-accent); outline-offset:2px; }
|
||||
dialog { box-sizing:border-box; width:min(560px,calc(100vw - 32px)); max-height:80vh; max-height:80dvh; overflow:auto; padding:18px 22px; border:1px solid var(--nf-line); border-radius:14px; background:var(--nf-chrome-solid); color:var(--nf-text); font:14px/1.5 system-ui,sans-serif; box-shadow:var(--nf-shadow); pointer-events:auto; }
|
||||
dialog::backdrop { background:#050b16a6; }
|
||||
header { display:flex; align-items:center; justify-content:space-between; gap:20px; font-size:16px; }
|
||||
.close { width:30px; height:30px; padding:0; font-size:23px; }
|
||||
p { white-space:pre-wrap; overflow-wrap:anywhere; margin:16px 0 4px; }
|
||||
`];
|
||||
}
|
||||
if (!customElements.get("nf-help-popup")) customElements.define("nf-help-popup", NfHelpPopup);
|
||||
@@ -9,6 +9,7 @@ import type { FurniturePack } from "../packs.ts";
|
||||
import { controls, tokens } from "../styles.ts";
|
||||
import type { HomeAssistant } from "../types.ts";
|
||||
import type { ModelInfo } from "../viewer/viewer3d.ts";
|
||||
import { hint } from "./editor/fields.ts";
|
||||
|
||||
type Present = "unknown" | "yes" | "no";
|
||||
|
||||
@@ -214,7 +215,7 @@ export class NfModelUpload extends LitElement {
|
||||
<button class="nf-btn" @click=${() => this.turn(-1)}>↺ 90°</button>
|
||||
<button class="nf-btn" @click=${() => this.turn(1)}>↻ 90°</button>
|
||||
</div>
|
||||
<small class="nf-sub">${this.t("model_front_hint")}</small>
|
||||
${hint(this.t("model_front_hint"))}
|
||||
</div>
|
||||
<div class="nf-field">
|
||||
<span>${this.t("model_paint")}</span>
|
||||
@@ -242,12 +243,12 @@ export class NfModelUpload extends LitElement {
|
||||
if (slots.length === 0 || !(this.hass?.user?.is_admin ?? false)) return nothing;
|
||||
return html`<section class="nf-ext-card">
|
||||
<h3>${this.t("models")}</h3>
|
||||
<p class="nf-sub">${this.t("models_hint")}</p>
|
||||
${hint(this.t("models_hint"))}
|
||||
${slots.map((slot) => this.row(slot))}
|
||||
${this._draft ? this.editor(this._draft) : nothing}
|
||||
${this._busy && !this._draft ? html`<p class="nf-sub">${this.t("loading")}</p>` : nothing}
|
||||
${this._message ? html`<p class="nf-sub ${this._message.ok ? "nf-notice" : "nf-pack-error"}">${this._message.text}</p>` : nothing}
|
||||
<p class="nf-sub">${this.t("models_licence")}</p>
|
||||
${hint(this.t("models_licence"))}
|
||||
</section>`;
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ export class NfQuickMenu extends LitElement {
|
||||
@click=${() => (moving ? this.call("cover", "stop_cover") : this.ask() && this.call("cover", closed > 50 ? "open_cover" : "close_cover"))}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 4h16M5 4v15M19 4v15M7 8h10M7 12h10M7 16h10" /></svg>
|
||||
<b>${pos !== null ? `${pos} %` : stateText(this.hass, st)}</b>
|
||||
<b>${pos !== null ? `${Math.round(pos)} %` : stateText(this.hass, st)}</b>
|
||||
</button>
|
||||
</div>
|
||||
${setPos
|
||||
@@ -193,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", { entity_id: this.tiltEntity || this.entity, tilt_position: Number((e.target as HTMLInputElement).value) })}
|
||||
@change=${(e: Event) => this.call("cover", "set_cover_tilt_position", { entity_id: st.attributes.nf_cover_control ? this.entity : 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">
|
||||
|
||||
@@ -22,6 +22,8 @@ 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";
|
||||
import { deviceValueReadouts } from "../entities/device-values.ts";
|
||||
import { pointInPolygon } from "../model.ts";
|
||||
|
||||
const COVER_SET_POSITION = 4;
|
||||
const COVER_STOP = 8;
|
||||
@@ -533,6 +535,7 @@ export class NfRoomPanel extends LitElement {
|
||||
${media.length ? this.section("panel_media", media.map((st) => this.mediaRow(st))) : nothing}
|
||||
${switches.length ? this.section("panel_switches", switches.map((st) => this.switchRow(st))) : nothing}
|
||||
${sensors.length ? this.section("panel_sensors", sensors.map((st) => this.sensorRow(st))) : nothing}
|
||||
${this.extraValues(room)}
|
||||
${canAnnounce(this.hass) && roomHasSpeaker(this.hass, this.floor, room) ? this.announceSection(room) : nothing}
|
||||
${this.pluginSections(room, ids)}
|
||||
${hiddenCount
|
||||
@@ -545,6 +548,13 @@ export class NfRoomPanel extends LitElement {
|
||||
}
|
||||
|
||||
/** Header facts: the room's temperature and humidity from its climate sensors (chosen or automatic). */
|
||||
private extraValues(room: Room) {
|
||||
if (!this.floor) return nothing;
|
||||
const groups = [...this.floor.placements.filter((p) => !p.outside && pointInPolygon([p.x, p.z], room.points)).map((p) => ({ name: p.name || entityName(this.hass, p.entity_id), rows: deviceValueReadouts(this.hass, p.values) })),
|
||||
...this.floor.furniture.filter((f) => pointInPolygon([f.x, f.z], room.points)).map((f) => ({ name: f.name || (f.entity && f.entity !== "none" ? entityName(this.hass, f.entity) : this.t("device")), rows: deviceValueReadouts(this.hass, f.values) }))].filter((g) => g.rows.length);
|
||||
return groups.length ? this.section("device_values", groups.map((g) => html`<div class="nf-extra-values"><b>${g.name}</b>${g.rows.map((v) => html`<div class="nf-rp-row"><span class="nf-rp-icon">${v.icon}</span><span class="nf-rp-name">${v.label}</span><b class="nf-rp-state">${v.text}</b></div>`)}</div>`)) : nothing;
|
||||
}
|
||||
|
||||
private facts(climates: HassEntity[]): string[] {
|
||||
const out: string[] = [];
|
||||
const room = this.room;
|
||||
@@ -564,6 +574,8 @@ export class NfRoomPanel extends LitElement {
|
||||
else if (climateTemp && room.climate?.temperature !== "none") out.push(`${formatNumber(this.hass, climateTemp.attributes.current_temperature as number, 1)} ${tempUnit(this.hass)}`);
|
||||
const hum = value("humidity", "%");
|
||||
if (hum) out.push(hum);
|
||||
const lux = roomClimateValue(this.hass, this.floor ?? null, room, "illuminance");
|
||||
if (lux !== null) out.push(`☀ ${formatNumber(this.hass, lux, 0)} lx`);
|
||||
// what the room's devices draw now
|
||||
const power = this.floor && this.building ? roomPower(this.hass, this.building, this.floor, room) : null;
|
||||
if (power !== null) out.push(`⚡ ${powerText(this.hass, power)}`);
|
||||
@@ -755,7 +767,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: tiltEntity ?? id, tilt_position: Number((e.target as HTMLInputElement).value) })}
|
||||
@change=${(e: Event) => this.call("cover", "set_cover_tilt_position", { entity_id: a.nf_cover_control ? id : tiltEntity ?? id, tilt_position: Number((e.target as HTMLInputElement).value) })}
|
||||
/></label>`
|
||||
: features & 48
|
||||
? html`<div class="nf-rp-buttons">
|
||||
|
||||
@@ -50,6 +50,7 @@ import { scaleGlow, buildMarkers, openMoreInfo, stateText, toggleEntity, withPlu
|
||||
import { fanSpin } from "../entities/fans.ts";
|
||||
import { fixtureGlow } from "../entities/kinds.ts";
|
||||
import { coverTiltEntity } from "../entities/covers.ts";
|
||||
import { deviceValuesText } from "../entities/device-values.ts";
|
||||
import { furnitureShown, hiddenFurniture, withoutHidden } from "../entities/visibility.ts";
|
||||
import { pictureUrl } from "../entities/pictures.ts";
|
||||
import { fetchImage } from "../api.ts";
|
||||
@@ -1236,7 +1237,7 @@ export class NfView3d extends LitElement {
|
||||
const deviceTemp = !isCooling(f.type) ? deviceTempOf(hass, f.temp_entity) : null;
|
||||
const deviceTempText = deviceTemp === null ? "" : `🌡 ${formatNumber(hass, fromCelsius(hass, deviceTemp), 1)} ${tempUnit(hass)}`;
|
||||
const extraRef = f.type === "home_battery" ? f.soc : f.type === "wallbox" ? f.status : temps ? (f.temp_entity && f.temp_entity !== "none" ? f.temp_entity : f.temp_entity2) : deviceTemp !== null ? f.temp_entity : null;
|
||||
const extra = extraRef && extraRef !== "none" ? extraRef : null;
|
||||
const extra = extraRef && extraRef !== "none" ? extraRef : (f.values ?? []).find((v) => v.entity && v.entity !== "none")?.entity ?? null;
|
||||
const link = linked ?? (extra ? { entity: null, power: null } : undefined);
|
||||
if (!link) continue;
|
||||
// a battery goes by its charge first: its power sensor is often placed on its own as well
|
||||
@@ -1330,6 +1331,7 @@ export class NfView3d extends LitElement {
|
||||
? formatPower(hass, Math.max(0, power))
|
||||
: "",
|
||||
deviceTempText,
|
||||
deviceValuesText(hass, f.values),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" · "),
|
||||
@@ -1341,7 +1343,7 @@ export class NfView3d extends LitElement {
|
||||
// inverter, battery, wallbox: their own text (watts, charge, status) is always worth a pin
|
||||
energyDevice: f.type === "inverter" || f.type === "home_battery" || f.type === "wallbox" || f.type === "meter",
|
||||
// a fridge's temperatures are worth a pin, like an energy device's values
|
||||
readout: !!temps || undefined,
|
||||
readout: !!temps || !!f.values?.some((v) => v.entity && v.entity !== "none") || undefined,
|
||||
show: f.marker ?? undefined,
|
||||
fromFurniture: true,
|
||||
});
|
||||
@@ -1563,7 +1565,7 @@ export class NfView3d extends LitElement {
|
||||
}
|
||||
|
||||
/** A lamp: its 3D model glows with the linked light and is tapped directly. */
|
||||
private lampMarker(hass: HomeAssistant, floor: Building["floors"][number], f: Furniture, entity: string | null): DeviceMarker & { fromFurniture: boolean } {
|
||||
private lampMarker(hass: HomeAssistant, floor: Building["floors"][number], f: Furniture, entity: string | null): DeviceMarker & { fromFurniture: boolean; readout?: boolean } {
|
||||
const st = entity ? hass.states[entity] : undefined;
|
||||
// further bulbs of the same fixture (a night light, an ambient ring): the lamp glows with them while its main light is off
|
||||
const others = (f.extra_lights ?? []).map((id) => hass.states[id]).filter((s): s is HassEntity => !!s);
|
||||
@@ -1607,7 +1609,7 @@ export class NfView3d extends LitElement {
|
||||
bollard: base + f.h + 0.25,
|
||||
garden: base + f.h + 0.25,
|
||||
}[model];
|
||||
const marker: DeviceMarker & { fromFurniture: boolean } = {
|
||||
const marker: DeviceMarker & { fromFurniture: boolean; readout?: boolean } = {
|
||||
// a lamp without a light keeps a key of its own (it is drawn, but not tappable)
|
||||
id: entity ?? `lamp:${f.id}`,
|
||||
floorId: floor.id,
|
||||
@@ -1617,7 +1619,8 @@ export class NfView3d extends LitElement {
|
||||
y,
|
||||
icon: iconSvg("light"),
|
||||
name: f.name || (entity ? entityName(hass, entity) : furnitureName(hass, f.type)),
|
||||
text: st && (isActive(st) || !otherOn) ? stateText(hass, st) : otherOn ? entityName(hass, otherOn.entity_id) : "",
|
||||
text: [st && (isActive(st) || !otherOn) ? stateText(hass, st) : otherOn ? entityName(hass, otherOn.entity_id) : "", deviceValuesText(hass, f.values)].filter(Boolean).join(" · "),
|
||||
readout: !!f.values?.some((v) => v.entity && v.entity !== "none"),
|
||||
active: (st ? isActive(st) : false) || !!otherOn,
|
||||
unavailable: st ? isUnavailable(st) : false,
|
||||
glow: st || others.length ? scaleGlow(fixtureGlow(st, others, f.color_entity && f.color_entity !== "none" ? hass.states[f.color_entity] : undefined), f.glow_scale) : null,
|
||||
|
||||
@@ -48,6 +48,14 @@ test("a standalone blind's separate slat position is watched", () => {
|
||||
assert.ok(watchedEntities(inputs({ building: b })).includes("cover.slats"));
|
||||
});
|
||||
|
||||
test("all custom device and furniture readings are watched", () => {
|
||||
const b = building();
|
||||
b.floors[0].placements[0].values = [{ id: "a", entity: "sensor.inside" }, { id: "b", entity: "sensor.outside" }];
|
||||
b.floors[0].furniture[0].values = [{ id: "c", entity: "sensor.lux" }];
|
||||
const ids = watchedEntities(inputs({ building: b, needsRoomSensors: false }));
|
||||
for (const id of ["sensor.inside", "sensor.outside", "sensor.lux"]) assert.ok(ids.includes(id));
|
||||
});
|
||||
|
||||
test("room cards watch explicitly chosen values outside the area, including a source that is temporarily missing", () => {
|
||||
const b = building();
|
||||
Object.assign(b.floors[0].rooms[0], { climate_card: true, climate: { humidity: "cover.knx", temperature: "sensor.missing", co2: "sensor.other_room" } });
|
||||
|
||||
@@ -42,7 +42,7 @@ function furnitureIds(inputs: WatchInputs): MaybeId[] {
|
||||
...pieces.flatMap((m) => [m.state_entity, m.state_entity2, m.color_entity, ...(m.gang_entities ?? []), ...(m.extra_lights ?? []), m.cover_entity, m.care_entity, m.room_sensor, m.show_when?.entity, m.picture && /^[a-z_]+\.[a-z0-9_]+$/.test(m.picture) ? m.picture : null]),
|
||||
// a washer's, dryer's or dishwasher's time left comes from a sensor next to its switch
|
||||
...pieces.filter((m) => m.type === "washer" || m.type === "dryer" || m.type === "dishwasher").flatMap((m) => deviceSiblings(hass, furnitureLinks.get(m.id)?.entity ?? furnitureLinks.get(m.id)?.power).filter((id) => id.startsWith("sensor."))),
|
||||
...pieces.flatMap((m) => [m.door_left, m.door_right, m.soc, m.status, m.charge, m.export, m.temp_entity, m.temp_entity2]),
|
||||
...pieces.flatMap((m) => [m.door_left, m.door_right, m.soc, m.status, m.charge, m.export, m.temp_entity, m.temp_entity2, ...(m.values ?? []).map((v) => v.entity)]),
|
||||
...pieces.filter((m) => m.type === "robot_vacuum").map((m) => robotRoomSensor(hass, furnitureLinks.get(m.id)?.entity ?? null, m.room_sensor)),
|
||||
...pieces.flatMap((m) => (m.pictures ?? []).flatMap((rule) => [rule.entity, ...(rule.image.startsWith("camera:") ? [rule.image.slice("camera:".length)] : [])])),
|
||||
];
|
||||
@@ -60,11 +60,11 @@ export function watchedEntities(inputs: WatchInputs): string[] {
|
||||
const energy = b.energy;
|
||||
const lightsOfRooms = roomsOf(b).flatMap((r) => roomEntities(hass, r).filter((id) => kindOf(id) === "light"));
|
||||
const sensorsOfRooms = b.floors.flatMap((f) => f.rooms.flatMap((r) => inputs.needsRoomSensors || r.climate_card
|
||||
? [...roomEntities(hass, r).filter((id) => id.startsWith("sensor.") || id.startsWith("climate.")), ...Object.values(r.climate ?? {}).flat(), ...(["temperature", "humidity", "co2"] as const).flatMap((key) => roomClimateSensors(hass, f, r, key))]
|
||||
? [...roomEntities(hass, r).filter((id) => id.startsWith("sensor.") || id.startsWith("climate.")), ...Object.values(r.climate ?? {}).flat(), ...(["temperature", "humidity", "co2", "illuminance"] as const).flatMap((key) => roomClimateSensors(hass, f, r, key))]
|
||||
: []));
|
||||
const ids: MaybeId[] = [
|
||||
...placed,
|
||||
...b.floors.flatMap((f) => f.placements.map((p) => p.cover_tilt)),
|
||||
...b.floors.flatMap((f) => f.placements.flatMap((p) => [p.cover_tilt, p.position, ...(p.values ?? []).map((v) => v.entity)])),
|
||||
...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