Coverage for custom_components/supernotify/button.py: 100%
20 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-08 17:42 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-08 17:42 +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
23# Entities are pushed, never polled, and their actions only change local state
24PARALLEL_UPDATES = 0
27async def async_setup_entry(
28 hass: HomeAssistant,
29 entry: SupernotifyConfigEntry,
30 async_add_entities: AddConfigEntryEntitiesCallback,
31) -> None:
32 """Add the reset overrides button."""
33 _ = hass
34 async_add_entities([SupernotifyResetOverridesButton(entry.runtime_data, entry.entry_id)])
37class SupernotifyResetOverridesButton(ButtonEntity):
38 """Put everything switched on or off at runtime back to its configured state."""
40 _attr_has_entity_name = True
41 _attr_entity_category = EntityCategory.CONFIG
42 _attr_translation_key = "reset_overrides"
43 _attr_unique_id = "reset_overrides"
44 _attr_should_poll = False
46 def __init__(self, engine: SupernotifyEngine, entry_id: str) -> None:
47 self._engine = engine
48 self._attr_device_info = ha_device_info(entry_id)
50 async def async_press(self) -> None:
51 self._engine.reset_overrides(context=self._context)