From cabf3b7ab9b13326db537ba369f3fd50a2adca58 Mon Sep 17 00:00:00 2001 From: Tom Matheussen <13683094+Tommatheussen@users.noreply.github.com> Date: Wed, 18 Feb 2026 12:04:30 +0100 Subject: [PATCH] Set last_reported timestamp for Satel Integra entities (#163352) --- .../satel_integra/alarm_control_panel.py | 7 ++-- .../components/satel_integra/binary_sensor.py | 6 ++-- .../components/satel_integra/switch.py | 6 ++-- .../satel_integra/test_alarm_control_panel.py | 34 +++++++++++++++++- .../satel_integra/test_binary_sensor.py | 35 ++++++++++++++++++- tests/components/satel_integra/test_switch.py | 34 +++++++++++++++++- 6 files changed, 106 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/satel_integra/alarm_control_panel.py b/homeassistant/components/satel_integra/alarm_control_panel.py index ed72698cb3d..549ddcca9a2 100644 --- a/homeassistant/components/satel_integra/alarm_control_panel.py +++ b/homeassistant/components/satel_integra/alarm_control_panel.py @@ -102,11 +102,8 @@ class SatelIntegraAlarmPanel( @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - state = self._read_alarm_state() - - if state != self._attr_alarm_state: - self._attr_alarm_state = state - self.async_write_ha_state() + self._attr_alarm_state = self._read_alarm_state() + self.async_write_ha_state() def _read_alarm_state(self) -> AlarmControlPanelState | None: """Read current status of the alarm and translate it into HA status.""" diff --git a/homeassistant/components/satel_integra/binary_sensor.py b/homeassistant/components/satel_integra/binary_sensor.py index a16fba03046..567fecb132d 100644 --- a/homeassistant/components/satel_integra/binary_sensor.py +++ b/homeassistant/components/satel_integra/binary_sensor.py @@ -103,10 +103,8 @@ class SatelIntegraBinarySensor[_CoordinatorT: SatelIntegraBaseCoordinator]( @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - new_state = self._get_state_from_coordinator() - if new_state != self._attr_is_on: - self._attr_is_on = new_state - self.async_write_ha_state() + self._attr_is_on = self._get_state_from_coordinator() + self.async_write_ha_state() def _get_state_from_coordinator(self) -> bool | None: """Method to get binary sensor state from coordinator data.""" diff --git a/homeassistant/components/satel_integra/switch.py b/homeassistant/components/satel_integra/switch.py index 7b321d6eeda..1c53ce7ee9e 100644 --- a/homeassistant/components/satel_integra/switch.py +++ b/homeassistant/components/satel_integra/switch.py @@ -74,10 +74,8 @@ class SatelIntegraSwitch( @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - new_state = self._get_state_from_coordinator() - if new_state != self._attr_is_on: - self._attr_is_on = new_state - self.async_write_ha_state() + self._attr_is_on = self._get_state_from_coordinator() + self.async_write_ha_state() def _get_state_from_coordinator(self) -> bool | None: """Method to get switch state from coordinator data.""" diff --git a/tests/components/satel_integra/test_alarm_control_panel.py b/tests/components/satel_integra/test_alarm_control_panel.py index f447739d30e..5de46aff313 100644 --- a/tests/components/satel_integra/test_alarm_control_panel.py +++ b/tests/components/satel_integra/test_alarm_control_panel.py @@ -3,6 +3,7 @@ from collections.abc import AsyncGenerator from unittest.mock import AsyncMock, patch +from freezegun.api import FrozenDateTimeFactory import pytest from satel_integra.satel_integra import AlarmState from syrupy.assertion import SnapshotAssertion @@ -26,7 +27,12 @@ from homeassistant.helpers.entity_registry import EntityRegistry from . import MOCK_CODE, MOCK_ENTRY_ID, get_monitor_callbacks, setup_integration -from tests.common import MockConfigEntry, snapshot_platform +from tests.common import ( + MockConfigEntry, + async_capture_events, + async_fire_time_changed, + snapshot_platform, +) @pytest.fixture(autouse=True) @@ -163,3 +169,29 @@ async def test_alarm_control_panel_disarming( mock_satel.disarm.assert_awaited_once_with(MOCK_CODE, [1]) mock_satel.clear_alarm.assert_awaited_once_with(MOCK_CODE, [1]) + + +async def test_alarm_panel_last_reported( + hass: HomeAssistant, + mock_satel: AsyncMock, + mock_config_entry_with_subentries: MockConfigEntry, + freezer: FrozenDateTimeFactory, +) -> None: + """Test alarm panels update last_reported if same state is reported.""" + events = async_capture_events(hass, "state_changed") + await setup_integration(hass, mock_config_entry_with_subentries) + + first_reported = hass.states.get("alarm_control_panel.home").last_reported + assert first_reported is not None + # Initial state change event + assert len(events) == 1 + + freezer.tick(1) + async_fire_time_changed(hass) + + # Run callbacks with same payload + alarm_panel_update_method, _, _ = get_monitor_callbacks(mock_satel) + alarm_panel_update_method() + + assert first_reported != hass.states.get("alarm_control_panel.home").last_reported + assert len(events) == 1 # last_reported shall not fire state_changed diff --git a/tests/components/satel_integra/test_binary_sensor.py b/tests/components/satel_integra/test_binary_sensor.py index 7d125e53309..42435968146 100644 --- a/tests/components/satel_integra/test_binary_sensor.py +++ b/tests/components/satel_integra/test_binary_sensor.py @@ -3,6 +3,7 @@ from collections.abc import AsyncGenerator from unittest.mock import AsyncMock, patch +from freezegun.api import FrozenDateTimeFactory import pytest from syrupy.assertion import SnapshotAssertion @@ -15,7 +16,12 @@ from homeassistant.helpers.entity_registry import EntityRegistry from . import get_monitor_callbacks, setup_integration -from tests.common import MockConfigEntry, snapshot_platform +from tests.common import ( + MockConfigEntry, + async_capture_events, + async_fire_time_changed, + snapshot_platform, +) @pytest.fixture(autouse=True) @@ -117,3 +123,30 @@ async def test_binary_sensor_callback( zone_update_method({"zones": {2: 1}}) assert hass.states.get("binary_sensor.zone").state == STATE_UNKNOWN assert hass.states.get("binary_sensor.output").state == STATE_UNKNOWN + + +async def test_binary_sensor_last_reported( + hass: HomeAssistant, + mock_satel: AsyncMock, + mock_config_entry_with_subentries: MockConfigEntry, + freezer: FrozenDateTimeFactory, +) -> None: + """Test binary sensors update last_reported if same state is reported.""" + events = async_capture_events(hass, "state_changed") + await setup_integration(hass, mock_config_entry_with_subentries) + + first_reported = hass.states.get("binary_sensor.zone").last_reported + assert first_reported is not None + # Initial 2 state change events for both zone and output + assert len(events) == 2 + + freezer.tick(1) + async_fire_time_changed(hass) + + # Run callbacks with same payload + _, zone_update_method, output_update_method = get_monitor_callbacks(mock_satel) + output_update_method({"outputs": {1: 0}}) + zone_update_method({"zones": {1: 0}}) + + assert first_reported != hass.states.get("binary_sensor.zone").last_reported + assert len(events) == 2 # last_reported shall not fire state_changed diff --git a/tests/components/satel_integra/test_switch.py b/tests/components/satel_integra/test_switch.py index 16532407559..8a6a3bedc83 100644 --- a/tests/components/satel_integra/test_switch.py +++ b/tests/components/satel_integra/test_switch.py @@ -3,6 +3,7 @@ from collections.abc import AsyncGenerator from unittest.mock import AsyncMock, patch +from freezegun.api import FrozenDateTimeFactory import pytest from syrupy.assertion import SnapshotAssertion @@ -25,7 +26,12 @@ from homeassistant.helpers.entity_registry import EntityRegistry from . import MOCK_CODE, MOCK_ENTRY_ID, get_monitor_callbacks, setup_integration -from tests.common import MockConfigEntry, snapshot_platform +from tests.common import ( + MockConfigEntry, + async_capture_events, + async_fire_time_changed, + snapshot_platform, +) @pytest.fixture(autouse=True) @@ -144,3 +150,29 @@ async def test_switch_change_state( assert hass.states.get("switch.switchable_output").state == STATE_OFF mock_satel.set_output.assert_awaited_once_with(MOCK_CODE, 1, False) + + +async def test_switch_last_reported( + hass: HomeAssistant, + mock_satel: AsyncMock, + mock_config_entry_with_subentries: MockConfigEntry, + freezer: FrozenDateTimeFactory, +) -> None: + """Test switches update last_reported if same state is reported.""" + events = async_capture_events(hass, "state_changed") + await setup_integration(hass, mock_config_entry_with_subentries) + + first_reported = hass.states.get("switch.switchable_output").last_reported + assert first_reported is not None + # Initial state change event + assert len(events) == 1 + + freezer.tick(1) + async_fire_time_changed(hass) + + # Run callbacks with same payload + _, _, output_update_method = get_monitor_callbacks(mock_satel) + output_update_method({"outputs": {1: 0}}) + + assert first_reported != hass.states.get("switch.switchable_output").last_reported + assert len(events) == 1 # last_reported shall not fire state_changed