Skip to content

Commit

Permalink
tesla.override_vehicles can limit the vehicles available for bot control
Browse files Browse the repository at this point in the history
Closes #42
  • Loading branch information
eras committed Jan 16, 2024
1 parent 09eb728 commit 99f802a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ control = matrix
[tesla]
email = [email protected]

# To constrain the list of available devices in the bot:
# override_vehicles = vehicle1,vehicle2

[matrix]
# Store matrix state in this directory
store_path = matrix_store
Expand Down
10 changes: 8 additions & 2 deletions teslabot/tesla.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from typing import List, Optional, Tuple, Callable, Awaitable, Any, TypeVar, Dict, Union, cast, NewType
from typing import List, Optional, Tuple, Callable, Awaitable, Any, TypeVar, Dict, Union, cast, NewType, Set
import re
import datetime
from configparser import ConfigParser
Expand Down Expand Up @@ -291,6 +291,7 @@ class App(ControlCallback):
location_detail: LocationDetail
cached_vehicle_list: List[Any]
_prev_info: Dict[str, str]
override_vehicles_lc: Set[str] # If empty, query for devices

def __init__(self,
control: Control,
Expand All @@ -301,6 +302,7 @@ def __init__(self,
self.locations = Locations(self.state)
self.location_detail = LocationDetail.Full
self.cached_vehicle_list = []
self.override_vehicles_lc = {x.lower().strip() for x in self.config.get("tesla", "override_vehicles", fallback="").split(",")}
self._prev_info = {}
control.callback = self
cache_loader: Union[Callable[[], Dict[str, Any]], None] = None
Expand Down Expand Up @@ -473,7 +475,11 @@ def call() -> None:

async def _get_vehicle_list(self) -> List[Any]:
def call() -> List[Any]:
self.cached_vehicle_list = self.tesla.vehicle_list()
vehicle_list = self.tesla.vehicle_list()
if self.override_vehicles_lc:
vehicle_list = [vehicle for vehicle in vehicle_list
if vehicle["display_name"].lower() in self.override_vehicles_lc]
self.cached_vehicle_list = vehicle_list
return self.cached_vehicle_list
result_or_error = await self._retry_to_async(call)
if isinstance(result_or_error, Exception):
Expand Down

0 comments on commit 99f802a

Please sign in to comment.