Files
NextFloor/frontend/src/entities/device-values.test.ts
T

28 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from "node:assert/strict";
import { test } from "node:test";
import { entity, hassOf } from "./fixtures.ts";
import { deviceValueReadouts, deviceValuesText } from "./device-values.ts";
test("several temperatures and other device values keep independent symbols, labels and native readings", () => {
const h = hassOf([
entity("cover.temp", "open", { symcon_numeric_value: 22.7, unit_of_measurement: "°C", device_class: "temperature" }),
entity("sensor.out", "48.5", { unit_of_measurement: "°C", friendly_name: "Ausgang", device_class: "temperature" }),
entity("sensor.humidity", "55", { unit_of_measurement: "%", device_class: "humidity" }),
entity("sensor.status", "normal", {}),
]);
const links = [{ id: "a", entity: "cover.temp", icon: "❄", label: "Innen" }, { id: "b", entity: "sensor.out", icon: "🔥" }, { id: "c", entity: "sensor.humidity" }, { id: "d", entity: "sensor.status", icon: "✓" }];
const rows = deviceValueReadouts(h, links);
assert.deepEqual(rows.map((v) => v.icon), ["❄", "🔥", "💧", "✓"]);
assert.equal(rows[0].text, "22.7 °C", "an inferred actuator domain cannot replace the numeric reading with an on/off state");
assert.equal(rows[1].label, "Ausgang");
assert.equal(rows[3].text, "normal");
assert.match(deviceValuesText(h, links), /❄ Innen: 22.7 °C.*🔥 48.5 °C.*💧 55 %/);
assert.equal(deviceValueReadouts(h, [links[1]])[0].id, "b", "removing one link keeps the others intact");
});
test("unassigned values stay hidden and linked unavailable readings retain a dash", () => {
const h = hassOf([entity("sensor.offline", "unavailable"), entity("sensor.native", "on", { symcon_formatted: "Ein" })]);
const rows = deviceValueReadouts(h, [{ id: "empty", entity: null }, { id: "none", entity: "none" }, { id: "offline", entity: "sensor.offline" }, { id: "native", entity: "sensor.native" }]);
assert.deepEqual(rows.map((v) => v.text), ["–", "Ein"]);
});