1 """Button platform for Tesla Fleet 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 TeslaFleetConfigEntry
16 from .entity
import TeslaFleetVehicleEntity
17 from .helpers
import handle_vehicle_command
18 from .models
import TeslaFleetVehicleData
24 """Do nothing with a positive result."""
25 return {
"response": {
"result":
True}}
28 @dataclass(frozen=True, kw_only=True)
30 """Describes a TeslaFleet Button entity."""
32 func: Callable[[TeslaFleetButtonEntity], Awaitable[Any]]
35 DESCRIPTIONS: tuple[TeslaFleetButtonEntityDescription, ...] = (
40 key=
"flash_lights", func=
lambda self: self.api.flash_lights()
43 key=
"honk", func=
lambda self: self.api.honk_horn()
46 key=
"enable_keyless_driving", func=
lambda self: self.api.remote_start_drive()
49 key=
"boombox", func=
lambda self: self.api.remote_boombox(0)
53 func=
lambda self: self.api.trigger_homelink(
54 lat=self.coordinator.data[
"drive_state_latitude"],
55 lon=self.coordinator.data[
"drive_state_longitude"],
63 entry: TeslaFleetConfigEntry,
64 async_add_entities: AddEntitiesCallback,
66 """Set up the TeslaFleet Button platform from a config entry."""
70 for vehicle
in entry.runtime_data.vehicles
71 for description
in DESCRIPTIONS
72 if Scope.VEHICLE_CMDS
in entry.runtime_data.scopes
77 """Base class for TeslaFleet buttons."""
79 entity_description: TeslaFleetButtonEntityDescription
83 data: TeslaFleetVehicleData,
84 description: TeslaFleetButtonEntityDescription,
86 """Initialize the button."""
88 super().
__init__(data, description.key)
91 """Update the attributes of the entity."""
94 """Press the button."""
95 await self.wake_up_if_asleep()
bool handle_vehicle_command(Awaitable command)