feat: add native charging station telemetry and aliased lock status
This commit is contained in:
1 parent
df4a6f36a3
commit
59292517b7
24 files changed
+1756
-1304
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { box, entity, floorWith, hassOf } from "./entities/fixtures.ts";
|
||||
import { emptyBuilding, normalizeBuilding, type Furniture } from "./model.ts";
|
||||
import { chargingDurationText, chargingReadouts, chargingRefs, chargingTimeText, isChargingStation } from "./charging-station.ts";
|
||||
import { furniturePowerCards } from "./live/furniture-power-card.ts";
|
||||
import { watchedEntities } from "./components/view3d/watch-list.ts";
|
||||
|
||||
const point = (id: string, value: number | string, extra: Record<string, unknown> = {}) => entity(id, "open", { symcon_id: 123, symcon_variable_type: typeof value === "number" ? 1 : 3, symcon_value: value, ...extra });
|
||||
const item = (extra: Partial<Furniture> = {}): Furniture => ({ id: "charger", type: "wallbox", name: "Meine Wallbox", x: 2, z: 2, w: .3, d: .3, h: .4, rotation: 0, variant: null, power_card: true, power: "none", ...extra });
|
||||
|
||||
test("built-in and both pack wallboxes offer charging data without classifying linked variable names", () => {
|
||||
for (const type of ["wallbox", "pack:nextfloor.a_smart:wallbox", "pack:nextfloor.energie:wallbox", "pack:test:ev_bike_charger", "pack:test:ev_charger", "pack:test:charging_station"]) assert.equal(isChargingStation(type), true);
|
||||
for (const type of ["desk", "pack:test:wallbox_holder", "pack:wallbox:desk"]) assert.equal(isChargingStation(type), false);
|
||||
});
|
||||
|
||||
test("zero SoC, zero duration and arbitrary native Integer aliases remain authoritative", () => {
|
||||
const h = hassOf([point("cover.1", 0, { symcon_formatted: "0" }), point("climate.2", 0), point("light.3", 0, { symcon_formatted: "Stecker frei" }), point("cover.4", 12.35, { symcon_formatted: "12,35 kWh", unit_of_measurement: "kWh" })], {}, { language: "de", symconObjects: [] });
|
||||
const f = item({ charging: { soc: "cover.1", duration: "climate.2", energy: "cover.4", lock: "light.3" } });
|
||||
assert.deepEqual(chargingReadouts(h, f).map((r) => [r.id, r.text]), [["soc", "0 %"], ["duration", "0:00:00"], ["energy", "12,35 kWh"], ["lock", "Stecker frei"]]);
|
||||
h.states["light.3"] = point("light.3", 7, { symcon_formatted: "Wartung: verriegelt" });
|
||||
assert.equal(chargingReadouts(h, f).at(-1)?.text, "Wartung: verriegelt");
|
||||
h.states["light.3"].state = "unavailable";
|
||||
assert.equal(chargingReadouts(h, f).at(-1)?.text, "–");
|
||||
assert.deepEqual(chargingReadouts(h, item({ charging: { soc: null, energy: "none" } })), []);
|
||||
});
|
||||
|
||||
test("native timestamp profiles, strings, seconds and milliseconds display dates without changing source values", () => {
|
||||
const h = hassOf([], {}, { language: "de" }), ts = Date.UTC(2026, 10, 12, 13, 45, 0) / 1000;
|
||||
const st = point("cover.start", ts);
|
||||
const expected = new Date(ts * 1000).toLocaleString("de", { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
||||
assert.equal(chargingTimeText(h, st), expected);
|
||||
assert.equal(chargingTimeText(h, point("cover.ms", ts * 1000)), expected);
|
||||
assert.equal(chargingTimeText(h, point("cover.iso", new Date(ts * 1000).toISOString())), expected);
|
||||
assert.equal(chargingTimeText(h, point("cover.date", ts, { symcon_formatted: "12.11.2026" })), "12.11.2026");
|
||||
assert.equal(chargingTimeText(h, point("cover.time", 45000, { symcon_formatted: "12:30" })), "12:30");
|
||||
assert.equal(chargingTimeText(h, point("cover.raw", ts, { symcon_formatted: "Eigene Anzeige" }), "value"), "Eigene Anzeige");
|
||||
assert.equal(chargingTimeText(h, point("cover.raw", ts, { symcon_formatted: "Eigene Anzeige" }), "seconds"), expected);
|
||||
assert.equal(chargingTimeText(h, point("cover.ms", ts * 1000), "milliseconds"), expected);
|
||||
assert.equal(chargingTimeText(h, point("cover.invalid", "noch nicht gestartet")), "noch nicht gestartet");
|
||||
assert.equal(st.attributes.symcon_value, ts);
|
||||
});
|
||||
|
||||
test("duration conversion respects units, explicit overrides and native formatted duration profiles", () => {
|
||||
const h = hassOf([], {}, { language: "de" });
|
||||
assert.equal(chargingDurationText(h, point("cover.s", 90061)), "25:01:01");
|
||||
assert.equal(chargingDurationText(h, point("cover.min", 61, { unit_of_measurement: "min", symcon_formatted: "61 min" })), "1:01:00");
|
||||
assert.equal(chargingDurationText(h, point("cover.h", 1.5, { unit_of_measurement: "h" })), "1:30:00");
|
||||
assert.equal(chargingDurationText(h, point("cover.h", 1.5), "hours"), "1:30:00");
|
||||
assert.equal(chargingDurationText(h, point("cover.min", 2), "minutes"), "0:02:00");
|
||||
assert.equal(chargingDurationText(h, point("cover.s", -3)), "−0:00:03");
|
||||
assert.equal(chargingDurationText(h, point("cover.native", 3661, { symcon_formatted: "1 Std 1 Min" })), "1 Std 1 Min");
|
||||
assert.equal(chargingDurationText(h, point("cover.text", "02:15:00")), "02:15:00");
|
||||
assert.equal(chargingDurationText(h, point("cover.raw", 61, { symcon_formatted: "61 min" }), "value"), "61 min");
|
||||
assert.equal(chargingDurationText(h, undefined), "–");
|
||||
});
|
||||
|
||||
test("a charging-data-only floating card needs no power or switch and remains scoped and opt-in", () => {
|
||||
const f = item({ charging: { soc: "sensor.1", lock: "sensor.2" } }), h = hassOf([point("sensor.1", 55), point("sensor.2", 0, { symcon_formatted: "Entriegelt" })]);
|
||||
const b = { ...emptyBuilding(), floors: [floorWith([box("r", 0, 0, 5, 5)], { furniture: [f] })] };
|
||||
const [card] = furniturePowerCards(h, b, new Map([[f.id, { entity: null, power: "sensor.ignored" }]]), null, null);
|
||||
assert.equal(card.powerEntity, null); assert.equal(card.power, null);
|
||||
assert.deepEqual(card.readings?.map((r) => r.text), ["55 %", "Entriegelt"]);
|
||||
assert.deepEqual(furniturePowerCards(h, b, new Map(), "other", null), []);
|
||||
f.power_card = false; assert.deepEqual(furniturePowerCards(h, b, new Map(), null, null), []);
|
||||
});
|
||||
|
||||
test("all six links survive JSON normalization and trigger live updates even without room climate sensors", () => {
|
||||
const f = item({ charging: { soc: "cover.1", start: "light.2", end: "climate.3", duration: "switch.4", energy: "sensor.5", lock: "cover.6", start_format: "milliseconds", end_format: "value", duration_unit: "minutes" } });
|
||||
const b = normalizeBuilding(JSON.parse(JSON.stringify({ ...emptyBuilding(), floors: [floorWith([], { furniture: [f] })] })));
|
||||
assert.deepEqual(b.floors[0].furniture[0].charging, f.charging);
|
||||
const h = hassOf([], {}, { symconObjects: [] });
|
||||
const watched = watchedEntities({ hass: h, building: b, furnitureLinks: new Map(), openingLinks: new Map(), needsRoomSensors: false, alertSources: null, weatherEntityId: null });
|
||||
assert.ok(chargingRefs(f).every((id) => watched.includes(id)));
|
||||
assert.equal(chargingReadouts(h, f).length, 6, "temporarily missing linked values retain their row as a dash");
|
||||
assert.ok(chargingReadouts(h, f).every((r) => r.text === "–"));
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
import type { EntityRef, Furniture } from "./model.ts";
|
||||
import type { HassEntity, HomeAssistant } from "./types.ts";
|
||||
import { nativeNumber, nativeText, nativeValue } from "./entities/symcon-values.ts";
|
||||
import { formatNumber, translate, type I18nKey } from "./i18n.ts";
|
||||
|
||||
export type ChargingTimeFormat = "auto" | "value" | "seconds" | "milliseconds";
|
||||
export type ChargingDurationUnit = "auto" | "value" | "seconds" | "minutes" | "hours";
|
||||
export interface ChargingStationConfig {
|
||||
soc?: EntityRef; start?: EntityRef; end?: EntityRef; duration?: EntityRef; energy?: EntityRef; lock?: EntityRef;
|
||||
start_format?: ChargingTimeFormat; end_format?: ChargingTimeFormat; duration_unit?: ChargingDurationUnit;
|
||||
}
|
||||
export interface ChargingReadout { id: string; entity: string; icon: string; label: string; text: string }
|
||||
|
||||
/** Furniture type identifiers only; linked variables are never classified by their names. */
|
||||
export const isChargingStation = (type: string): boolean => type === "wallbox" || /^pack:[^:]+:(wallbox|ev_charger|ev_bike_charger|charging_station)$/.test(type);
|
||||
const fields = [
|
||||
["soc", "🔋", "furn_soc"], ["start", "▶", "charging_start"], ["end", "■", "charging_end"],
|
||||
["duration", "⏱", "charging_duration"], ["energy", "⚡", "charging_energy"], ["lock", "🔐", "charging_lock"],
|
||||
] as const satisfies readonly (readonly [keyof ChargingStationConfig, string, I18nKey])[];
|
||||
const real = (id: EntityRef | undefined): id is string => !!id && id !== "none";
|
||||
const numericText = (text: string): boolean => /^[+-]?\d+(?:[.,\s]\d{3})*(?:[.,]\d+)?$/.test(text.trim());
|
||||
const sourceOf = (hass: HomeAssistant, id: string) => String(hass.states[id]?.attributes.symcon_source_entity || id);
|
||||
export function chargingRefs(item: Pick<Furniture, "type" | "charging">): string[] {
|
||||
return isChargingStation(item.type) ? [...new Set(fields.map(([key]) => item.charging?.[key]).filter(real))] : [];
|
||||
}
|
||||
|
||||
/** Preserve Symcon's formatted profile values, particularly arbitrary Integer associations. */
|
||||
function valueText(hass: HomeAssistant, st: HassEntity | undefined, fallbackUnit = ""): string {
|
||||
if (nativeValue(st) === null) return "–";
|
||||
const formatted = st?.attributes.symcon_formatted;
|
||||
if (typeof formatted === "string" && formatted.trim()) {
|
||||
return fallbackUnit && /^[-+]?\d+(?:[.,]\d+)?$/.test(formatted.trim()) ? `${formatted} ${fallbackUnit}` : formatted;
|
||||
}
|
||||
const n = nativeNumber(st);
|
||||
return n === null ? nativeText(st) : `${formatNumber(hass, n, Number.isInteger(n) ? 0 : 2)}${st?.attributes.unit_of_measurement || fallbackUnit ? ` ${st?.attributes.unit_of_measurement || fallbackUnit}` : ""}`;
|
||||
}
|
||||
|
||||
export function chargingTimeText(hass: HomeAssistant, st: HassEntity | undefined, format: ChargingTimeFormat = "auto"): string {
|
||||
if (nativeValue(st) === null) return "–";
|
||||
if (format === "value") return valueText(hass, st);
|
||||
const n = nativeNumber(st), raw = nativeValue(st);
|
||||
let ms: number | null = null;
|
||||
if (format !== "auto") ms = n === null ? null : n * (format === "seconds" ? 1000 : 1);
|
||||
else {
|
||||
const formatted = st?.attributes.symcon_formatted;
|
||||
// Native date/time profiles already know their preferred display, including time-only values.
|
||||
if (typeof formatted === "string" && formatted.trim() && !numericText(formatted)) return formatted;
|
||||
if (n !== null && n >= 1e8) ms = n < 1e11 ? n * 1000 : n;
|
||||
else if (typeof raw === "string" && /^\d{4}-\d\d-\d\d[T ]\d\d:\d\d/.test(raw)) ms = Date.parse(raw);
|
||||
}
|
||||
if (ms === null || !Number.isFinite(ms) || !Number.isFinite(new Date(ms).getTime())) return valueText(hass, st);
|
||||
return new Date(ms).toLocaleString(hass.language || "de", { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
||||
}
|
||||
|
||||
export function chargingDurationText(hass: HomeAssistant, st: HassEntity | undefined, unit: ChargingDurationUnit = "auto"): string {
|
||||
if (nativeValue(st) === null) return "–";
|
||||
if (unit === "value") return valueText(hass, st);
|
||||
const n = nativeNumber(st);
|
||||
if (n === null) return valueText(hass, st);
|
||||
if (unit === "auto") {
|
||||
const formatted = st?.attributes.symcon_formatted;
|
||||
const suffix = String(st?.attributes.unit_of_measurement ?? "").trim();
|
||||
// Retain native duration profiles/aliases, unless this is just a number with its unit.
|
||||
if (typeof formatted === "string" && formatted.trim() && !numericText(formatted) && !(suffix && formatted.trim().endsWith(suffix) && numericText(formatted.trim().slice(0, -suffix.length).trim()))) return formatted;
|
||||
unit = /^(min|minute[n]?|minutes)$/i.test(suffix) ? "minutes" : /^(h|std\.?|stunde[n]?|hours?)$/i.test(suffix) ? "hours" : "seconds";
|
||||
}
|
||||
const seconds = Math.round(Math.abs(n) * (unit === "hours" ? 3600 : unit === "minutes" ? 60 : 1));
|
||||
if (!Number.isSafeInteger(seconds)) return valueText(hass, st);
|
||||
return `${n < 0 ? "−" : ""}${Math.floor(seconds / 3600)}:${String(Math.floor(seconds / 60) % 60).padStart(2, "0")}:${String(seconds % 60).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
export function chargingReadouts(hass: HomeAssistant, item: Pick<Furniture, "type" | "charging">): ChargingReadout[] {
|
||||
if (!isChargingStation(item.type)) return [];
|
||||
const config = item.charging;
|
||||
return fields.flatMap(([key, icon, label]) => {
|
||||
const ref = config?.[key];
|
||||
if (!real(ref)) return [];
|
||||
const entity = sourceOf(hass, ref), st = hass.states[entity];
|
||||
const text = key === "start" || key === "end" ? chargingTimeText(hass, st, config?.[`${key}_format`])
|
||||
: key === "duration" ? chargingDurationText(hass, st, config?.duration_unit) : valueText(hass, st, key === "soc" ? "%" : "");
|
||||
return [{ id: key, entity, icon, label: translate(hass, label), text }];
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { html, nothing, type TemplateResult } from "lit";
|
||||
import { isChargingStation, type ChargingStationConfig, type ChargingDurationUnit, type ChargingTimeFormat } from "../../../charging-station.ts";
|
||||
import type { Furniture } from "../../../model.ts";
|
||||
import { entityOptions } from "../entities.ts";
|
||||
import { entityField, hint, selectField } from "../fields.ts";
|
||||
import type { EditorHost } from "../host.ts";
|
||||
|
||||
export function chargingStationFields(host: EditorHost, item: Furniture, update: (patch: Partial<Furniture>) => void): TemplateResult | typeof nothing {
|
||||
if (!isChargingStation(item.type)) return nothing;
|
||||
const t = host.t, c = item.charging ?? {}, options = entityOptions(host.hass, () => true);
|
||||
const set = (patch: Partial<ChargingStationConfig>) => {
|
||||
const charging = { ...c, ...patch };
|
||||
update({ charging: Object.values(charging).some((v) => v != null) ? charging : null });
|
||||
};
|
||||
const timeFormats: [ChargingTimeFormat, string][] = [["auto", t("charging_auto")], ["value", t("charging_value")], ["seconds", t("charging_unix_seconds")], ["milliseconds", t("charging_unix_ms")]];
|
||||
const units: [ChargingDurationUnit, string][] = [["auto", t("charging_auto")], ["value", t("charging_value")], ["seconds", t("charging_seconds")], ["minutes", t("charging_minutes")], ["hours", t("charging_hours")]];
|
||||
const field = (key: "soc" | "start" | "end" | "duration" | "energy" | "lock", label: string, types: number[]) => entityField(host, label, c[key] ?? null, undefined, options, (v) => set({ [key]: v === "none" ? null : v }), { types });
|
||||
return html`<div class="nf-form nf-links nf-charging-links">
|
||||
<b class="nf-wide">${t("charging_data")}</b>
|
||||
${hint(t("charging_hint"), "nf-wide")}
|
||||
${field("soc", t("furn_soc"), [1, 2])}
|
||||
${field("start", t("charging_start"), [1, 2, 3])}
|
||||
${c.start && c.start !== "none" ? selectField(host, `${t("charging_start")} · ${t("charging_time_format")}`, c.start_format ?? "auto", timeFormats, (start_format) => set({ start_format }), { wide: true }) : nothing}
|
||||
${field("end", t("charging_end"), [1, 2, 3])}
|
||||
${c.end && c.end !== "none" ? selectField(host, `${t("charging_end")} · ${t("charging_time_format")}`, c.end_format ?? "auto", timeFormats, (end_format) => set({ end_format }), { wide: true }) : nothing}
|
||||
${field("duration", t("charging_duration"), [1, 2, 3])}
|
||||
${c.duration && c.duration !== "none" ? selectField(host, t("charging_duration_unit"), c.duration_unit ?? "auto", units, (duration_unit) => set({ duration_unit }), { wide: true }) : nothing}
|
||||
${field("energy", t("charging_energy"), [1, 2])}
|
||||
${field("lock", t("charging_lock"), [1])}
|
||||
</div>`;
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import { lightEffectFields } from "../light-effect-fields.ts";
|
||||
import { lightEffectSource } from "../../../light-effects.ts";
|
||||
import { renderDeviceValues } from "../device-values.ts";
|
||||
import { isSymcon, isSymconVariable } from "../../../entities/symcon-values.ts";
|
||||
import { isChargingStation } from "../../../charging-station.ts";
|
||||
import { chargingStationFields } from "./charging-station.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. */
|
||||
@@ -291,7 +293,7 @@ export function furnitureLinks(host: EditorHost, item: Furniture, actions: Furni
|
||||
hasScreen(item.type) ? glowField(host, item.ambilight, (v) => actions.update({ ambilight: v }), { label: "ambilight", hint: "ambilight_hint", lowest: 0 }) : nothing,
|
||||
(isMediaFurniture(item.type) || isSpeakerFurniture(item.type)) ? glowField(host, item.sound_rings, (v) => actions.update({ sound_rings: v }), { label: "sound_rings", hint: "sound_rings_hint", lowest: 0 }) : nothing,
|
||||
item.type === "grid_point" ? nothing : html`${entityField(host, t(meterParent(host.doc, item) ? "meter_sub_power" : powerLabel(item.type)), item.power ?? null, autoPower, power, (v) => actions.update({ power: v }), { types: [1, 2] })}
|
||||
${checkField(host, t("furniture_power_card"), !!item.power_card, (on) => actions.update({ power_card: on || undefined }))}${hint(t("furniture_power_card_hint"), "nf-wide")}`,
|
||||
${checkField(host, t(isChargingStation(item.type) ? "charging_card" : "furniture_power_card"), !!item.power_card, (on) => actions.update({ power_card: on || undefined }))}${hint(t(isChargingStation(item.type) ? "charging_hint" : "furniture_power_card_hint"), "nf-wide")}`,
|
||||
)}
|
||||
${isCooling(item.type) ? coolingLinks(host, item, actions) : lamp || item.type === "grid_point" ? nothing : deviceTempLink(host, item, actions)}
|
||||
${item.type === "meter" ? subMeterLinks(host, item, actions) : nothing}
|
||||
@@ -305,7 +307,8 @@ export function furnitureLinks(host: EditorHost, item: Furniture, actions: Furni
|
||||
hint(t("furn_charge_hint"), "nf-wide"),
|
||||
)
|
||||
: nothing}
|
||||
${item.type === "wallbox" ? linkBlock(entityField(host, t("furn_wallbox_status"), item.status ?? null, undefined, kindOptions((id) => isBinary(id) || isNumeric(id)), set("status"))) : nothing}
|
||||
${isChargingStation(item.type) ? linkBlock(entityField(host, t("furn_wallbox_status"), item.status ?? null, undefined, kindOptions((id) => isBinary(id) || isNumeric(id)), set("status"), { types: [0, 1, 2, 3] })) : nothing}
|
||||
${chargingStationFields(host, item, actions.update)}
|
||||
${!lamp || hasLink || powerRef
|
||||
? html`${checkField(host, t("device_confirm"), !!item.confirm, (on) => actions.update({ confirm: on }), { title: t("device_confirm_hint") })}
|
||||
<div class="nf-form">${markerField(host, item.marker ?? null, (v) => actions.update({ marker: v }))}${iconField(host, item.icon, (v) => actions.update({ icon: v }))}${lamp ? nothing : pinShiftField(host, item.pin_offset, (v) => actions.update({ pin_offset: v }))}</div>`
|
||||
|
||||
@@ -29,6 +29,8 @@ 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";
|
||||
import { chargingReadouts } from "../charging-station.ts";
|
||||
import { furnitureName } from "../furniture-names.ts";
|
||||
|
||||
const COVER_SET_POSITION = 4;
|
||||
const COVER_STOP = 8;
|
||||
@@ -561,7 +563,7 @@ export class NfRoomPanel extends LitElement {
|
||||
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);
|
||||
...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) : furnitureName(this.hass, f.type)), rows: [...chargingReadouts(this.hass, f), ...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}${trendButton(this.hass, [v.entity], v.label)}</b></div>`)}</div>`)) : nothing;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import type { HomeAssistant } from "../../types.ts";
|
||||
import { weatherEntity } from "../../weather.ts";
|
||||
import { utilityWatched } from "../../utilities.ts";
|
||||
import { hydronicRefs } from "../../hydronic-model.ts";
|
||||
import { chargingRefs } from "../../charging-station.ts";
|
||||
|
||||
export interface WatchInputs {
|
||||
hass: HomeAssistant;
|
||||
@@ -46,6 +47,7 @@ function furnitureIds(inputs: WatchInputs): MaybeId[] {
|
||||
...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, ...(m.values ?? []).map((v) => v.entity)]),
|
||||
...pieces.flatMap(hydronicRefs),
|
||||
...pieces.flatMap(chargingRefs),
|
||||
...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)] : [])])),
|
||||
];
|
||||
|
||||
@@ -1710,6 +1710,23 @@ const DE = {
|
||||
furn_charge: "Ladeleistung (W, separater Sensor, optional)",
|
||||
furn_charge_hint: "Meldet dein Speicher Laden und Entladen in zwei Sensoren (z. B. Anker Solix), nimm oben den Entlade-Sensor als Leistung und hier den Lade-Sensor. Ein Sensor mit Vorzeichen braucht das nicht.",
|
||||
furn_wallbox_status: "Status (lädt, angesteckt)",
|
||||
charging_data: "Ladedaten",
|
||||
charging_card: "Ladestation als 3D-Kachel",
|
||||
charging_hint: "Verknüpfte Ladedaten erscheinen in der 3D-Kachel und im Raummenü, auch ohne Leistungswert. Nicht verknüpfte Zeilen bleiben ausgeblendet. Zeitprofile und Integer-Aliase werden aus Symcon übernommen. Ohne Zeitprofil erkennt Automatisch Unix-Zeitstempel; numerische Ladezeiten ohne Einheit gelten als Sekunden. Die Formatwahl kann dies ändern. Die Werte dienen ausschließlich der Anzeige.",
|
||||
charging_start: "Startzeit",
|
||||
charging_end: "Endzeit",
|
||||
charging_duration: "Ladezeit",
|
||||
charging_energy: "Geladene Energie",
|
||||
charging_lock: "Verriegelungsstatus",
|
||||
charging_time_format: "Zeitformat",
|
||||
charging_duration_unit: "Ladezeit-Einheit",
|
||||
charging_auto: "Automatisch",
|
||||
charging_value: "Symcon-Wert unverändert",
|
||||
charging_seconds: "Sekunden",
|
||||
charging_minutes: "Minuten",
|
||||
charging_hours: "Stunden",
|
||||
charging_unix_seconds: "Unix-Zeit (Sekunden)",
|
||||
charging_unix_ms: "Unix-Zeit (Millisekunden)",
|
||||
energy_only_note: "⚡ Energie: Hier lassen sich nur Solarfelder und Energiegeräte verschieben, Räume und Möbel sind gesperrt.",
|
||||
roof_only_note: "🏠 Dach: Hier lassen sich nur Dachflächen und Dachfenster verschieben, Räume und Möbel sind gesperrt.",
|
||||
energy_devices_hint: "Stromzähler, Wechselrichter, Stromspeicher, Wallbox und Netzanschluss werden hier angelegt: auf der oben gewählten Etage, im Grundriss verschiebbar. Mit Leistungssensor zeigen sie ihre Watt; der Zähler bekommt den Netzsensor, beim Strang wählst du den Wechselrichter. Mehrere Wechselrichter und Speicher (etwa eine Balkonanlage dazu) gehen auch: Jeder bekommt seinen eigenen Sensor.",
|
||||
@@ -3754,6 +3771,23 @@ const EN: Record<Key, string> = {
|
||||
furn_charge: "Charging power (W, separate sensor, optional)",
|
||||
furn_charge_hint: "If your battery reports charging and discharging in two sensors (e.g. Anker Solix), take the discharging sensor as power above and the charging sensor here. A signed sensor does not need this.",
|
||||
furn_wallbox_status: "Status (charging, plugged in)",
|
||||
charging_data: "Charging data",
|
||||
charging_card: "Charging station as a floating 3D card",
|
||||
charging_hint: "Linked charging data appears on the floating card and in the room menu, even without a power reading. Unlinked rows stay hidden. Native date/time profiles and Integer associations retain their Symcon display. Auto detects Unix timestamps without a time profile; numeric durations without a unit use seconds. Change the format to override this. These readings are display-only.",
|
||||
charging_start: "Start time",
|
||||
charging_end: "End time",
|
||||
charging_duration: "Charging duration",
|
||||
charging_energy: "Charged energy",
|
||||
charging_lock: "Lock status",
|
||||
charging_time_format: "Time format",
|
||||
charging_duration_unit: "Duration unit",
|
||||
charging_auto: "Automatic",
|
||||
charging_value: "Unchanged Symcon value",
|
||||
charging_seconds: "Seconds",
|
||||
charging_minutes: "Minutes",
|
||||
charging_hours: "Hours",
|
||||
charging_unix_seconds: "Unix time (seconds)",
|
||||
charging_unix_ms: "Unix time (milliseconds)",
|
||||
energy_only_note: "⚡ Energy: only solar fields and energy devices can be moved here; rooms and furniture are locked.",
|
||||
roof_only_note: "🏠 Roof: only roof sections and roof windows can be moved here; rooms and furniture are locked.",
|
||||
energy_devices_hint: "Meter, inverters, home batteries, wallboxes and the grid connection are added here: on the floor chosen above, movable in the plan. With a power sensor they show their watts; the meter takes the grid sensor, a string picks its inverter. Several inverters and batteries (say a balcony plant on top) work too: each gets its own sensor.",
|
||||
|
||||
@@ -261,8 +261,8 @@ export function unstackLhCards(root: ParentNode): void {
|
||||
.sort((a, b) => b.y - a.y);
|
||||
for (const it of items) {
|
||||
let bottom = it.y;
|
||||
// Hydraulic cards contain several readings: use nearby free columns before stacking them out of view.
|
||||
if (it.el.classList.contains("live-card-hydronic") && width > it.w + 16 && height > it.h + 16) {
|
||||
// Multi-reading equipment cards use nearby free columns before stacking out of view.
|
||||
if ((it.el.classList.contains("live-card-hydronic") || it.el.classList.contains("live-card-charging")) && width > it.w + 16 && height > it.h + 16) {
|
||||
const xs = [it.x, it.w / 2 + 8, width - it.w / 2 - 8, ...placed.flatMap((p) => [p.x0 - it.w / 2 - 8, p.x1 + it.w / 2 + 8])]
|
||||
.filter((x) => x >= it.w / 2 + 8 && x <= width - it.w / 2 - 8).sort((a, b) => Math.abs(a - it.x) - Math.abs(b - it.x));
|
||||
const ys = [Math.max(it.h + 8, Math.min(height - 8, bottom)), ...placed.flatMap((p) => [p.y0 - 8, p.y1 + it.h + 8])].filter((y) => y >= it.h + 8 && y <= height - 8);
|
||||
@@ -345,8 +345,9 @@ function roomClimateCard(hass: HomeAssistant | undefined, c: RoomClimateCard, i:
|
||||
|
||||
function furniturePowerCard(hass: HomeAssistant | undefined, c: FurniturePowerCard, i: number): TemplateResult {
|
||||
const power = c.power === null ? "–" : `${c.power < 0 ? "−" : ""}${watts(hass, c.power)}`;
|
||||
return html`<div class="live-card live-card-power" data-i=${i} data-furniture=${c.id} role="group" aria-label=${c.name}>
|
||||
<div class="live-power-name">${c.name}</div><div class="live-row"><span aria-hidden="true">⚡</span><b>${power}</b>${trendButton(hass, [c.powerEntity], c.name)}</div>
|
||||
return html`<div class="live-card live-card-power ${(c.readings ?? []).length ? "live-card-charging" : ""}" data-i=${i} data-furniture=${c.id} role="group" aria-label=${c.name}>
|
||||
<div class="live-power-name">${c.name}</div>${c.powerEntity ? html`<div class="live-row"><span aria-hidden="true">⚡</span><b>${power}</b>${trendButton(hass, [c.powerEntity], c.name)}</div>` : nothing}
|
||||
${(c.readings ?? []).map((r) => html`<div class="live-row live-charging-row" data-reading=${r.id}><span class="live-charging-label" title=${r.label}><span aria-hidden="true">${r.icon}</span> ${r.label}</span><b title=${r.text}>${r.text}</b>${trendButton(hass, [r.entity], r.label)}</div>`)}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
@@ -363,6 +364,11 @@ export const liveCardStyles = css`
|
||||
.live-card-power .live-row { align-items:center; gap:6px; }
|
||||
.live-card-power .live-row b { margin-left:auto; color:color-mix(in srgb,#ffca8a 80%,var(--nf-text)); font-variant-numeric:tabular-nums; }
|
||||
.live-card-power nf-trend-button { margin-left:0; }
|
||||
.live-card-power.live-card-charging { max-width:min(320px,calc(100vw - 24px)); }
|
||||
.live-card-power .live-charging-row { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1.4fr) 18px; align-items:center; column-gap:6px; min-height:18px; }
|
||||
.live-charging-label { color:var(--nf-muted); font-size:10px; overflow:hidden; text-overflow:ellipsis; }
|
||||
.live-charging-row b { font-size:11px; overflow:hidden; text-overflow:ellipsis; }
|
||||
.live-charging-row nf-trend-button { grid-column:3; }
|
||||
.live-cards {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
|
||||
@@ -6,13 +6,15 @@ import type { FurnitureLinks } from "../entities/furniture-links.ts";
|
||||
import type { HomeAssistant } from "../types.ts";
|
||||
import { readPower } from "../energy.ts";
|
||||
import type { PlanPoint } from "../viewer/live-energy.ts";
|
||||
import { chargingReadouts, type ChargingReadout } from "../charging-station.ts";
|
||||
|
||||
export interface FurniturePowerCard {
|
||||
kind: "power";
|
||||
id: string;
|
||||
name: string;
|
||||
powerEntity: string;
|
||||
powerEntity: string | null;
|
||||
power: number | null;
|
||||
readings?: ChargingReadout[];
|
||||
at: PlanPoint;
|
||||
}
|
||||
|
||||
@@ -24,14 +26,16 @@ export function furniturePowerCards(hass: HomeAssistant, building: Building, lin
|
||||
const room = roomId ? floor.rooms.find((r) => r.id === roomId) : null;
|
||||
if (roomId && !room) continue;
|
||||
for (const item of floor.furniture) {
|
||||
if (!item.power_card || item.power === "none" || !furnitureShown(hass, item)) continue;
|
||||
if (!item.power_card || !furnitureShown(hass, item)) continue;
|
||||
if (room && !pointInPolygon([item.x, item.z], room.points)) continue;
|
||||
const source = item.power || links.get(item.id)?.power;
|
||||
if (!source || source === "none") continue;
|
||||
const powerEntity = String(hass.states[source]?.attributes.symcon_source_entity || source);
|
||||
const candidate = item.power === "none" ? null : item.power || links.get(item.id)?.power;
|
||||
const source = candidate && candidate !== "none" ? candidate : null;
|
||||
const readings = chargingReadouts(hass, item);
|
||||
if (!source && !readings.length) continue;
|
||||
const powerEntity = source ? String(hass.states[source]?.attributes.symcon_source_entity || source) : null;
|
||||
const offset = item.pin_offset;
|
||||
cards.push({ kind: "power", id: item.id, name: item.name || furnitureName(hass, item.type), powerEntity,
|
||||
power: readPower(hass.states[powerEntity]), at: { floorId: floor.id, x: item.x + (offset?.x ?? 0), z: item.z + (offset?.z ?? 0), y: mountBase(floor, item) + item.h + .35 + (offset?.y ?? 0) } });
|
||||
power: powerEntity ? readPower(hass.states[powerEntity]) : null, readings, at: { floorId: floor.id, x: item.x + (offset?.x ?? 0), z: item.z + (offset?.z ?? 0), y: mountBase(floor, item) + item.h + .35 + (offset?.y ?? 0) } });
|
||||
}
|
||||
}
|
||||
return cards;
|
||||
|
||||
@@ -269,6 +269,8 @@ export interface Furniture extends LightEffectConfig {
|
||||
power?: EntityRef;
|
||||
/** Show this furniture's linked power reading as its own floating 3D card. */
|
||||
power_card?: boolean;
|
||||
/** Charging station telemetry; read-only links retain native values and Integer aliases. */
|
||||
charging?: import("./charging-station.ts").ChargingStationConfig | null;
|
||||
/** Fridges and freezers: a temperature sensor of the fridge (temp_entity) and one of the freezer compartment; the marker shows them and warns when too warm. Any other device: its own thermometer, shown on its pin (#112). */
|
||||
temp_entity?: string | null;
|
||||
temp_entity2?: string | null;
|
||||
|
||||
Reference in new issue
Block a user