Add significant change support to select entity (#51978)

pull/51997/head
Franck Nijhof 2021-06-18 20:31:09 +02:00 committed by GitHub
parent 98a53188f8
commit 06edc731c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,19 @@
"""Helper to test significant Select state changes."""
from __future__ import annotations
from typing import Any
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,
) -> bool:
"""Test if state significantly changed."""
return old_state != new_state

View File

@ -0,0 +1,20 @@
"""Test the select significant change platform."""
from homeassistant.components.select.significant_change import (
async_check_significant_change,
)
from homeassistant.core import HomeAssistant
async def test_significant_change(hass: HomeAssistant) -> None:
"""Detect select significant change."""
attrs1 = {"options": ["option1", "option2"]}
attrs2 = {"options": ["option1", "option2", "option3"]}
assert not async_check_significant_change(
hass, "option1", attrs1, "option1", attrs1
)
assert not async_check_significant_change(
hass, "option1", attrs1, "option1", attrs2
)
assert async_check_significant_change(hass, "option1", attrs1, "option2", attrs1)
assert async_check_significant_change(hass, "option1", attrs1, "option2", attrs2)