mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 12:21:04 -04:00
bosch_shc: add Motion Detector II tamper reset button (#184448)
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
c30459718d
commit
ba2dbaec51
@@ -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):
|
||||
|
||||
@@ -44,6 +44,9 @@
|
||||
},
|
||||
"entity": {
|
||||
"button": {
|
||||
"reset_tamper": {
|
||||
"name": "Reset tamper"
|
||||
},
|
||||
"smoke_test": {
|
||||
"name": "Start self-test"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user