LifeFlow/home-assistant/custom_components/lifeflow/button.py

71 lines
2.0 KiB
Python

"""LifeFlow buttons for Home Assistant."""
from __future__ import annotations
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import (
DOMAIN,
BUTTON_LOG_VITAMINS,
BUTTON_LOG_WATER,
BUTTON_LOG_MEDS,
BUTTON_COMPLETE_ROUTINE,
)
BUTTON_TYPES: tuple[ButtonEntityDescription, ...] = (
ButtonEntityDescription(
key=BUTTON_LOG_VITAMINS,
name="Log Vitamins",
icon="mdi:pill",
),
ButtonEntityDescription(
key=BUTTON_LOG_WATER,
name="Log Water",
icon="mdi:water",
),
ButtonEntityDescription(
key=BUTTON_LOG_MEDS,
name="Log Medication",
icon="mdi:medication",
),
ButtonEntityDescription(
key=BUTTON_COMPLETE_ROUTINE,
name="Complete Routine",
icon="mdi:check-circle",
),
)
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up LifeFlow buttons."""
entities = [LifeFlowButton(entry, description) for description in BUTTON_TYPES]
async_add_entities(entities)
class LifeFlowButton(ButtonEntity):
"""LifeFlow button."""
def __init__(
self,
entry: ConfigEntry,
description: ButtonEntityDescription,
) -> None:
"""Initialize the button."""
self.entity_description = description
self._entry = entry
self._attr_unique_id = f"{entry.entry_id}_{description.key}"
self._attr_name = f"LifeFlow {description.name}"
async def async_press(self) -> None:
"""Handle the button press."""
# In production, this would call the LifeFlow API
# For now, just log the action
# You can add automations in Home Assistant to respond to these button presses
pass