From 20bc582a9a0353bfcd1a804d44d2dff3975b9ae5 Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Sun, 7 Jan 2024 07:55:57 +1000 Subject: [PATCH] Finish Teslemetry implementation --- tesla_fleet_api/TeslaFleetApi.py | 1 + tesla_fleet_api/Teslemetry.py | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tesla_fleet_api/TeslaFleetApi.py b/tesla_fleet_api/TeslaFleetApi.py index a3a0582..49fc08b 100644 --- a/tesla_fleet_api/TeslaFleetApi.py +++ b/tesla_fleet_api/TeslaFleetApi.py @@ -204,6 +204,7 @@ class Vehicle: """Class describing the Tesla Fleet API vehicle endpoints and commands.""" def __init__(self, parent): + self._parent = parent self._request = parent._request self.use_command_protocol = parent.use_command_protocol diff --git a/tesla_fleet_api/Teslemetry.py b/tesla_fleet_api/Teslemetry.py index 2fa6a71..edb008b 100644 --- a/tesla_fleet_api/Teslemetry.py +++ b/tesla_fleet_api/Teslemetry.py @@ -1,5 +1,6 @@ import aiohttp from .TeslaFleetApi import TeslaFleetApi +from .const import Methods class Teslemetry(TeslaFleetApi): @@ -18,12 +19,11 @@ def __init__( raise_for_status=raise_for_status, ) - async def subscriptions(self): - """Get the subscriptions.""" - raise NotImplementedError("Not implemented yet") - return await self.get( - "/meta/subscriptions", - {"headers": {"Authorization": f"Bearer {self.access_token}"}}, + async def vehicles(self): + """Get the subscribed vehicles.""" + return await self._request( + Methods.GET, + "/meta/vehicles", ) async def find_server(self): @@ -38,8 +38,11 @@ class Vehicle(TeslaFleetApi.Vehicle): """Tesla Fleet API Vehicle.""" async def create( - self, only_subscribed=False + self, only_subscribed=True ) -> [TeslaFleetApi.Vehicle.Specific]: """Creates a class for each vehicle.""" - list = await self.list() - return [self.Specific(self, x["vin"]) for x in list["response"]] + if only_subscribed: + return [ + self.Specific(self, vin) for vin in await self._parent.vehicles() + ] + return await super().create()