feat: add scoped user accounts, password login and garden paving materials

This commit is contained in:
jhartworks committed 2026-11-16 16:30:47 +01:00
1 parent c56f1a5ba9
commit 1d67e8ceba
43 files changed
+2024 -625

No files matched your search

+9
View File
@@ -981,6 +981,15 @@ export const editorStyles = css`
fill: rgba(184, 163, 130, 0.24);
stroke: rgba(184, 163, 130, 0.65);
}
.nf-out-pavers polygon,
.nf-out-natural_stone polygon {
fill: rgba(170, 160, 135, 0.22);
stroke: rgba(170, 160, 135, 0.6);
}
.nf-out-stepping_stones polygon {
fill: rgba(130, 170, 110, 0.18);
stroke: rgba(160, 190, 140, 0.55);
}
.nf-free-wall {
cursor: grab;
}
+3 -1
View File
@@ -2,6 +2,7 @@
// up/stop/down for blinds, on/off for switches, with a slider and a way to the full details.
import { css, html, LitElement, nothing } from "lit";
import { canControl } from "../access.ts";
import { assumedCover, type CarState, entityName, isUnavailable, kindOf } from "../devices.ts";
import { translate, type I18nKey } from "../i18n.ts";
import { openMoreInfo, stateText } from "../markers.ts";
@@ -73,6 +74,7 @@ export class NfQuickMenu extends LitElement {
}
private call(domain: string, service: string, data: Record<string, unknown> = {}): void {
if (!canControl(this.hass, this.entity)) return;
void this.hass.callService(domain, service, { entity_id: this.entity, ...data });
}
@@ -262,7 +264,7 @@ export class NfQuickMenu extends LitElement {
if (!st) return nothing;
const kind = kindOf(this.entity);
// a cover without feedback (a garage remote) stays unknown, but its buttons still work
const body = isUnavailable(st) && !assumedCover(st)
const body = !canControl(this.hass, this.entity) || (isUnavailable(st) && !assumedCover(st))
? html`<p class="qm-note">${stateText(this.hass, st)}</p>`
: kind === "light"
? this.renderLight(st)
+3 -1
View File
@@ -5,6 +5,7 @@ import { ROOM_HVAC_FIELDS } from "../entities/room-hvac.ts";
import { nativeBool, nativeNumber, nativeText, nativeValue } from "../entities/symcon-values.ts";
import { controls, tokens } from "../styles.ts";
import { trendButton } from "./trend-button.ts";
import { canControl } from "../access.ts";
interface SchedulePoint { hour: number; minute: number; second: number; action: number }
interface ScheduleGroup { id: number; days: number; points: SchedulePoint[] }
@@ -20,6 +21,7 @@ export class NfRoomHvac extends LitElement {
constructor() { super(); this._pending = new Set(); this._error = ""; }
private async send(id: string, domain: string, service: string, data: Record<string, unknown>) {
if (!canControl(this.hass, id)) return;
this._pending = new Set([...this._pending, id]);
this._error = "";
try { await this.hass.callService(domain, service, { entity_id: id, ...data }); }
@@ -47,7 +49,7 @@ export class NfRoomHvac extends LitElement {
const days = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"];
const time = (p: SchedulePoint) => `${String(p.hour).padStart(2, "0")}:${String(p.minute).padStart(2, "0")}${p.second ? `:${String(p.second).padStart(2, "0")}` : ""}`;
return html`<details class="schedule"><summary>${String(st.attributes.friendly_name ?? "Schaltuhr")}</summary>
<label class="nf-check"><input type="checkbox" .checked=${st.state === "on"} ?disabled=${this._pending.has(id)} @change=${(e: Event) => void this.send(id, "schedule", "set_active", { active: (e.target as HTMLInputElement).checked })} /> Aktiv</label>
<label class="nf-check"><input type="checkbox" .checked=${st.state === "on"} ?disabled=${this._pending.has(id) || !canControl(this.hass, id)} @change=${(e: Event) => void this.send(id, "schedule", "set_active", { active: (e.target as HTMLInputElement).checked })} /> Aktiv</label>
${next > 0 ? html`<p class="next">Nächster Schaltpunkt: ${new Date(next * 1000).toLocaleString(this.hass.language)}${nextAction ? ` · ${nextAction.name}` : ""}</p>` : nothing}
${groups.length ? groups.map((group) => html`<div class="schedule-group"><b>${days.filter((_, i) => group.days & (1 << i)).join(" · ")}</b><div class="points">
${[...group.points].sort((a, b) => a.hour * 3600 + a.minute * 60 + a.second - (b.hour * 3600 + b.minute * 60 + b.second)).map((point) => {
+27 -21
View File
@@ -2,6 +2,7 @@
// scenes and scripts). Shown next to the 3D view when a room is selected.
import { css, html, LitElement, nothing, svg, type TemplateResult } from "lit";
import { canControl } from "../access.ts";
import { assumedCover, entityName, groupByDevice, groupCovers, isActive, isUnavailable, kindOf, roomClimateSensors, roomClimateValue, roomPanelEntities, fromCelsius, tempUnit, type DeviceKind, roomEntities } from "../devices.ts";
import { formatNumber, translate, type I18nKey } from "../i18n.ts";
import { iconPath } from "../icons.ts";
@@ -239,7 +240,7 @@ export class NfRoomPanel extends LitElement {
if (!quietSince || minutes < EMPTY_MINUTES) return nothing;
return html`<div class="nf-rp-shade">
<span>💡 ${this.t("empty_lights_hint", { n: lightsOn.length, min: minutes })}</span>
<button class="nf-btn nf-rp-small" @click=${() => this.call("light", "turn_off", { entity_id: lightsOn.map((l) => l.entity_id) })}>${this.t("empty_lights_off")}</button>
<button class="nf-btn nf-rp-small" ?disabled=${!lightsOn.some((l) => canControl(this.hass, l.entity_id))} @click=${() => this.call("light", "turn_off", { entity_id: lightsOn.filter((l) => canControl(this.hass, l.entity_id)).map((l) => l.entity_id) })}>${this.t("empty_lights_off")}</button>
</div>`;
}
@@ -254,6 +255,7 @@ export class NfRoomPanel extends LitElement {
if (!open.length) return nothing;
const down = () => {
for (const c of heating) {
if (!canControl(this.hass, c.entity_id)) continue;
const modes = (c.attributes.hvac_modes as string[] | undefined) ?? [];
if (modes.includes("off")) this.call("climate", "set_hvac_mode", { entity_id: c.entity_id, hvac_mode: "off" });
else if (typeof c.attributes.min_temp === "number") this.call("climate", "set_temperature", { entity_id: c.entity_id, temperature: c.attributes.min_temp });
@@ -261,7 +263,7 @@ export class NfRoomPanel extends LitElement {
};
return html`<div class="nf-rp-shade nf-rp-open-heat">
<span>🪟 ${this.t("open_heating_hint", { n: open.length })}</span>
<button class="nf-btn nf-rp-small" @click=${down}>${this.t("open_heating_off")}</button>
<button class="nf-btn nf-rp-small" ?disabled=${!heating.some((c) => canControl(this.hass, c.entity_id))} @click=${down}>${this.t("open_heating_off")}</button>
</div>`;
}
@@ -281,7 +283,7 @@ export class NfRoomPanel extends LitElement {
const pos = st.attributes.current_position;
return typeof pos === "number" ? pos > 30 : st.state === "open";
};
const covers = [...new Set(sunnyWindowsNow(this.building, this.floor, room, { latitude, longitude }).flatMap((o) => [o.cover, o.cover2].filter(open)))];
const covers = [...new Set(sunnyWindowsNow(this.building, this.floor, room, { latitude, longitude }).flatMap((o) => [o.cover, o.cover2].filter(open)))].filter((id) => canControl(this.hass, id));
if (!covers.length) return nothing;
return html`<div class="nf-rp-shade">
<span>☀ ${this.t("shade_hint", { n: covers.length, temp: `${formatNumber(this.hass, fromCelsius(this.hass, temp), 1)} ${tempUnit(this.hass)}` })}</span>
@@ -366,6 +368,8 @@ export class NfRoomPanel extends LitElement {
}
private call(domain: string, service: string, data: Record<string, unknown>): void {
const ids = Array.isArray(data.entity_id) ? data.entity_id : [data.entity_id];
if (ids.some((id) => typeof id !== "string" || !canControl(this.hass, id))) return;
void this.hass.callService(domain, service, data);
}
@@ -373,7 +377,7 @@ export class NfRoomPanel extends LitElement {
private renderClean(room: Room) {
const id = room.clean_entity;
const st = id ? this.hass.states[id] : undefined;
if (!id || !st) return nothing;
if (!id || !st || !canControl(this.hass, id)) return nothing;
const domain = id.slice(0, id.indexOf("."));
const run = () => (domain === "script" ? this.call("script", "turn_on", { entity_id: id }) : this.call(domain, "press", { entity_id: id }));
return html`<div class="nf-rp-alloff"><button class="nf-btn nf-rp-small" ?disabled=${isUnavailable(st)} title=${this.t("room_clean_run_hint")} @click=${run}>🧹 ${this.t("room_clean_run")}</button></div>`;
@@ -381,7 +385,7 @@ export class NfRoomPanel extends LitElement {
/** Switches off what is on in the room and offers to undo it for ten seconds. */
private allOff(states: HassEntity[]): void {
const plan = allOffPlan(states);
const plan = allOffPlan(states.filter((st) => canControl(this.hass, st.entity_id)));
for (const c of plan.off) this.call(c.domain, c.service, c.data);
this._undo = plan.undo;
clearTimeout(this.undoTimer);
@@ -397,7 +401,7 @@ export class NfRoomPanel extends LitElement {
/** "Everything off" while something is on, and its undo right after. */
private renderAllOff(states: HassEntity[]): TemplateResult | typeof nothing {
if (this._undo) return html`<div class="nf-rp-alloff"><span>${this.t("all_off_done")}</span><button class="nf-btn nf-rp-small" @click=${() => this.undoAllOff()}>↶ ${this.t("all_off_undo")}</button></div>`;
const { count } = allOffPlan(states);
const { count } = allOffPlan(states.filter((st) => canControl(this.hass, st.entity_id)));
if (count < 2) return nothing;
return html`<div class="nf-rp-alloff"><button class="nf-btn nf-rp-small" title=${this.t("all_off_hint")} @click=${() => this.allOff(states)}>⏻ ${this.t("all_off_n", { n: count })}</button></div>`;
}
@@ -435,7 +439,7 @@ export class NfRoomPanel extends LitElement {
role="switch"
aria-checked=${on ? "true" : "false"}
aria-label=${this.name(st.entity_id)}
?disabled=${isUnavailable(st)}
?disabled=${isUnavailable(st) || !canControl(this.hass, st.entity_id)}
@click=${guarded}
></button>`;
}
@@ -470,7 +474,7 @@ export class NfRoomPanel extends LitElement {
const switches = by(["switch", "fan", "lock"]);
const sensors = by(["sensor", "binary"]);
const scenes = by(["scene", "script"]);
const facts = this.facts(climates);
const facts = room.symcon_read_room === false ? [] : this.facts(climates);
const lightsOn = lights.filter((l) => l.state === "on");
return html`<section class="nf-rp" aria-label=${room.name}>
<header class="nf-rp-head">
@@ -491,7 +495,9 @@ export class NfRoomPanel extends LitElement {
<nf-utility-report .hass=${this.hass} .readings=${roomUtilityReadings(this.hass, room, this.building?.floors.flatMap((f) => f.rooms))}></nf-utility-report>
${this.renderAllOff([...lights, ...media, ...switches])}
${this.renderClean(room)}
${!room.area_id && !outside && !(isSymcon(this.hass) && hvacRefs.length)
${room.symcon_read_room === false
? html`<p class="nf-rp-note">${this.t(ids.length ? "access_room_devices" : "access_room_geometry")}</p>`
: !room.area_id && !outside && !(isSymcon(this.hass) && hvacRefs.length)
? html`<p class="nf-rp-note">${this.t("panel_no_area")}</p>`
: !ids.length && !(isSymcon(this.hass) && hvacRefs.length)
? html`<p class="nf-rp-note">${this.t("panel_empty")}</p>`
@@ -517,13 +523,13 @@ export class NfRoomPanel extends LitElement {
${lights.length
? this.section(
"panel_lights",
[...lights.map((st) => this.lightRow(st)), ...(room ? [this.renderMoods(room, lights)] : [])],
html`${lightsOn.length < lights.length
? html`<button class="nf-btn nf-rp-small" @click=${() => this.call("light", "turn_on", { entity_id: lights.filter((l) => !isUnavailable(l)).map((l) => l.entity_id) })}>
[...lights.map((st) => canControl(this.hass, st.entity_id) ? this.lightRow(st) : this.sensorRow(st)), ...(room && lights.some((st) => canControl(this.hass, st.entity_id)) ? [this.renderMoods(room, lights)] : [])],
html`${lights.some((l) => l.state !== "on" && canControl(this.hass, l.entity_id))
? html`<button class="nf-btn nf-rp-small" ?disabled=${!lights.some((l) => canControl(this.hass, l.entity_id))} @click=${() => this.call("light", "turn_on", { entity_id: lights.filter((l) => !isUnavailable(l) && canControl(this.hass, l.entity_id)).map((l) => l.entity_id) })}>
${this.t("panel_all_on")}
</button>`
: nothing}${lightsOn.length
? html`<button class="nf-btn nf-rp-small" @click=${() => this.call("light", "turn_off", { entity_id: lightsOn.map((l) => l.entity_id) })}>
: nothing}${lightsOn.some((l) => canControl(this.hass, l.entity_id))
? html`<button class="nf-btn nf-rp-small" ?disabled=${!lightsOn.some((l) => canControl(this.hass, l.entity_id))} @click=${() => this.call("light", "turn_off", { entity_id: lightsOn.filter((l) => canControl(this.hass, l.entity_id)).map((l) => l.entity_id) })}>
${this.t("panel_all_off")}
</button>`
: nothing}`,
@@ -532,20 +538,20 @@ export class NfRoomPanel extends LitElement {
${covers.length
? this.section(
"panel_covers",
covers.map((st) => this.coverRow(st)),
covers.length > 1 && groupCovers(covers, this.confirmEntities).length
? html`<button class="nf-btn nf-rp-small" @click=${() => this.call("cover", "open_cover", { entity_id: groupCovers(covers, this.confirmEntities) })}>
covers.map((st) => canControl(this.hass, st.entity_id) ? this.coverRow(st) : this.sensorRow(st)),
covers.length > 1 && groupCovers(covers.filter((c) => canControl(this.hass, c.entity_id)), this.confirmEntities).length
? html`<button class="nf-btn nf-rp-small" @click=${() => this.call("cover", "open_cover", { entity_id: groupCovers(covers.filter((c) => canControl(this.hass, c.entity_id)), this.confirmEntities) })}>
${this.t("panel_all_open")}</button
><button class="nf-btn nf-rp-small" @click=${() => this.call("cover", "close_cover", { entity_id: groupCovers(covers, this.confirmEntities) })}>
><button class="nf-btn nf-rp-small" @click=${() => this.call("cover", "close_cover", { entity_id: groupCovers(covers.filter((c) => canControl(this.hass, c.entity_id)), this.confirmEntities) })}>
${this.t("panel_all_close")}
</button>`
: nothing,
)
: nothing}
${isSymcon(this.hass) ? html`<nf-room-hvac .hass=${this.hass} .room=${room}></nf-room-hvac>` : nothing}
${climates.length ? this.section("panel_climate", climates.map((st) => this.climateRow(st))) : nothing}
${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}
${climates.length ? this.section("panel_climate", climates.map((st) => canControl(this.hass, st.entity_id) ? this.climateRow(st) : this.sensorRow(st))) : nothing}
${media.length ? this.section("panel_media", media.map((st) => canControl(this.hass, st.entity_id) ? this.mediaRow(st) : this.sensorRow(st))) : nothing}
${switches.length ? this.section("panel_switches", switches.map((st) => canControl(this.hass, st.entity_id) ? this.switchRow(st) : this.sensorRow(st))) : nothing}
${sensors.length ? this.section("panel_sensors", sensors.map((st) => this.sensorRow(st))) : nothing}
${this.extraValues(room)}
${!isSymcon(this.hass) && canAnnounce(this.hass) && roomHasSpeaker(this.hass, this.floor, room) ? this.announceSection(room) : nothing}
+13 -6
View File
@@ -1,6 +1,7 @@
// Lit wrapper around the lazily loaded 3D viewer.
import { changeMoments, hassAt, loadHistory, replayable, type History } from "../live/time-travel.ts";
import { canControl } from "../access.ts";
import { sunPosition, todayAt } from "../sun-position.ts";
import { dayCurves, statesRead, type DayCurves } from "../live/day-curves.ts";
import { backdropStyle } from "../backdrop.ts";
@@ -1070,7 +1071,7 @@ export class NfView3d extends LitElement {
private jumpTo(a: Alert): void {
// an own warning: its details, or what was chosen for it (switch the entity, go to its room)
if (a.kind === "own" && a.tap !== "room") {
if (a.tap === "toggle") void this.hass.callService("homeassistant", "toggle", { entity_id: a.entity });
if (a.tap === "toggle" && canControl(this.hass, a.entity)) void this.hass.callService("homeassistant", "toggle", { entity_id: a.entity });
else openMoreInfo(this, a.entity);
return;
}
@@ -1091,7 +1092,7 @@ export class NfView3d extends LitElement {
const room = floor?.rooms.find((r) => r.id === roomId);
if (!b || !hass || !floor || !room) return;
const mode = roomToggleMode(b.settings.room_double_tap, this.roomDoubleTap);
const lights = roomToggleLights(hass, floor, room, this.furnitureLinks, this.confirmSet, mode);
const lights = roomToggleLights(hass, floor, room, this.furnitureLinks, this.confirmSet, mode).filter((id) => canControl(hass, id));
if (!lights.length) return;
const anyOn = lights.some((id) => hass.states[id]?.state === "on");
void hass.callService("homeassistant", anyOn ? "turn_off" : "turn_on", { entity_id: lights });
@@ -1104,6 +1105,7 @@ export class NfView3d extends LitElement {
}
private runScene(id: string): void {
if (!canControl(this.hass, id)) return;
void this.hass.callService(id.split(".")[0], "turn_on", { entity_id: id });
this._sceneFired = id;
setTimeout(() => (this._sceneFired = null), 600);
@@ -1802,7 +1804,7 @@ export class NfView3d extends LitElement {
const st = this.hass?.states[entityId];
if (phase === "start") {
// devices that ask before switching are not moved by a swipe (it turns the view instead)
if (!st || isUnavailable(st) || this.confirmSet.has(entityId)) return false;
if (!st || isUnavailable(st) || !canControl(this.hass, entityId) || this.confirmSet.has(entityId)) return false;
const kind = kindOf(entityId);
if (kind === "light" && lightAbilities(st).dim) {
const pct = st.state === "on" ? (typeof st.attributes.brightness === "number" ? Math.round((st.attributes.brightness as number) / 2.55) : 100) : 0;
@@ -1843,6 +1845,7 @@ export class NfView3d extends LitElement {
}
private applySwipe(): void {
if (this._swipe && !canControl(this.hass, this._swipe.entity)) return;
const s = this._swipe;
if (!s || !this.hass) return;
if (s.kind === "light") {
@@ -2002,8 +2005,8 @@ export class NfView3d extends LitElement {
if (!this._central) return star;
const floor = this.floorId ? b.floors.find((f) => f.id === this.floorId) : undefined;
const floors = floor ? [floor] : b.floors;
const lights = floors.flatMap((f) => floorControls(hass, f).lights);
const covers = floors.flatMap((f) => floorControls(hass, f).covers);
const lights = floors.flatMap((f) => floorControls(hass, f).lights).filter((id) => canControl(hass, id));
const covers = floors.flatMap((f) => floorControls(hass, f).covers).filter((id) => canControl(hass, id));
const lightsOn = lights.filter((id) => hass.states[id]?.state === "on").length;
const house = !floor;
// house-wide: the first tap arms the button ("sure?"), the second runs it
@@ -2050,7 +2053,7 @@ export class NfView3d extends LitElement {
return html`<button
class="nf-chip"
aria-pressed=${on || this._sceneFired === id}
?disabled=${isUnavailable(st)}
?disabled=${isUnavailable(st) || !canControl(hass, id)}
@click=${() => {
void hass.callService(domain, service, { entity_id: id });
this._sceneFired = id;
@@ -2357,6 +2360,10 @@ export class NfView3d extends LitElement {
return;
}
const kind = kindOf(entityId);
if (this.hass.symconObjects !== undefined && !canControl(this.hass, entityId)) {
if (this.hass.states[entityId]) this._menu = { entity: entityId, x, y };
return;
}
// blinds have no single on/off: a tap opens their quick menu (up, positions, stop, down); speakers and TVs open theirs
// (play, skip, volume, sources and the stations set for them)
if (kind === "cover" || kind === "media") {