Add significant change support to binary_sensor (#45677)
* Add significant change support to binary_sensorpull/46219/head
parent
85e6bc581f
commit
6bf59dbeab
|
@ -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
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
)
|
Loading…
Reference in New Issue