diff --git a/src/state_icon.ts b/src/state_icon.ts index 97d3cd3..2a75f2f 100644 --- a/src/state_icon.ts +++ b/src/state_icon.ts @@ -8,7 +8,7 @@ import { inputDateTimeIcon } from "./input_datetime_icon"; import { domainIcon } from "./domain_icons"; const domainIcons = { - binary_sensor: binarySensorIcon, + binary_sensor: (stateObj: HassEntity) => binarySensorIcon(stateObj.state, stateObj), cover: coverIcon, sensor: sensorIcon, input_datetime: inputDateTimeIcon, diff --git a/test/icons.test.ts b/test/icons.test.ts index ffcd4bf..558fe10 100644 --- a/test/icons.test.ts +++ b/test/icons.test.ts @@ -4,6 +4,7 @@ import { coverIcon } from "../src/cover_icon"; import { domainIcon } from "../src/domain_icons"; import { inputDateTimeIcon } from "../src/input_datetime_icon"; import { sensorIcon } from "../src/sensor_icon"; +import { stateIcon } from "../src/state_icon"; describe("domainIcon", () => { it("returns fixed icons and state-based icons", () => { @@ -69,3 +70,23 @@ describe("inputDateTimeIcon", () => { ); }); }); + +describe("stateIcon", () => { + it("returns correct icon for binary_sensor with device_class", () => { + const stateObj = { + entity_id: "binary_sensor.door", + state: "off", + attributes: { device_class: "door" }, + } as any; + expect(stateIcon(stateObj)).toBe("mdi:door-closed"); + }); + + it("returns correct icon for binary_sensor on state", () => { + const stateObj = { + entity_id: "binary_sensor.door", + state: "on", + attributes: { device_class: "door" }, + } as any; + expect(stateIcon(stateObj)).toBe("mdi:door-open"); + }); +});