forked from flosoft/TeslaETA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial working implementation
- Loading branch information
Showing
6 changed files
with
116 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
PORT=5051 | ||
DATA_DIR=/data/ | ||
SECRET_KEY=RANDOMLY_GENERATED_HERE | ||
ADMIN_PASSWORD=HTPASS_PASSWORD_FOR_ADMIN_PAGE | ||
BASE_URL=/map | ||
MAPBOX_TOKEN=pk.BLA | ||
|
||
# BACKEND_PROVIDER can be either "teslalogger" or "teslamate" | ||
# For Teslamate, you need to deploy TeslamateAPI, available here : https://github.com/tobiasehlert/teslamateapi | ||
BACKEND_PROVIDER=teslamate | ||
BACKEND_PROVIDER_BASE_URL=http://insert-base-api-here:withport/ | ||
BACKEND_PROVIDER_CAR_ID=1 | ||
|
||
TZ=Europe/Berlin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,20 @@ | ||
from interfaces.backendinterface import IBackendProvider | ||
import requests | ||
|
||
class TeslaloggerBackendProvider(IBackendProvider): | ||
|
||
def latitude(): | ||
pass | ||
|
||
def longitude(): | ||
pass | ||
|
||
def odometer(): | ||
pass | ||
|
||
def is_driving(): | ||
pass | ||
|
||
def is_charging(): | ||
pass | ||
|
||
def get_battery_level(): | ||
pass | ||
|
||
def active_route_destination(): | ||
pass | ||
|
||
def active_route_latitude(): | ||
pass | ||
|
||
def active_route_longitude(): | ||
pass | ||
|
||
def active_route_minutes_to_arrival(): | ||
pass | ||
def refresh_data(self): | ||
data = requests.get(f"{self.base_url}/currentjson/{self.car_id}/").json() | ||
|
||
def active_route_energy_at_arrival(): | ||
pass | ||
self.latitude = data["latitude"] | ||
self.longitude = data["longitude"] | ||
self.odometer = data["odometer"] | ||
self.is_driving = data["driving"] | ||
self.is_charging = data["charging"] | ||
self.battery_level = data["battery_level"] | ||
|
||
self.active_route_latitude = data["active_route_latitude"] | ||
self.active_route_longitude = data["active_route_longitude"] | ||
|
||
self.active_route_destination = data["active_route_destination"] | ||
self.active_route_minutes_to_arrival = data["active_route_minutes_to_arrival"] | ||
self.active_route_energy_at_arrival = data["active_route_energy_at_arrival"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
from interfaces.backendinterface import IBackendProvider | ||
import requests | ||
|
||
class TeslamateBackendProvider(): | ||
pass | ||
class TeslamateBackendProvider(IBackendProvider): | ||
def refresh_data(self): | ||
|
||
data = requests.get(f"{self.base_url}/api/v1/cars/{self.car_id}/status").json()["data"]["status"] | ||
|
||
self.latitude = data["car_geodata"]["latitude"] | ||
self.longitude = data["car_geodata"]["longitude"] | ||
self.odometer = data["odometer"] | ||
self.is_driving = data["driving_details"]["shift_state"] is not "P" | ||
self.is_charging = data["charging_details"]["time_to_full_charge"] > 0 | ||
self.battery_level = data["battery_details"]["battery_level"] | ||
|
||
|
||
self.active_route_latitude = data["driving_details"]["active_route"]["location"]["latitude"] | ||
self.active_route_longitude = data["driving_details"]["active_route"]["location"]["longitude"] | ||
|
||
self.active_route_destination = data["driving_details"]["active_route"]["destination"] | ||
self.active_route_minutes_to_arrival = data["driving_details"]["active_route"]["minutes_to_arrival"] | ||
self.active_route_energy_at_arrival = data["driving_details"]["active_route"]["energy_at_arrival"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,33 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
class IBackendProvider(ABC): | ||
base_url: str = None | ||
car_id: int = None | ||
|
||
latitude: float = None | ||
longitude: float = None | ||
odometer: float = None | ||
is_driving: bool = False | ||
is_charging: bool = False | ||
battery_level: int = 0 | ||
|
||
active_route_destination: str = None | ||
active_route_latitude: float = None | ||
active_route_longitude: float = None | ||
active_route_minutes_to_arrival: float = None | ||
active_route_energy_at_arrival: int = None | ||
|
||
|
||
def __init__(self, base_url, car_id): | ||
self.base_url = base_url | ||
self.car_id = car_id | ||
|
||
print(f"Starting provider. BASE_URL : {base_url}, CAR_ID : {car_id}") | ||
|
||
@abstractmethod | ||
def latitude(): | ||
pass | ||
|
||
@abstractmethod | ||
def longitude(): | ||
pass | ||
|
||
@abstractmethod | ||
def odometer(): | ||
pass | ||
|
||
@abstractmethod | ||
def is_driving(): | ||
pass | ||
|
||
@abstractmethod | ||
def is_charging(): | ||
pass | ||
|
||
@abstractmethod | ||
def get_battery_level(): | ||
pass | ||
|
||
@abstractmethod | ||
def active_route_destination(): | ||
pass | ||
|
||
@abstractmethod | ||
def active_route_latitude(): | ||
pass | ||
|
||
@abstractmethod | ||
def active_route_longitude(): | ||
pass | ||
|
||
@abstractmethod | ||
def active_route_minutes_to_arrival(): | ||
def refresh_data(self): | ||
pass | ||
@abstractmethod | ||
def active_route_energy_at_arrival(): | ||
pass | ||
|
||
@property | ||
def active_route_seconds_to_arrival(self) -> float: | ||
return self.active_route_minutes_to_arrival * 60 |