diff --git a/homeassistant/components/binary_sensor/significant_change.py b/homeassistant/components/binary_sensor/significant_change.py new file mode 100644 index 00000000000..bc2dba04f09 --- /dev/null +++ b/homeassistant/components/binary_sensor/significant_change.py @@ -0,0 +1,20 @@ +"""Helper to test significant Binary Sensor state changes.""" +from typing import Any, Optional + +from homeassistant.core import HomeAssistant, callback + + +@callback +def async_check_significant_change( + hass: HomeAssistant, + old_state: str, + old_attrs: dict, + new_state: str, + new_attrs: dict, + **kwargs: Any, +) -> Optional[bool]: + """Test if state significantly changed.""" + if old_state != new_state: + return True + + return False diff --git a/homeassistant/components/binary_sensor/translations/en.json b/homeassistant/components/binary_sensor/translations/en.json index 98c8a3a220a..a9a20e3fa50 100644 --- a/homeassistant/components/binary_sensor/translations/en.json +++ b/homeassistant/components/binary_sensor/translations/en.json @@ -159,8 +159,8 @@ "on": "Plugged in" }, "presence": { - "off": "Away", - "on": "Home" + "off": "[%key:common::state::not_home%]", + "on": "[%key:common::state::home%]" }, "problem": { "off": "OK", diff --git a/tests/components/binary_sensor/test_significant_change.py b/tests/components/binary_sensor/test_significant_change.py new file mode 100644 index 00000000000..673374a15e4 --- /dev/null +++ b/tests/components/binary_sensor/test_significant_change.py @@ -0,0 +1,20 @@ +"""Test the Binary Sensor significant change platform.""" +from homeassistant.components.binary_sensor.significant_change import ( + async_check_significant_change, +) + + +async def test_significant_change(): + """Detect Binary Sensor significant changes.""" + old_attrs = {"attr_1": "value_1"} + new_attrs = {"attr_1": "value_2"} + + assert ( + async_check_significant_change(None, "on", old_attrs, "on", old_attrs) is False + ) + assert ( + async_check_significant_change(None, "on", old_attrs, "on", new_attrs) is False + ) + assert ( + async_check_significant_change(None, "on", old_attrs, "off", old_attrs) is True + )