From 58070e14a7403fa53c379e487327ff69ffb2e7af Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:40:55 +0100 Subject: [PATCH] Add significant Change support for camera (#105866) --- .../components/camera/significant_change.py | 22 +++++++++++++++++++ .../camera/test_significant_change.py | 19 ++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 homeassistant/components/camera/significant_change.py create mode 100644 tests/components/camera/test_significant_change.py diff --git a/homeassistant/components/camera/significant_change.py b/homeassistant/components/camera/significant_change.py new file mode 100644 index 00000000000..4fc175b0723 --- /dev/null +++ b/homeassistant/components/camera/significant_change.py @@ -0,0 +1,22 @@ +"""Helper to test significant Camera 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 | None: + """Test if state significantly changed.""" + if old_state != new_state: + return True + + return None diff --git a/tests/components/camera/test_significant_change.py b/tests/components/camera/test_significant_change.py new file mode 100644 index 00000000000..b1e1eb66589 --- /dev/null +++ b/tests/components/camera/test_significant_change.py @@ -0,0 +1,19 @@ +"""Test the Camera significant change platform.""" +from homeassistant.components.camera import STATE_IDLE, STATE_RECORDING +from homeassistant.components.camera.significant_change import ( + async_check_significant_change, +) + + +async def test_significant_change() -> None: + """Detect Camera significant changes.""" + attrs = {} + assert not async_check_significant_change( + None, STATE_IDLE, attrs, STATE_IDLE, attrs + ) + assert not async_check_significant_change( + None, STATE_IDLE, attrs, STATE_IDLE, {"dummy": "dummy"} + ) + assert async_check_significant_change( + None, STATE_IDLE, attrs, STATE_RECORDING, attrs + )