2023-12-22 02:40:55 +00:00
|
|
|
"""Button platform for Tessie integration."""
|
2024-03-08 15:35:23 +00:00
|
|
|
|
2023-12-22 02:40:55 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from collections.abc import Callable
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
from tessie_api import (
|
|
|
|
boombox,
|
|
|
|
enable_keyless_driving,
|
|
|
|
flash_lights,
|
|
|
|
honk,
|
|
|
|
trigger_homelink,
|
|
|
|
wake,
|
|
|
|
)
|
|
|
|
|
|
|
|
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
|
2024-05-28 07:05:24 +00:00
|
|
|
from . import TessieConfigEntry
|
2023-12-22 02:40:55 +00:00
|
|
|
from .entity import TessieEntity
|
2024-06-26 09:46:30 +00:00
|
|
|
from .models import TessieVehicleData
|
2023-12-22 02:40:55 +00:00
|
|
|
|
2024-07-18 07:38:26 +00:00
|
|
|
PARALLEL_UPDATES = 0
|
|
|
|
|
2023-12-22 02:40:55 +00:00
|
|
|
|
|
|
|
@dataclass(frozen=True, kw_only=True)
|
|
|
|
class TessieButtonEntityDescription(ButtonEntityDescription):
|
|
|
|
"""Describes a Tessie Button entity."""
|
|
|
|
|
|
|
|
func: Callable
|
|
|
|
|
|
|
|
|
|
|
|
DESCRIPTIONS: tuple[TessieButtonEntityDescription, ...] = (
|
2024-02-21 18:49:04 +00:00
|
|
|
TessieButtonEntityDescription(key="wake", func=lambda: wake),
|
|
|
|
TessieButtonEntityDescription(key="flash_lights", func=lambda: flash_lights),
|
|
|
|
TessieButtonEntityDescription(key="honk", func=lambda: honk),
|
2023-12-22 02:40:55 +00:00
|
|
|
TessieButtonEntityDescription(
|
2024-02-21 18:49:04 +00:00
|
|
|
key="trigger_homelink", func=lambda: trigger_homelink
|
2023-12-22 02:40:55 +00:00
|
|
|
),
|
|
|
|
TessieButtonEntityDescription(
|
2023-12-23 12:45:06 +00:00
|
|
|
key="enable_keyless_driving",
|
|
|
|
func=lambda: enable_keyless_driving,
|
|
|
|
),
|
2024-02-21 18:49:04 +00:00
|
|
|
TessieButtonEntityDescription(key="boombox", func=lambda: boombox),
|
2023-12-22 02:40:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
2024-05-28 07:05:24 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: TessieConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
2023-12-22 02:40:55 +00:00
|
|
|
) -> None:
|
|
|
|
"""Set up the Tessie Button platform from a config entry."""
|
2024-05-28 07:05:24 +00:00
|
|
|
data = entry.runtime_data
|
2023-12-22 02:40:55 +00:00
|
|
|
|
|
|
|
async_add_entities(
|
2024-05-28 07:05:24 +00:00
|
|
|
TessieButtonEntity(vehicle, description)
|
|
|
|
for vehicle in data.vehicles
|
2023-12-22 02:40:55 +00:00
|
|
|
for description in DESCRIPTIONS
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TessieButtonEntity(TessieEntity, ButtonEntity):
|
|
|
|
"""Base class for Tessie Buttons."""
|
|
|
|
|
|
|
|
entity_description: TessieButtonEntityDescription
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
2024-06-26 09:46:30 +00:00
|
|
|
vehicle: TessieVehicleData,
|
2023-12-22 02:40:55 +00:00
|
|
|
description: TessieButtonEntityDescription,
|
|
|
|
) -> None:
|
|
|
|
"""Initialize the Button."""
|
2024-06-26 09:46:30 +00:00
|
|
|
super().__init__(vehicle, description.key)
|
2023-12-22 02:40:55 +00:00
|
|
|
self.entity_description = description
|
|
|
|
|
|
|
|
async def async_press(self) -> None:
|
|
|
|
"""Press the button."""
|
2023-12-23 12:45:06 +00:00
|
|
|
await self.run(self.entity_description.func())
|