Coverage for custom_components/supernotify/button.py: 100%
19 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-25 21:14 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-25 21:14 +0000
1"""Button platform: reset every runtime override in one press.
3The same as calling supernotify.reset_overrides with no `kind` - every scenario, recipient,
4delivery and transport switched on or off at runtime is put back to its configured state.
5"""
7from __future__ import annotations
9from typing import TYPE_CHECKING
11from homeassistant.components.button import ButtonEntity
12from homeassistant.const import EntityCategory
14from .hass_api import ha_device_info
16if TYPE_CHECKING:
17 from homeassistant.core import HomeAssistant
18 from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
20 from . import SupernotifyConfigEntry
21 from .engine import SupernotifyEngine
24async def async_setup_entry(
25 hass: HomeAssistant,
26 entry: SupernotifyConfigEntry,
27 async_add_entities: AddConfigEntryEntitiesCallback,
28) -> None:
29 """Add the reset overrides button."""
30 _ = hass
31 async_add_entities([SupernotifyResetOverridesButton(entry.runtime_data, entry.entry_id)])
34class SupernotifyResetOverridesButton(ButtonEntity):
35 """Put everything switched on or off at runtime back to its configured state."""
37 _attr_has_entity_name = True
38 _attr_entity_category = EntityCategory.CONFIG
39 _attr_translation_key = "reset_overrides"
40 _attr_unique_id = "reset_overrides"
41 _attr_should_poll = False
43 def __init__(self, engine: SupernotifyEngine, entry_id: str) -> None:
44 self._engine = engine
45 self._attr_device_info = ha_device_info(entry_id)
47 async def async_press(self) -> None:
48 self._engine.reset_overrides()