Remove wake helper from Teslemetry (#143376)

This commit is contained in:
Brett Adams 2025-04-22 19:40:03 +10:00 committed by GitHub
parent 2188603a49
commit 08ae05cc76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 2 additions and 41 deletions

View File

@ -20,7 +20,6 @@ from .coordinator import (
TeslemetryEnergySiteLiveCoordinator,
TeslemetryVehicleDataCoordinator,
)
from .helpers import wake_up_vehicle
from .models import TeslemetryEnergyData, TeslemetryVehicleData
@ -126,10 +125,6 @@ class TeslemetryVehicleEntity(TeslemetryEntity):
"""Return a specific value from coordinator data."""
return self.coordinator.data.get(self.key)
async def wake_up_if_asleep(self) -> None:
"""Wake up the vehicle if its asleep."""
await wake_up_vehicle(self.vehicle)
class TeslemetryEnergyLiveEntity(TeslemetryEntity):
"""Parent class for Teslemetry Energy Site Live entities."""

View File

@ -1,13 +1,12 @@
"""Teslemetry helper functions."""
import asyncio
from typing import Any
from tesla_fleet_api.exceptions import TeslaFleetError
from homeassistant.exceptions import HomeAssistantError
from .const import DOMAIN, LOGGER, TeslemetryState
from .const import DOMAIN, LOGGER
def flatten(data: dict[str, Any], parent: str | None = None) -> dict[str, Any]:
@ -23,34 +22,6 @@ def flatten(data: dict[str, Any], parent: str | None = None) -> dict[str, Any]:
return result
async def wake_up_vehicle(vehicle) -> None:
"""Wake up a vehicle."""
async with vehicle.wakelock:
times = 0
while vehicle.coordinator.data["state"] != TeslemetryState.ONLINE:
try:
if times == 0:
cmd = await vehicle.api.wake_up()
else:
cmd = await vehicle.api.vehicle()
state = cmd["response"]["state"]
except TeslaFleetError as e:
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="wake_up_failed",
translation_placeholders={"message": e.message},
) from e
vehicle.coordinator.data["state"] = state
if state != TeslemetryState.ONLINE:
times += 1
if times >= 4: # Give up after 30 seconds total
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="wake_up_timeout",
)
await asyncio.sleep(times * 5)
async def handle_command(command) -> dict[str, Any]:
"""Handle a command."""
try:

View File

@ -12,7 +12,7 @@ from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.helpers import config_validation as cv, device_registry as dr
from .const import DOMAIN
from .helpers import handle_command, handle_vehicle_command, wake_up_vehicle
from .helpers import handle_command, handle_vehicle_command
from .models import TeslemetryEnergyData, TeslemetryVehicleData
_LOGGER = logging.getLogger(__name__)
@ -107,7 +107,6 @@ def async_register_services(hass: HomeAssistant) -> None:
config = async_get_config_for_device(hass, device)
vehicle = async_get_vehicle_for_entry(hass, device, config)
await wake_up_vehicle(vehicle)
await handle_vehicle_command(
vehicle.api.navigation_gps_request(
lat=call.data[ATTR_GPS][CONF_LATITUDE],
@ -148,7 +147,6 @@ def async_register_services(hass: HomeAssistant) -> None:
translation_domain=DOMAIN, translation_key="set_scheduled_charging_time"
)
await wake_up_vehicle(vehicle)
await handle_vehicle_command(
vehicle.api.set_scheduled_charging(enable=call.data["enable"], time=time)
)
@ -205,7 +203,6 @@ def async_register_services(hass: HomeAssistant) -> None:
translation_key="set_scheduled_departure_off_peak",
)
await wake_up_vehicle(vehicle)
await handle_vehicle_command(
vehicle.api.set_scheduled_departure(
enable,
@ -242,7 +239,6 @@ def async_register_services(hass: HomeAssistant) -> None:
config = async_get_config_for_device(hass, device)
vehicle = async_get_vehicle_for_entry(hass, device, config)
await wake_up_vehicle(vehicle)
await handle_vehicle_command(
vehicle.api.set_valet_mode(
call.data.get("enable"), call.data.get("pin", "")
@ -268,7 +264,6 @@ def async_register_services(hass: HomeAssistant) -> None:
config = async_get_config_for_device(hass, device)
vehicle = async_get_vehicle_for_entry(hass, device, config)
await wake_up_vehicle(vehicle)
enable = call.data.get("enable")
if enable is True:
await handle_vehicle_command(