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
@@ -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>`;
|
||||
|
||||
Reference in new issue
Block a user