forked from DurgNomis-drol/mytoyota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_client_example.py
87 lines (68 loc) · 2.82 KB
/
simple_client_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""Simple test of new API Changes."""
import asyncio
import json
import pprint
from datetime import date, timedelta
from mytoyota.client import MyT
from mytoyota.models.summary import SummaryType
pp = pprint.PrettyPrinter(indent=4)
# Set your username and password in a file on top level called "credentials.json" in the format:
# {
# "username": "<username>",
# "password": "<password>"
# }
def load_credentials():
"""Load credentials from 'credentials.json'."""
try:
with open("credentials.json", encoding="utf-8") as f:
return json.load(f)
except (FileNotFoundError, json.decoder.JSONDecodeError):
return None
credentials = load_credentials()
if not credentials:
raise ValueError(
"Did you forget to set your username and password? Or supply the credentials file"
)
USERNAME = credentials["username"]
PASSWORD = credentials["password"]
client = MyT(username=USERNAME, password=PASSWORD)
async def get_information():
"""Test login and output from endpoints."""
print("Logging in...")
await client.login()
print("Retrieving cars...")
cars = await client.get_vehicles(metric=True)
for car in cars:
await car.update()
# Dashboard Information
pp.pprint(f"Dashboard: {car.dashboard}")
# Location Information
pp.pprint(f"Location: {car.location}")
# Lock Status
pp.pprint(f"Lock Status: {car.lock_status}")
# Notifications
pp.pprint(f"Notifications: {[[x] for x in car.notifications]}")
# Service history
pp.pprint(f"Latest service: {car.get_latest_service_history()}")
# Summary
# pp.pprint(
# f"Summary: {[[x] for x in await car.get_summary(date.today() - timedelta(days=7), date.today(), summary_type=SummaryType.DAILY)]}" # noqa: E501 # pylint: disable=C0301
# )
# pp.pprint(
# f"Summary: {[[x] for x in await car.get_summary(date.today() - timedelta(days=7 * 4), date.today(), summary_type=SummaryType.WEEKLY)]}" # noqa: E501 # pylint: disable=C0301
# )
pp.pprint(
f"Summary: {[[x] for x in await car.get_summary(date.today() - timedelta(days=6 * 30), date.today(), summary_type=SummaryType.MONTHLY)]}" # noqa: E501
)
# pp.pprint(
# f"Summary: {[[x] for x in await car.get_summary(date.today() - timedelta(days=365), date.today(), summary_type=SummaryType.YEARLY)]}" # noqa: E501 # pylint: disable=C0301
# )
# Trips
# pp.pprint(
# f"Trips: f{await car.get_trips(date.today() - timedelta(days=7), date.today(), full_route=True)}" # noqa: E501
# )
# Dump all the information collected so far:
# pp.pprint(car._dump_all())
loop = asyncio.get_event_loop()
loop.run_until_complete(get_information())
loop.close()