1 """Tesla Fleet helper functions."""
4 from collections.abc
import Awaitable
7 from tesla_fleet_api.exceptions
import TeslaFleetError
11 from .const
import DOMAIN, LOGGER, TeslaFleetState
12 from .models
import TeslaFleetVehicleData
16 """Wake up a vehicle."""
17 async
with vehicle.wakelock:
19 while vehicle.coordinator.data[
"state"] != TeslaFleetState.ONLINE:
22 cmd = await vehicle.api.wake_up()
24 cmd = await vehicle.api.vehicle()
25 state = cmd[
"response"][
"state"]
26 except TeslaFleetError
as e:
28 vehicle.coordinator.data[
"state"] = state
29 if state != TeslaFleetState.ONLINE:
33 await asyncio.sleep(times * 5)
37 """Handle a command."""
39 result = await command
40 except TeslaFleetError
as e:
42 translation_domain=DOMAIN,
43 translation_key=
"command_failed",
44 translation_placeholders={
"message": e.message},
46 LOGGER.debug(
"Command result: %s", result)
51 """Handle a vehicle command."""
53 if (response := result.get(
"response"))
is None:
54 if error := result.get(
"error"):
57 translation_domain=DOMAIN,
58 translation_key=
"command_error",
59 translation_placeholders={
"error": error},
63 if (result := response.get(
"result"))
is not True:
64 if reason := response.get(
"reason"):
65 if reason
in (
"already_set",
"not_charging",
"requested"):
70 translation_domain=DOMAIN,
71 translation_key=
"command_reason",
72 translation_placeholders={
"reason": reason},
76 translation_domain=DOMAIN,
77 translation_key=
"command_no_reason",
bool handle_vehicle_command(Awaitable command)
None wake_up_vehicle(TeslaFleetVehicleData vehicle)
dict[str, Any] handle_command(Awaitable command)