From a91d25b27d1838099b8d3885fb21aaaf897088b3 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 14 Oct 2021 12:22:07 +0200 Subject: [PATCH] Add tamper device class for binary sensor (#10268) --- src/common/entity/binary_sensor_icon.ts | 1 + src/components/chart/state-history-chart-timeline.ts | 1 + src/data/logbook.ts | 9 +++++++++ src/translations/en.json | 4 +++- src/util/hass-attributes-util.ts | 1 + 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/common/entity/binary_sensor_icon.ts b/src/common/entity/binary_sensor_icon.ts index da18e0d01f..8ee9864e77 100644 --- a/src/common/entity/binary_sensor_icon.ts +++ b/src/common/entity/binary_sensor_icon.ts @@ -22,6 +22,7 @@ export const binarySensorIcon = (state?: string, stateObj?: HassEntity) => { case "gas": case "problem": case "safety": + case "tamper": return is_off ? "hass:check-circle" : "hass:alert-circle"; case "smoke": return is_off ? "hass:check-circle" : "hass:smoke"; diff --git a/src/components/chart/state-history-chart-timeline.ts b/src/components/chart/state-history-chart-timeline.ts index 6aa8c2951b..4dd857bcfe 100644 --- a/src/components/chart/state-history-chart-timeline.ts +++ b/src/components/chart/state-history-chart-timeline.ts @@ -26,6 +26,7 @@ const BINARY_SENSOR_DEVICE_CLASS_COLOR_INVERTED = new Set([ "problem", "safety", "smoke", + "tamper", "window", ]); diff --git a/src/data/logbook.ts b/src/data/logbook.ts index b67e602d6c..4671a6f2e8 100644 --- a/src/data/logbook.ts +++ b/src/data/logbook.ts @@ -279,6 +279,15 @@ export const getLogbookMessage = ( ); } break; + + case "tamper": + if (isOn) { + return hass.localize(`${LOGBOOK_LOCALIZE_PATH}.detected_tampering`); + } + if (isOff) { + return hass.localize(`${LOGBOOK_LOCALIZE_PATH}.cleared_tampering`); + } + break; } break; diff --git a/src/translations/en.json b/src/translations/en.json index 78d240f811..9755fff8ab 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -333,7 +333,9 @@ "turned_off": "turned off", "turned_on": "turned on", "changed_to_state": "changed to {state}", - "became_unavailable": "became unavailable" + "became_unavailable": "became unavailable", + "detected_tampering": "detected tampering", + "cleared_tampering": "cleared tampering" } }, "entity": { diff --git a/src/util/hass-attributes-util.ts b/src/util/hass-attributes-util.ts index f237e082ce..8aeaf49b13 100644 --- a/src/util/hass-attributes-util.ts +++ b/src/util/hass-attributes-util.ts @@ -34,6 +34,7 @@ const hassAttributeUtil = { "safety", "smoke", "sound", + "tamper", "vibration", "window", ],