mirror of
https://github.com/home-assistant/core.git
synced 2026-05-17 22:10:57 +01:00
ea642980f2
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""Support for SwitchBee scenario button."""
|
|
|
|
from switchbee.api.central_unit import SwitchBeeError
|
|
from switchbee.device import ApiStateCommand, DeviceType
|
|
|
|
from homeassistant.components.button import ButtonEntity
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import HomeAssistantError
|
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|
|
|
from .coordinator import SwitchBeeConfigEntry
|
|
from .entity import SwitchBeeEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: SwitchBeeConfigEntry,
|
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
|
) -> None:
|
|
"""Set up Switchbee button."""
|
|
coordinator = entry.runtime_data
|
|
async_add_entities(
|
|
SwitchBeeButton(switchbee_device, coordinator)
|
|
for switchbee_device in coordinator.data.values()
|
|
if switchbee_device.type == DeviceType.Scenario
|
|
)
|
|
|
|
|
|
class SwitchBeeButton(SwitchBeeEntity, ButtonEntity):
|
|
"""Representation of an Switchbee button."""
|
|
|
|
async def async_press(self) -> None:
|
|
"""Fire the scenario in the SwitchBee hub."""
|
|
try:
|
|
await self.coordinator.api.set_state(self._device.id, ApiStateCommand.ON)
|
|
except SwitchBeeError as exp:
|
|
raise HomeAssistantError(
|
|
f"Failed to fire scenario {self.name}, {exp!s}"
|
|
) from exp
|