feat: add floating room climate cards and fix Symcon humidity selection
This commit is contained in:
1 parent
24188f96f7
commit
ff54f4461a
21 files changed
+764
-398
No files matched your search
@@ -21,6 +21,20 @@ test("a KNX numeric temperature remains selectable and readable even with an inf
|
||||
assert.equal(roomClimateValue(hass, null, { ...room, climate: { temperature: "sensor.fahrenheit" } }, "temperature"), 20);
|
||||
});
|
||||
|
||||
test("manual Symcon climate assignment accepts unclassified numeric values without relaxing automatic detection", () => {
|
||||
const h = hassOf([
|
||||
entity("cover.knx", "open", { symcon_id: 12, symcon_variable_type: 2, symcon_numeric_value: 48.5 }),
|
||||
entity("sensor.percent", "50", { unit_of_measurement: "%" }),
|
||||
entity("sensor.soil", "50", { device_class: "moisture", unit_of_measurement: "%" }),
|
||||
entity("sensor.text", "50", { symcon_id: 13, symcon_variable_type: 3, unit_of_measurement: "%" }),
|
||||
]);
|
||||
assert.equal(isClimateValueSensor(h, "cover.knx", "humidity", true), true);
|
||||
assert.equal(isClimateValueSensor(h, "cover.knx", "humidity"), false);
|
||||
assert.equal(isClimateValueSensor(h, "sensor.percent", "humidity"), true);
|
||||
assert.equal(isClimateValueSensor(h, "sensor.soil", "humidity"), false);
|
||||
assert.equal(isClimateValueSensor(h, "sensor.text", "humidity", true), false);
|
||||
});
|
||||
|
||||
const lounge = hassOf(
|
||||
[
|
||||
entity("light.ceiling", "on"),
|
||||
|
||||
@@ -210,13 +210,18 @@ export const CLIMATE_CLASSES = { temperature: "temperature", humidity: "humidity
|
||||
export type ClimateKey = keyof typeof CLIMATE_CLASSES;
|
||||
|
||||
/** Numeric room values, including Symcon readings whose legacy domain was inferred from a parent name. */
|
||||
export function isClimateValueSensor(hass: HomeAssistant, id: string, key: ClimateKey): boolean {
|
||||
export function isClimateValueSensor(hass: HomeAssistant, id: string, key: ClimateKey, manual = false): boolean {
|
||||
const a = hass.states[id]?.attributes;
|
||||
if (!a) return false;
|
||||
const symconNumber = (a.symcon_variable_type === 1 || a.symcon_variable_type === 2) && typeof a.symcon_id === "number";
|
||||
if (typeof a.symcon_id === "number" && !symconNumber) return false;
|
||||
if (!symconNumber && !/^(sensor|input_number|number)\./.test(id)) return false;
|
||||
// An explicit assignment gives an otherwise unclassified Symcon number its meaning.
|
||||
if (manual && symconNumber) return true;
|
||||
const unit = String(a.unit_of_measurement ?? "").replace(/\s/g, "").toLowerCase();
|
||||
if (key === "temperature" && ["°c", "°f", "℃", "℉", "k"].includes(unit)) return true;
|
||||
if (key === "humidity" && !a.device_class && ["%", "%rh", "%r.h.", "%rf", "%r.f."].includes(unit)) return true;
|
||||
if (key === "co2" && unit === "ppm" && /co[₂2]/i.test(String(a.friendly_name ?? ""))) return true;
|
||||
return a.device_class === CLIMATE_CLASSES[key];
|
||||
}
|
||||
|
||||
@@ -264,11 +269,13 @@ export function roomClimateValue(hass: HomeAssistant, floor: Floor | null, room:
|
||||
const readings = roomClimateSensors(hass, floor, room, key)
|
||||
.map((id) => {
|
||||
const state = hass.states[id];
|
||||
if (!state || isUnavailable(state) || (!state.state.trim() && state.attributes.symcon_numeric_value === undefined)) return NaN;
|
||||
const reading = Number(state?.attributes.symcon_numeric_value ?? state?.state);
|
||||
return key === "temperature" ? toCelsius(reading, hass.states[id]?.attributes.unit_of_measurement) : reading;
|
||||
})
|
||||
.filter(Number.isFinite);
|
||||
if (readings.length) return readings.reduce((sum, v) => sum + v, 0) / readings.length;
|
||||
if (room.climate?.[key]) return null;
|
||||
// no room sensor: a thermostat of the room's area tells its temperature and humidity (heating curves, the heat map)
|
||||
if (key === "co2" || room.climate?.[key] === "none") return null;
|
||||
const attr = key === "temperature" ? "current_temperature" : "current_humidity";
|
||||
|
||||
Reference in new issue
Block a user