feat: add native Symcon room climate, schedules, weather and presence

This commit is contained in:
jhartworks committed 2026-11-11 09:34:26 +01:00
1 parent 510aece983
commit 18e73194e0
37 files changed
+2861 -2132

No files matched your search

@@ -7,6 +7,8 @@ import { pointInPolygon, type Room } from "../../../model.ts";
import { entityOptions } from "../entities.ts";
import { checkField, deviceIcon, entityField, hint } from "../fields.ts";
import type { EditorHost } from "../host.ts";
import { isSymcon } from "../../../entities/symcon-values.ts";
import { renderSymconRoomHvac } from "../symcon-fields.ts";
import { matchesQuery, placedElsewhere, placedInRoom, rankedBy, takeFirst, withToggled } from "../ops/device-list.ts";
import type { SideState } from "../side-state.ts";
@@ -126,7 +128,7 @@ export function renderDeviceList(host: EditorHost, state: SideState, room: Room,
export function renderRoomClimate(host: EditorHost, room: Room, patch: (patch: Partial<Room>) => void): TemplateResult | typeof nothing {
const { hass } = host;
if (!hass) return nothing;
const chosen = !!room.climate && Object.values(room.climate).some((x) => x != null);
const chosen = !!room.floor_heating || !!room.hvac || (!!room.climate && Object.values(room.climate).some((x) => x != null));
const change = (key: ClimateKey, value: string | string[] | null) => {
const next = { ...(room.climate ?? {}), [key]: value };
patch({ climate: Object.values(next).every((x) => x == null) ? null : next });
@@ -148,7 +150,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"))} ${field("illuminance", host.t("climate_illuminance"))}</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"))}${isSymcon(hass) ? renderSymconRoomHvac(host, room, patch) : nothing}</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"))}
@@ -5,6 +5,8 @@ import { entityName, outsideEntities } from "../../../devices.ts";
import type { I18nKey } from "../../../i18n.ts";
import { BUTTON_ACTIONS, uid, type ButtonAction, type Circuit, type CustomButton, type ForecastCard, type MediaPreset, type OwnAlert, type StartView } from "../../../model.ts";
import { entityOptions, isNumeric } from "../entities.ts";
import { isSymcon } from "../../../entities/symcon-values.ts";
import { renderSymconPresence } from "../symcon-fields.ts";
import { actions, checkField, colorField, entityField, hint, iconField, selectField, textField } from "../fields.ts";
import type { EditorHost } from "../host.ts";
import { likelyRoomSensors, parseButtonData, patchPresence, startViewYaml } from "../ops/house.ts";
@@ -267,6 +269,7 @@ export function renderStartView(host: EditorHost, paneView: () => StartView | nu
/** Which room sensor says where each person is. */
export function renderPresence(host: EditorHost): TemplateResult {
if (isSymcon(host.hass)) return renderSymconPresence(host);
const linked = host.doc.presence.map((l) => l.person);
const persons = [...new Set([...Object.keys(host.hass?.states ?? {}).filter((id) => id.startsWith("person.")).sort(), ...linked])];
const numeric = entityOptions(host.hass, isNumeric);
@@ -296,6 +299,7 @@ export function renderPresence(host: EditorHost): TemplateResult {
/** Locating Bluetooth tags by room: pick a tag, walk through the rooms, record them (the element does the work). */
export function renderBleLocate(host: EditorHost, doc: unknown): TemplateResult {
if (isSymcon(host.hass)) return html``;
return html`<details class="nf-section">
<summary>${host.t("ble")}</summary>
${hint(host.t("ble_hint"))}
+4 -3
View File
@@ -14,6 +14,7 @@ import { formatArea, formatLength } from "../../../units.ts";
import { generateWalls, innerSize, type Wall } from "../../../geometry/walls.ts";
import { countsAsLiving, roomArea } from "../../../geometry/living-area.ts";
import { roomSpeaker } from "../../../live/announce.ts";
import { isSymcon } from "../../../entities/symcon-values.ts";
/** What the room form makes the editor do, and the parts of it that the editor still draws itself. */
export interface RoomActions {
@@ -120,7 +121,7 @@ function ceilingField(host: EditorHost, room: Room, floor: Floor, actions: RoomA
/** Announcements in the room: its speaker (automatic, chosen, or none) and a quiet time. */
function announceFields(host: EditorHost, room: Room, floor: Floor | null, actions: RoomActions): TemplateResult {
const t = host.t;
if (!host.hass) return html``;
if (!host.hass || isSymcon(host.hass)) return html``;
const auto = roomSpeaker(host.hass, floor, { ...room, announce_speaker: null });
const speakers = entityOptions(host.hass, (id) => /^(media_player|assist_satellite)\./.test(id) || (id.startsWith("notify.") && id.endsWith("_announce")));
const quiet = room.announce_quiet ?? null;
@@ -171,8 +172,8 @@ export function renderRoomForm(host: EditorHost, state: SideState, room: Room, a
${hint(t("room_floor_offset_hint"), "nf-wide")}
${entityField(host, t("room_clean"), room.clean_entity ?? null, undefined, entityOptions(host.hass, (id) => /^(script|button|input_button)\./.test(id)), (v) => actions.patch({ clean_entity: v && v !== "none" ? v : null }))}
${room.clean_entity ? nothing : hint(t("room_clean_hint"), "nf-wide")}
${entityField(host, t("floor_heating"), room.floor_heating ?? null, undefined, entityOptions(host.hass, (id) => /^(climate|switch|valve|binary_sensor|input_boolean)\./.test(id)), (v) => actions.patch({ floor_heating: v && v !== "none" ? v : null }))}
${room.floor_heating ? hint(t("floor_heating_hint"), "nf-wide") : nothing}
${isSymcon(host.hass) ? nothing : entityField(host, t("floor_heating"), room.floor_heating ?? null, undefined, entityOptions(host.hass, (id) => /^(climate|switch|valve|binary_sensor|input_boolean)\./.test(id)), (v) => actions.patch({ floor_heating: v && v !== "none" ? v : null }))}
${room.floor_heating && !isSymcon(host.hass) ? hint(t("floor_heating_hint"), "nf-wide") : nothing}
${announceFields(host, room, host.floor ?? null, actions)}
${inner ? html`<p class="nf-sub nf-wide" title=${t("room_inner_hint")}>${t("room_inner", { w: formatLength(host.hass, inner[0]), d: formatLength(host.hass, inner[1]) })}</p>` : nothing}
${livingLine(host, room, walls)}
@@ -1,5 +1,7 @@
import { html, nothing, type TemplateResult } from "lit";
import { weatherEntity } from "../../../weather.ts";
import { isSymcon } from "../../../entities/symcon-values.ts";
import { renderSymconWeather } from "../symcon-fields.ts";
import type { I18nKey } from "../../../i18n.ts";
import { DEFAULT_PAINT_INSIDE, DEFAULT_PAINT_OUTSIDE, DEFAULT_WEATHER_EFFECTS, WEATHER_EFFECTS, type Building, type RoofType } from "../../../model.ts";
import { entityName } from "../../../devices.ts";
@@ -91,14 +93,14 @@ export function renderSettings(host: EditorHost, actions: SettingsActions): Temp
: nothing}
${gable ? numberField(host, t("roof_pitch"), s.roof.pitch, (v) => setRoof({ pitch: clamp(v, 5, 60) }), 1, 5) : nothing}
${s.roof.type !== "none" ? numberField(host, t("roof_overhang"), s.roof.overhang, (v) => setRoof({ overhang: clamp(v, 0, 2) }), 0.05, 0) : nothing}
${host.hass ? entityField(host, t("weather_entity"), s.weather_entity ?? null, weatherEntity(host.hass, null), entityOptions(host.hass, (id) => id.startsWith("weather.")), (v) => set({ weather_entity: v })) : nothing}
${isSymcon(host.hass) ? renderSymconWeather(host, s, set) : host.hass ? entityField(host, t("weather_entity"), s.weather_entity ?? null, weatherEntity(host.hass, null), entityOptions(host.hass, (id) => id.startsWith("weather.")), (v) => set({ weather_entity: v })) : nothing}
<div class="nf-sub nf-wide">${t("weather_effects")}</div>
${WEATHER_EFFECTS.map((effect) => checkField(host, t(`weather_effect_${effect}` as I18nKey), current.includes(effect), (on) => set({ weather_effects: withEffect(current, effect, on) }), { wide: false }))}
${checkField(host, t("rain_warning"), s.rain_warning !== false, (on) => set({ rain_warning: on }))}
${host.hass && s.rain_warning !== false
${host.hass && !isSymcon(host.hass) && s.rain_warning !== false
? entityField(host, t("rain_sensor"), s.rain_sensor ?? null, undefined, entityOptions(host.hass, (id) => /^(binary_sensor|sensor)\./.test(id)), (v) => set({ rain_sensor: v === "none" ? null : v }))
: nothing}
${host.hass && s.rain_warning !== false && s.rain_sensor && s.rain_sensor !== "none" ? checkField(host, t("rain_sensor_inverted"), !!s.rain_sensor_inverted, (on) => set({ rain_sensor_inverted: on || undefined }), { title: t("rain_sensor_inverted_hint") }) : nothing}
${host.hass && !isSymcon(host.hass) && s.rain_warning !== false && s.rain_sensor && s.rain_sensor !== "none" ? checkField(host, t("rain_sensor_inverted"), !!s.rain_sensor_inverted, (on) => set({ rain_sensor_inverted: on || undefined }), { title: t("rain_sensor_inverted_hint") }) : nothing}
${host.hass ? entityField(host, t("outage_sensor"), s.outage_sensor ?? null, undefined, entityOptions(host.hass, (id) => /^(binary_sensor|sensor)\./.test(id)), (v) => set({ outage_sensor: v === "none" ? null : v })) : nothing}
${hint(t("outage_hint"), "nf-wide")}
${checkField(host, t("contact_warning"), !!s.contact_warning, (on) => set({ contact_warning: on || undefined }), { title: t("contact_warning_hint") })}
@@ -106,7 +108,7 @@ export function renderSettings(host: EditorHost, actions: SettingsActions): Temp
${selectField(host, t("room_double_tap"), s.room_double_tap ?? "area", [["area", t("room_double_tap_area")], ["plan", t("room_double_tap_plan")], ["off", t("room_double_tap_off")]] as const, (v) => set({ room_double_tap: v === "plan" || v === "off" ? v : null }), { title: t("room_double_tap_hint") })}
${checkField(host, t("motion_markers_active"), !!s.motion_markers_active, (on) => set({ motion_markers_active: on || undefined }), { title: t("motion_markers_active_hint") })}
${host.hass ? statusFields(host, s.status_entities ?? [], (status_entities) => set({ status_entities: status_entities.length ? status_entities : null })) : nothing}
${host.hass ? entityField(host, t("announce_tts"), s.announce_tts ?? null, undefined, entityOptions(host.hass, (id) => id.startsWith("tts.")), (v) => set({ announce_tts: v === "none" ? null : v })) : nothing}
${isSymcon(host.hass) ? nothing : html`${host.hass ? entityField(host, t("announce_tts"), s.announce_tts ?? null, undefined, entityOptions(host.hass, (id) => id.startsWith("tts.")), (v) => set({ announce_tts: v === "none" ? null : v })) : nothing}
<label class="nf-field nf-wide"
>${t("announce_phrases")}
<textarea
@@ -120,11 +122,11 @@ export function renderSettings(host: EditorHost, actions: SettingsActions): Temp
}}
></textarea>
</label>
${hint(t("announce_phrases_hint"), "nf-wide")}
${hint(t("announce_phrases_hint"), "nf-wide")}`}
${checkField(host, t("sun_patches"), s.sun_patches !== false, (on) => set({ sun_patches: on }), { title: t("sun_patches_hint") })}
${checkField(host, t("sun_arc"), s.sun_arc === true, (on) => set({ sun_arc: on }), { title: t("sun_arc_hint") })}
${backdropFields(host, s.backdrop ?? null, (backdrop) => set({ backdrop }))}
</div>
${hint(`${t("north_hint")} ${t("weather_entity_hint")}`)}
${hint(isSymcon(host.hass) ? t("north_hint") : `${t("north_hint")} ${t("weather_entity_hint")}`)}
</details>`;
}