From ba2dbaec51d6c73ee0b8a96ff5a696d99018dd42 Mon Sep 17 00:00:00 2001 From: Thomas <10558666+mosandlt@users.noreply.github.com> Date: Tue, 6 Oct 2026 14:07:05 +0200 Subject: [PATCH] bosch_shc: add Motion Detector II tamper reset button (#184448) Co-authored-by: Claude Sonnet 5.5 --- homeassistant/components/bosch_shc/button.py | 20 ++++++++- .../components/bosch_shc/strings.json | 3 ++ tests/components/bosch_shc/conftest.py | 2 + tests/components/bosch_shc/test_button.py | 43 ++++++++++++++++++- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/bosch_shc/button.py b/homeassistant/components/bosch_shc/button.py index 0ab00e848f2c..4855af33665e 100644 --- a/homeassistant/components/bosch_shc/button.py +++ b/homeassistant/components/bosch_shc/button.py @@ -4,7 +4,7 @@ from collections.abc import Callable from dataclasses import dataclass from typing import TYPE_CHECKING, override -from boschshcpy import SHCSmokeDetector +from boschshcpy import SHCMotionDetector2, SHCSmokeDetector from boschshcpy.device import SHCDevice from homeassistant.components.button import ButtonEntity, ButtonEntityDescription @@ -32,6 +32,13 @@ SMOKE_TEST_DESCRIPTION = SHCButtonEntityDescription[SHCSmokeDetector]( press_fn=lambda device: device.smoketest_requested(), ) +TAMPER_RESET_DESCRIPTION = SHCButtonEntityDescription[SHCMotionDetector2]( + key="reset_tamper", + translation_key="reset_tamper", + entity_category=EntityCategory.DIAGNOSTIC, + press_fn=lambda device: device.reset_tampered_state(), +) + async def async_setup_entry( hass: HomeAssistant, @@ -55,6 +62,17 @@ async def async_setup_entry( ) for device in session.device_helper.smoke_detectors ) + async_add_entities( + SHCButton( + hass=hass, + device=device, + parent_id=shc_info.unique_id, + entry_id=config_entry.entry_id, + description=TAMPER_RESET_DESCRIPTION, + ) + for device in session.device_helper.motion_detectors2 + if device.supports_tamper_reset + ) class SHCButton[_DeviceT: SHCDevice](SHCEntity, ButtonEntity): diff --git a/homeassistant/components/bosch_shc/strings.json b/homeassistant/components/bosch_shc/strings.json index b7da3cbae95b..826dc2d552a3 100644 --- a/homeassistant/components/bosch_shc/strings.json +++ b/homeassistant/components/bosch_shc/strings.json @@ -44,6 +44,9 @@ }, "entity": { "button": { + "reset_tamper": { + "name": "Reset tamper" + }, "smoke_test": { "name": "Start self-test" } diff --git a/tests/components/bosch_shc/conftest.py b/tests/components/bosch_shc/conftest.py index b5f7f7d1447f..3e1aeaee84b4 100644 --- a/tests/components/bosch_shc/conftest.py +++ b/tests/components/bosch_shc/conftest.py @@ -640,6 +640,7 @@ def motion_detector2_device( tamper_protection_enabled: bool = False, supports_smart_sensitivity: bool = False, smart_sensitivity_enabled: bool = False, + supports_tamper_reset: bool = True, latestmotion: str = "", motion_sensitivity: PirSensorConfigurationService.MotionSensitivity | None = PirSensorConfigurationService.MotionSensitivity.MIDDLE, @@ -659,6 +660,7 @@ def motion_detector2_device( device.tamper_protection_enabled = tamper_protection_enabled device.supports_smart_sensitivity = supports_smart_sensitivity device.smart_sensitivity_enabled = smart_sensitivity_enabled + device.supports_tamper_reset = supports_tamper_reset device.latestmotion = latestmotion if motion_sensitivity is None: del device.motion_sensitivity diff --git a/tests/components/bosch_shc/test_button.py b/tests/components/bosch_shc/test_button.py index 20123ecd2cf0..925ae5950dac 100644 --- a/tests/components/bosch_shc/test_button.py +++ b/tests/components/bosch_shc/test_button.py @@ -9,7 +9,7 @@ from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRE from homeassistant.const import ATTR_ENTITY_ID, Platform from homeassistant.core import HomeAssistant -from .conftest import setup_integration, smoke_detector_device +from .conftest import motion_detector2_device, setup_integration, smoke_detector_device from tests.common import MockConfigEntry @@ -43,3 +43,44 @@ async def test_smoke_test_button_press( ) device.smoketest_requested.assert_called_once_with() + + +@pytest.mark.parametrize( + "device_buckets", + [{"motion_detectors2": [motion_detector2_device()]}], + indirect=True, +) +@pytest.mark.usefixtures("mock_session") +async def test_reset_tamper_button_press( + hass: HomeAssistant, + mock_session: MagicMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Pressing the button resets the tamper condition.""" + await setup_integration(hass, mock_config_entry) + device = mock_session.device_helper.motion_detectors2[0] + + await hass.services.async_call( + BUTTON_DOMAIN, + SERVICE_PRESS, + {ATTR_ENTITY_ID: "button.motion_detector_reset_tamper"}, + blocking=True, + ) + + device.reset_tampered_state.assert_called_once_with() + + +@pytest.mark.parametrize( + "device_buckets", + [{"motion_detectors2": [motion_detector2_device(supports_tamper_reset=False)]}], + indirect=True, +) +@pytest.mark.usefixtures("mock_session") +async def test_no_reset_tamper_button_without_support( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, +) -> None: + """No tamper reset button is created without the LatestTamper service.""" + await setup_integration(hass, mock_config_entry) + + assert hass.states.get("button.motion_detector_reset_tamper") is None