Add reset consumption button to Bosch SHC (#188773)

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Thomas
2026-11-24 15:44:09 +01:00
committed by GitHub
co-authored by Claude Sonnet 5.5 Joost Lekkerkerker
parent 6715b69ccb
commit fefbf2f066
3 changed files with 73 additions and 1 deletions
+29 -1
View File
@@ -4,7 +4,13 @@ from collections.abc import Callable
from dataclasses import dataclass
from typing import TYPE_CHECKING, override
from boschshcpy import SHCMotionDetector2, SHCOutdoorSiren, SHCSmokeDetector
from boschshcpy import (
SHCMotionDetector2,
SHCOutdoorSiren,
SHCSmartPlug,
SHCSmartPlugCompact,
SHCSmokeDetector,
)
from boschshcpy.device import SHCDevice
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
@@ -46,6 +52,15 @@ SIREN_TEST_ALARM_DESCRIPTION = SHCButtonEntityDescription[SHCOutdoorSiren](
press_fn=lambda device: device.trigger_test_alarm(),
)
RESET_ENERGY_DESCRIPTION = SHCButtonEntityDescription[
SHCSmartPlug | SHCSmartPlugCompact
](
key="reset_energy_summation",
translation_key="reset_energy_summation",
entity_category=EntityCategory.CONFIG,
press_fn=lambda device: device.reset_energy_summation(),
)
async def async_setup_entry(
hass: HomeAssistant,
@@ -90,6 +105,19 @@ async def async_setup_entry(
)
for device in session.device_helper.outdoor_sirens
)
entities.extend(
SHCButton(
hass=hass,
device=plug,
parent_id=shc_info.unique_id,
entry_id=config_entry.entry_id,
description=RESET_ENERGY_DESCRIPTION,
)
for plug in (
*session.device_helper.smart_plugs,
*session.device_helper.smart_plugs_compact,
)
)
async_add_entities(entities)
@@ -69,6 +69,9 @@
}
},
"button": {
"reset_energy_summation": {
"name": "Reset consumption value"
},
"reset_tamper": {
"name": "Reset tamper"
},
+41
View File
@@ -14,6 +14,8 @@ from .conftest import (
motion_detector2_device,
outdoor_siren_device,
setup_integration,
smart_plug_compact_device,
smart_plug_device,
smoke_detector_device,
)
@@ -116,3 +118,42 @@ async def test_siren_test_alarm_button_press(
)
device.trigger_test_alarm.assert_called_once_with()
@pytest.mark.parametrize(
"device_buckets",
[
{
"smart_plugs": [smart_plug_device()],
"smart_plugs_compact": [smart_plug_compact_device()],
}
],
indirect=True,
)
@pytest.mark.parametrize(
("entity_id", "bucket"),
[
("button.smart_plug_reset_consumption_value", "smart_plugs"),
("button.smart_plug_compact_reset_consumption_value", "smart_plugs_compact"),
],
)
@pytest.mark.usefixtures("mock_session")
async def test_reset_energy_summation_button_press(
hass: HomeAssistant,
mock_session: MagicMock,
mock_config_entry: MockConfigEntry,
entity_id: str,
bucket: str,
) -> None:
"""Pressing the button resets the accumulated energy counter."""
await setup_integration(hass, mock_config_entry)
device = getattr(mock_session.device_helper, bucket)[0]
await hass.services.async_call(
BUTTON_DOMAIN,
ButtonService.PRESS,
{TargetKey.ENTITY_ID: entity_id},
blocking=True,
)
device.reset_energy_summation.assert_called_once_with()