1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-21 03:20:01 +00:00
Files
core/homeassistant/components/tolo/button.py
2025-10-05 18:43:37 +02:00

53 lines
1.6 KiB
Python

"""TOLO Sauna Button controls."""
from tololib import LampMode
from homeassistant.components.button import ButtonEntity
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .coordinator import ToloConfigEntry, ToloSaunaUpdateCoordinator
from .entity import ToloSaunaCoordinatorEntity
async def async_setup_entry(
hass: HomeAssistant,
entry: ToloConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up buttons for TOLO Sauna."""
coordinator = entry.runtime_data
async_add_entities(
[
ToloLampNextColorButton(coordinator, entry),
]
)
class ToloLampNextColorButton(ToloSaunaCoordinatorEntity, ButtonEntity):
"""Button for switching to the next lamp color."""
_attr_entity_category = EntityCategory.CONFIG
_attr_translation_key = "next_color"
def __init__(
self, coordinator: ToloSaunaUpdateCoordinator, entry: ToloConfigEntry
) -> None:
"""Initialize lamp next color button entity."""
super().__init__(coordinator, entry)
self._attr_unique_id = f"{entry.entry_id}_lamp_next_color"
@property
def available(self) -> bool:
"""Return if entity is available."""
return (
self.coordinator.data.status.lamp_on
and self.coordinator.data.settings.lamp_mode == LampMode.MANUAL
)
def press(self) -> None:
"""Execute action when lamp change color button was pressed."""
self.coordinator.client.lamp_change_color()