From 441b0b2fb7ddb7c82a0ec3a2e873f9c64a552fa3 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 16 Oct 2021 23:30:52 +0200 Subject: [PATCH] Add tamper device class for binary sensor (#57632) --- homeassistant/components/binary_sensor/__init__.py | 4 ++++ .../components/binary_sensor/device_condition.py | 9 +++++++++ homeassistant/components/binary_sensor/device_trigger.py | 6 ++++++ homeassistant/components/binary_sensor/strings.json | 4 ++++ .../components/binary_sensor/translations/en.json | 4 ++++ 5 files changed, 27 insertions(+) diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index 87d574fc4b0..d478780f9ac 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -92,6 +92,9 @@ DEVICE_CLASS_SMOKE = "smoke" # On means sound detected, Off means no sound (clear) DEVICE_CLASS_SOUND = "sound" +# On means tampering detected, Off means no tampering (clear) +DEVICE_CLASS_TAMPER = "tamper" + # On means update available, Off means up-to-date DEVICE_CLASS_UPDATE = "update" @@ -124,6 +127,7 @@ DEVICE_CLASSES = [ DEVICE_CLASS_SAFETY, DEVICE_CLASS_SMOKE, DEVICE_CLASS_SOUND, + DEVICE_CLASS_TAMPER, DEVICE_CLASS_UPDATE, DEVICE_CLASS_VIBRATION, DEVICE_CLASS_WINDOW, diff --git a/homeassistant/components/binary_sensor/device_condition.py b/homeassistant/components/binary_sensor/device_condition.py index a6b9d3ffb8b..ad305beb11b 100644 --- a/homeassistant/components/binary_sensor/device_condition.py +++ b/homeassistant/components/binary_sensor/device_condition.py @@ -37,6 +37,7 @@ from . import ( DEVICE_CLASS_SAFETY, DEVICE_CLASS_SMOKE, DEVICE_CLASS_SOUND, + DEVICE_CLASS_TAMPER, DEVICE_CLASS_UPDATE, DEVICE_CLASS_VIBRATION, DEVICE_CLASS_WINDOW, @@ -85,6 +86,8 @@ CONF_IS_SMOKE = "is_smoke" CONF_IS_NO_SMOKE = "is_no_smoke" CONF_IS_SOUND = "is_sound" CONF_IS_NO_SOUND = "is_no_sound" +CONF_IS_TAMPERED = "is_tampered" +CONF_IS_NOT_TAMPERED = "is_not_tampered" CONF_IS_UPDATE = "is_update" CONF_IS_NO_UPDATE = "is_no_update" CONF_IS_VIBRATION = "is_vibration" @@ -112,6 +115,7 @@ IS_ON = [ CONF_IS_PROBLEM, CONF_IS_SMOKE, CONF_IS_SOUND, + CONF_IS_TAMPERED, CONF_IS_UPDATE, CONF_IS_UNSAFE, CONF_IS_VIBRATION, @@ -132,6 +136,7 @@ IS_OFF = [ CONF_IS_NOT_PLUGGED_IN, CONF_IS_NOT_POWERED, CONF_IS_NOT_PRESENT, + CONF_IS_NOT_TAMPERED, CONF_IS_NOT_UNSAFE, CONF_IS_NO_GAS, CONF_IS_NO_LIGHT, @@ -194,6 +199,10 @@ ENTITY_CONDITIONS = { DEVICE_CLASS_SAFETY: [{CONF_TYPE: CONF_IS_UNSAFE}, {CONF_TYPE: CONF_IS_NOT_UNSAFE}], DEVICE_CLASS_SMOKE: [{CONF_TYPE: CONF_IS_SMOKE}, {CONF_TYPE: CONF_IS_NO_SMOKE}], DEVICE_CLASS_SOUND: [{CONF_TYPE: CONF_IS_SOUND}, {CONF_TYPE: CONF_IS_NO_SOUND}], + DEVICE_CLASS_TAMPER: [ + {CONF_TYPE: CONF_IS_TAMPERED}, + {CONF_TYPE: CONF_IS_NOT_TAMPERED}, + ], DEVICE_CLASS_UPDATE: [{CONF_TYPE: CONF_IS_UPDATE}, {CONF_TYPE: CONF_IS_NO_UPDATE}], DEVICE_CLASS_VIBRATION: [ {CONF_TYPE: CONF_IS_VIBRATION}, diff --git a/homeassistant/components/binary_sensor/device_trigger.py b/homeassistant/components/binary_sensor/device_trigger.py index a0966b5a018..f3eb1851247 100644 --- a/homeassistant/components/binary_sensor/device_trigger.py +++ b/homeassistant/components/binary_sensor/device_trigger.py @@ -35,6 +35,7 @@ from . import ( DEVICE_CLASS_SAFETY, DEVICE_CLASS_SMOKE, DEVICE_CLASS_SOUND, + DEVICE_CLASS_TAMPER, DEVICE_CLASS_UPDATE, DEVICE_CLASS_VIBRATION, DEVICE_CLASS_WINDOW, @@ -83,6 +84,8 @@ CONF_SMOKE = "smoke" CONF_NO_SMOKE = "no_smoke" CONF_SOUND = "sound" CONF_NO_SOUND = "no_sound" +CONF_TAMPERED = "tampered" +CONF_NOT_TAMPERED = "not_tampered" CONF_UPDATE = "update" CONF_NO_UPDATE = "no_update" CONF_VIBRATION = "vibration" @@ -113,6 +116,7 @@ TURNED_ON = [ CONF_UNSAFE, CONF_UPDATE, CONF_VIBRATION, + CONF_TAMPERED, CONF_TURNED_ON, ] @@ -129,6 +133,7 @@ TURNED_OFF = [ CONF_NOT_PLUGGED_IN, CONF_NOT_POWERED, CONF_NOT_PRESENT, + CONF_NOT_TAMPERED, CONF_NOT_UNSAFE, CONF_NO_GAS, CONF_NO_LIGHT, @@ -174,6 +179,7 @@ ENTITY_TRIGGERS = { DEVICE_CLASS_SMOKE: [{CONF_TYPE: CONF_SMOKE}, {CONF_TYPE: CONF_NO_SMOKE}], DEVICE_CLASS_SOUND: [{CONF_TYPE: CONF_SOUND}, {CONF_TYPE: CONF_NO_SOUND}], DEVICE_CLASS_UPDATE: [{CONF_TYPE: CONF_UPDATE}, {CONF_TYPE: CONF_NO_UPDATE}], + DEVICE_CLASS_TAMPER: [{CONF_TYPE: CONF_TAMPERED}, {CONF_TYPE: CONF_NOT_TAMPERED}], DEVICE_CLASS_VIBRATION: [ {CONF_TYPE: CONF_VIBRATION}, {CONF_TYPE: CONF_NO_VIBRATION}, diff --git a/homeassistant/components/binary_sensor/strings.json b/homeassistant/components/binary_sensor/strings.json index 62b6ec20323..70991f58759 100644 --- a/homeassistant/components/binary_sensor/strings.json +++ b/homeassistant/components/binary_sensor/strings.json @@ -38,6 +38,8 @@ "is_no_smoke": "{entity_name} is not detecting smoke", "is_sound": "{entity_name} is detecting sound", "is_no_sound": "{entity_name} is not detecting sound", + "is_tampered": "{entity_name} is detecting tampering", + "is_not_tampered": "{entity_name} is not detecting tampering", "is_update": "{entity_name} has an update available", "is_no_update": "{entity_name} is up-to-date", "is_vibration": "{entity_name} is detecting vibration", @@ -84,6 +86,8 @@ "no_smoke": "{entity_name} stopped detecting smoke", "sound": "{entity_name} started detecting sound", "no_sound": "{entity_name} stopped detecting sound", + "is_tampered": "{entity_name} started detecting tampering", + "is_not_tampered": "{entity_name} stopped detecting tampering", "update": "{entity_name} got an update available", "no_update": "{entity_name} became up-to-date", "vibration": "{entity_name} started detecting vibration", diff --git a/homeassistant/components/binary_sensor/translations/en.json b/homeassistant/components/binary_sensor/translations/en.json index 047820498da..be831864f38 100644 --- a/homeassistant/components/binary_sensor/translations/en.json +++ b/homeassistant/components/binary_sensor/translations/en.json @@ -31,6 +31,7 @@ "is_not_plugged_in": "{entity_name} is unplugged", "is_not_powered": "{entity_name} is not powered", "is_not_present": "{entity_name} is not present", + "is_not_tampered": "{entity_name} is not detecting tampering", "is_not_unsafe": "{entity_name} is safe", "is_occupied": "{entity_name} is occupied", "is_off": "{entity_name} is off", @@ -42,6 +43,7 @@ "is_problem": "{entity_name} is detecting problem", "is_smoke": "{entity_name} is detecting smoke", "is_sound": "{entity_name} is detecting sound", + "is_tampered": "{entity_name} is detecting tampering", "is_unsafe": "{entity_name} is unsafe", "is_update": "{entity_name} has an update available", "is_vibration": "{entity_name} is detecting vibration" @@ -52,6 +54,8 @@ "connected": "{entity_name} connected", "gas": "{entity_name} started detecting gas", "hot": "{entity_name} became hot", + "is_not_tampered": "{entity_name} stopped detecting tampering", + "is_tampered": "{entity_name} started detecting tampering", "light": "{entity_name} started detecting light", "locked": "{entity_name} locked", "moist": "{entity_name} became moist",