2021-11-25 21:02:59 +00:00
|
|
|
"""TOLO Sauna Button controls."""
|
|
|
|
|
|
|
|
from tololib.const import LampMode
|
|
|
|
|
|
|
|
from homeassistant.components.button import ButtonEntity
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
2021-12-16 12:09:35 +00:00
|
|
|
from homeassistant.helpers.entity import EntityCategory
|
2021-11-25 21:02:59 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
|
|
|
|
from . import ToloSaunaCoordinatorEntity, ToloSaunaUpdateCoordinator
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
|
|
|
"""Set up buttons for TOLO Sauna."""
|
|
|
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
async_add_entities(
|
|
|
|
[
|
|
|
|
ToloLampNextColorButton(coordinator, entry),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ToloLampNextColorButton(ToloSaunaCoordinatorEntity, ButtonEntity):
|
|
|
|
"""Button for switching to the next lamp color."""
|
|
|
|
|
2021-12-16 12:09:35 +00:00
|
|
|
_attr_entity_category = EntityCategory.CONFIG
|
2021-11-25 21:02:59 +00:00
|
|
|
_attr_icon = "mdi:palette"
|
|
|
|
_attr_name = "Next Color"
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self, coordinator: ToloSaunaUpdateCoordinator, entry: ConfigEntry
|
|
|
|
) -> 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()
|