import assert from "node:assert/strict"; import { test } from "node:test"; import { symconControl, symconPercent } from "./symcon-controls.ts"; import { entity } from "./entities/fixtures.ts"; test("integer dimmers, normalized floats and separate blind variables preserve their native ranges", () => { const integer = entity("cover.6", "open", { symcon_id: 6, symcon_numeric_value: 128, symcon_min: 0, symcon_max: 255 }); const light = symconControl(integer, "light")!; assert.equal(light.entity_id, "light.6"); assert.equal(light.attributes.brightness, 128); assert.deepEqual(light.attributes.supported_color_modes, ["brightness"]); assert.equal(light.attributes.symcon_source_entity, "cover.6"); const fraction = entity("sensor.7", "0.4", { symcon_id: 7, symcon_numeric_value: 0.4, symcon_min: 0, symcon_max: 1 }); assert.equal(symconControl(fraction, "light")!.attributes.brightness, 102); assert.equal(symconControl(fraction, "cover")!.attributes.current_position, 40); assert.equal(symconPercent(entity("sensor.low", "10", { symcon_numeric_value: 10, symcon_min: 10, symcon_max: 110 })), 0); const toggle = symconControl(entity("switch.8", "on", { symcon_id: 8, symcon_variable_type: 0 }), "light")!; assert.deepEqual(toggle.attributes.supported_color_modes, ["onoff"], "a boolean can switch a light but cannot pretend to dim"); assert.equal(toggle.attributes.brightness, undefined); }); test("Boolean lights use their raw value even when names previously classified them as a garage door or lock", () => { for (const domain of ["cover", "lock", "binary_sensor", "switch", "sensor"]) { const st = entity(`${domain}.57755`, "locked", { symcon_id: 57755, symcon_variable_type: 0, symcon_value: false }); assert.equal(symconControl(st, "light")!.state, "off"); st.attributes.symcon_value = true; assert.equal(symconControl(st, "light")!.state, "on"); st.state = "unavailable"; assert.equal(symconControl(st, "light")!.state, "unavailable"); assert.equal(symconControl(st, "cover"), null, "a boolean is not a numeric blind position"); } });