1 """Button platform for Teslemetry integration."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
9 from tesla_fleet_api.const
import Scope
15 from .
import TeslemetryConfigEntry
16 from .entity
import TeslemetryVehicleEntity
17 from .helpers
import handle_vehicle_command
18 from .models
import TeslemetryVehicleData
23 @dataclass(frozen=True, kw_only=True)
25 """Describes a Teslemetry Button entity."""
27 func: Callable[[TeslemetryButtonEntity], Awaitable[Any]] |
None =
None
30 DESCRIPTIONS: tuple[TeslemetryButtonEntityDescription, ...] = (
33 key=
"flash_lights", func=
lambda self: self.api.flash_lights()
36 key=
"honk", func=
lambda self: self.api.honk_horn()
39 key=
"enable_keyless_driving", func=
lambda self: self.api.remote_start_drive()
42 key=
"boombox", func=
lambda self: self.api.remote_boombox(0)
46 func=
lambda self: self.api.trigger_homelink(
47 lat=self.coordinator.data[
"drive_state_latitude"],
48 lon=self.coordinator.data[
"drive_state_longitude"],
56 entry: TeslemetryConfigEntry,
57 async_add_entities: AddEntitiesCallback,
59 """Set up the Teslemetry Button platform from a config entry."""
63 for vehicle
in entry.runtime_data.vehicles
64 for description
in DESCRIPTIONS
65 if Scope.VEHICLE_CMDS
in entry.runtime_data.scopes
70 """Base class for Teslemetry buttons."""
72 entity_description: TeslemetryButtonEntityDescription
76 data: TeslemetryVehicleData,
77 description: TeslemetryButtonEntityDescription,
79 """Initialize the button."""
81 super().
__init__(data, description.key)
84 """Update the attributes of the entity."""
87 """Press the button."""
88 await self.wake_up_if_asleep()
89 if self.entity_description.func:
bool handle_vehicle_command(Awaitable command)