Fix buttons in Teslemetry (#136142)

This commit is contained in:
Brett Adams 2025-01-21 17:06:18 +10:00 committed by GitHub
parent a73ab4145a
commit f6b444b24b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,7 +14,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import TeslemetryConfigEntry from . import TeslemetryConfigEntry
from .entity import TeslemetryVehicleEntity from .entity import TeslemetryVehicleEntity
from .helpers import handle_vehicle_command from .helpers import handle_command, handle_vehicle_command
from .models import TeslemetryVehicleData from .models import TeslemetryVehicleData
PARALLEL_UPDATES = 0 PARALLEL_UPDATES = 0
@ -28,24 +28,31 @@ class TeslemetryButtonEntityDescription(ButtonEntityDescription):
DESCRIPTIONS: tuple[TeslemetryButtonEntityDescription, ...] = ( DESCRIPTIONS: tuple[TeslemetryButtonEntityDescription, ...] = (
TeslemetryButtonEntityDescription(key="wake", func=lambda self: self.api.wake_up()),
TeslemetryButtonEntityDescription( TeslemetryButtonEntityDescription(
key="flash_lights", func=lambda self: self.api.flash_lights() key="wake", func=lambda self: handle_command(self.api.wake_up())
), ),
TeslemetryButtonEntityDescription( TeslemetryButtonEntityDescription(
key="honk", func=lambda self: self.api.honk_horn() key="flash_lights",
func=lambda self: handle_vehicle_command(self.api.flash_lights()),
), ),
TeslemetryButtonEntityDescription( TeslemetryButtonEntityDescription(
key="enable_keyless_driving", func=lambda self: self.api.remote_start_drive() key="honk", func=lambda self: handle_vehicle_command(self.api.honk_horn())
), ),
TeslemetryButtonEntityDescription( TeslemetryButtonEntityDescription(
key="boombox", func=lambda self: self.api.remote_boombox(0) key="enable_keyless_driving",
func=lambda self: handle_vehicle_command(self.api.remote_start_drive()),
),
TeslemetryButtonEntityDescription(
key="boombox",
func=lambda self: handle_vehicle_command(self.api.remote_boombox(0)),
), ),
TeslemetryButtonEntityDescription( TeslemetryButtonEntityDescription(
key="homelink", key="homelink",
func=lambda self: self.api.trigger_homelink( func=lambda self: handle_vehicle_command(
self.api.trigger_homelink(
lat=self.coordinator.data["drive_state_latitude"], lat=self.coordinator.data["drive_state_latitude"],
lon=self.coordinator.data["drive_state_longitude"], lon=self.coordinator.data["drive_state_longitude"],
)
), ),
), ),
) )
@ -85,4 +92,4 @@ class TeslemetryButtonEntity(TeslemetryVehicleEntity, ButtonEntity):
async def async_press(self) -> None: async def async_press(self) -> None:
"""Press the button.""" """Press the button."""
await handle_vehicle_command(self.entity_description.func(self)) await self.entity_description.func(self)