Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API Endpoints: Basics working. Thoughts & Help needed #242

Merged
merged 152 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 149 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
6e7051f
Basics working.
Nov 17, 2023
6d25366
Moved all calls to the Vehicle class.
Nov 18, 2023
c03b794
Got a "setter" working. Alias can now be set.
Nov 20, 2023
b2b6070
Update dependencies
Nov 20, 2023
fadb8ea
Added /v1/global/remote/status which brings the door/window sensors (…
Nov 20, 2023
91dec31
Added basic trips endpoint using pydantic models. Needs reviewing for…
Nov 22, 2023
898c977
Used python 3.9 compatible Optional[x] instead of 'x | None'
joro75 Nov 25, 2023
afc95a1
fix type hints in logs utils
CM000n Nov 27, 2023
e7a2c16
Run poetry update
CM000n Nov 27, 2023
07be5f9
Merge branch 'master' into master
CM000n Nov 27, 2023
55e72ff
emoves redundancy by combining censor_dict and censor_all into a sing…
CM000n Nov 27, 2023
4139cf5
Merge branch 'master' of github.com:GitOldGrumpy/mytoyota
CM000n Nov 27, 2023
14254c7
emoves redundancy by combining censor_dict and censor_all into a sing…
CM000n Nov 27, 2023
1487d7e
fix type hint
CM000n Nov 27, 2023
7f5283e
fix type hint
CM000n Nov 27, 2023
eeb906e
Fix type hints in api.py
CM000n Nov 27, 2023
3023210
use inline variable that is imidiatley returned with awared timezone …
CM000n Nov 27, 2023
342658c
lift code into else after jump into control flow
CM000n Nov 27, 2023
263af21
adjsut more type hints
CM000n Nov 27, 2023
d5eb289
fiy pylint errors
CM000n Nov 27, 2023
19c0989
add docstrings
CM000n Nov 27, 2023
a79e042
censor also link with vin from output and dump all by default
CM000n Nov 27, 2023
74553e2
adjust models and print trips in _dump_all()
CM000n Nov 27, 2023
5eddd88
add healt_status model
CM000n Nov 27, 2023
7e7384c
cencor vin in HealtStatusModel
CM000n Nov 27, 2023
5730069
use more generic string cencoring
CM000n Nov 27, 2023
830c01c
add location model
CM000n Nov 27, 2023
18d980e
Fix typing for 3.8. Added Account Model.
Nov 27, 2023
5f85029
Merge branch 'master' into master
CM000n Nov 27, 2023
31a0844
Further Updates!
Nov 27, 2023
ff382ae
Merge branch 'master' of github.com:GitOldGrumpy/mytoyota
Nov 27, 2023
4476e6b
Fix typo
Nov 27, 2023
45eff5b
add vscode to gitignore
CM000n Nov 27, 2023
1c0e946
Added/Updated the following endpoints, with basic tests:
Nov 27, 2023
0bfefe7
Merge branch 'master' of github.com:GitOldGrumpy/mytoyota
Nov 27, 2023
6f66503
Merge branch 'master' into master
CM000n Nov 27, 2023
0795c71
WIP. _STILL BROKEN_
Nov 28, 2023
75bd062
fix trips model and adjust payload unpacking
CM000n Nov 28, 2023
982afae
Fix alias names and data types
CM000n Nov 28, 2023
72e3e5e
Adjust StatusModel to inherit from it
CM000n Nov 28, 2023
556a164
Merge remote-tracking branch 'refs/remotes/origin/master'
Nov 28, 2023
da3b1ff
Use car_ prefix to avoid pydantic namespace error
CM000n Nov 28, 2023
26801c4
adjust request type for vehicles endpoint
CM000n Nov 28, 2023
93c87be
adjust request type for notification endpoint
CM000n Nov 28, 2023
d214b36
replace append loop with list extend
CM000n Nov 28, 2023
6672bb0
Adjust how information is received from VehicleGuidModel in Vehicle c…
CM000n Nov 28, 2023
6db3125
Comment out non supported feature from now in simple_client_test.py
CM000n Nov 28, 2023
4f13c6d
fix notifications endpoint model
CM000n Nov 28, 2023
3781f8d
add RemoteStatusResponseModel
CM000n Nov 28, 2023
ad1eb53
add RemoteStatusResponseModel
CM000n Nov 28, 2023
590a582
add telemtry model
CM000n Nov 28, 2023
bc7415f
adjust return type
CM000n Nov 28, 2023
4e5d4b0
Set payload on all Endpoint models to Optional with None as default
CM000n Nov 28, 2023
8f37341
Use UnitValueModel for common Models
CM000n Nov 28, 2023
9e1c269
Update mytoyota/models/endpoints/vehicle_guid.py
CM000n Nov 28, 2023
d0da6a9
add basic test for notification model
CM000n Nov 28, 2023
ae05882
add basic test for telemetry model
CM000n Nov 28, 2023
76319e1
run pre-commit on all files
CM000n Nov 28, 2023
b8ae73b
HDC needs to be optional for fuel only cars. Range not always reporte…
Nov 28, 2023
cac42a7
Add electric status endpoint
Nov 28, 2023
df3c2e2
Model Trips.Route
Nov 28, 2023
1c8cea6
Adjust Notification model name and fix import in tests
CM000n Nov 28, 2023
e65a0eb
adjust request type
CM000n Nov 28, 2023
873365d
remove unused import and use absolute imports
CM000n Nov 28, 2023
84dc2a8
Updated controller.py
Nov 28, 2023
2538f87
Run pre-commit
Nov 29, 2023
9efffcf
Merge branch 'master' of github.com:GitOldGrumpy/mytoyota
Nov 29, 2023
10f2a33
fix str-bytes-safe error
CM000n Nov 29, 2023
b999fc1
add names, phone_numer and email to censor data
CM000n Nov 29, 2023
7bf613d
replace censor_vin with censor_string
CM000n Nov 29, 2023
e90c596
Incompatible types in assignment literal incompatible with URL
CM000n Nov 29, 2023
0630b80
uuid defined outside init
CM000n Nov 29, 2023
c148dd7
Route endpoint no longer always get route. Changed endpoints to take …
Nov 29, 2023
50a75f3
move conftest file to tests folder
CM000n Nov 29, 2023
622da7e
run pre-commit
CM000n Nov 29, 2023
d89c4e3
run pre-commit
CM000n Nov 29, 2023
67e98dd
remove unused retry arguments
CM000n Nov 29, 2023
c8f7c94
abstracting requesting and parsing into own function
CM000n Nov 29, 2023
79dba7f
run pre-commit
CM000n Nov 29, 2023
9d2c408
better error handling in client
CM000n Nov 29, 2023
feace03
replace isort and flake8 with ruff
CM000n Nov 29, 2023
1e8be42
adjust black line-length to ruff and pylint
CM000n Nov 29, 2023
727a7fe
improve readability for endpoint gathering in vehicle model
CM000n Nov 29, 2023
1c33a4e
Add some documentation. Alter defaults on trip endpoint.
Nov 29, 2023
edc4b85
Update trips.py to to make summary optional, it might not be requested.
Nov 29, 2023
f1c172e
Black issues
Nov 29, 2023
fb1c05f
fix katashiki_code obscuring
CM000n Nov 30, 2023
4abb099
increase line-length to 120
CM000n Nov 30, 2023
d9481f5
deactivate pylint TODO warnings
CM000n Nov 30, 2023
9831729
added some docstrings and fix pylint R1705
CM000n Nov 30, 2023
b6a857e
Added some docstrings
CM000n Nov 30, 2023
9080b32
add test_api.py
CM000n Nov 30, 2023
cff061d
replace test_endpoints with test_api
CM000n Nov 30, 2023
c2b170a
Move endpoints to const
CM000n Nov 30, 2023
55f7788
move controller urls to const
CM000n Nov 30, 2023
37b40e4
seperate testing from linting
CM000n Nov 30, 2023
1f2707b
seperate testing from linting
CM000n Nov 30, 2023
ebd30ad
seperate testing from linting
CM000n Nov 30, 2023
9083321
rename simple_client_test file to exclude it from pytest
CM000n Nov 30, 2023
a20dcac
rename simple_client_test file to exclude it from pytest
CM000n Nov 30, 2023
0d56420
fix svar type for status in notifications model
CM000n Nov 30, 2023
ef80f85
adjust linting workflow
CM000n Nov 30, 2023
d23c5e7
adjust linting workflow
CM000n Nov 30, 2023
426a72a
Replace pylint and black with ruff
CM000n Nov 30, 2023
99c9417
use pytest-pretty
CM000n Nov 30, 2023
621b096
ignore error in test
CM000n Nov 30, 2023
e18cf72
If a notification has not be read it doesn't have a notification read…
Nov 30, 2023
50515e7
Added basic Vehicle API for discussion. Updated endpoint models for d…
Dec 1, 2023
392e1a4
enforce more docstring rules
CM000n Dec 1, 2023
d799155
add rule for unused arguments
CM000n Dec 1, 2023
fbaf64f
implement ruff specific rules
CM000n Dec 1, 2023
0a5ff2b
add ruff_cache to gitignore
CM000n Dec 1, 2023
995b22f
install without dev dependencies in build pipeline
CM000n Dec 1, 2023
a5e5c51
Fix small review issues
Dec 1, 2023
b664326
mark old tests as legacy and add some new tests for utils
CM000n Dec 1, 2023
3f589ee
mark old tests as legacy and add some new tests for utils
CM000n Dec 1, 2023
e7ac49f
run coverage only against source files
CM000n Dec 1, 2023
84c2492
run coverage only against source files
CM000n Dec 1, 2023
abb23f8
add simple test for https response formatting
CM000n Dec 3, 2023
6120f3b
Add notifiations to the Client API
Dec 3, 2023
facae29
Merge branch 'master' of github.com:GitOldGrumpy/mytoyota
Dec 3, 2023
36db649
use pprint in example.py
CM000n Dec 4, 2023
611c514
get initial lock status working
CM000n Dec 4, 2023
51cdf9e
fix misbehaviour in bool conversion
CM000n Dec 4, 2023
450503a
poetry update
CM000n Dec 4, 2023
592581d
fix deprecation warning in httpx formatting test
CM000n Dec 4, 2023
0057405
djust use of pytest.param
CM000n Dec 4, 2023
0230e29
Merge branch 'master' into master
CM000n Dec 4, 2023
2118700
recreate lock file
CM000n Dec 4, 2023
1ef3917
add tests for lock_status model
CM000n Dec 4, 2023
89b349c
use caching client
CM000n Dec 7, 2023
3e2056a
replace unsafe characters, according to RFC specification, in AUTHORI…
CM000n Dec 7, 2023
cb84040
If a refresh token exists this will be tried before attempting userna…
Dec 7, 2023
fd2d699
Add username to cache for people who are testing with multiple accounts
Dec 7, 2023
267a0ed
don't use CacheClient on request_raw
CM000n Dec 8, 2023
a835eb3
bump version and update readme
CM000n Dec 11, 2023
34a9e8f
change badge styling
CM000n Dec 11, 2023
fd22353
add coverage badge
CM000n Dec 11, 2023
97ebe31
Added supported for summaries
Dec 12, 2023
5caaf34
Merge branch 'master' of github.com:GitOldGrumpy/mytoyota
Dec 12, 2023
1441380
Fix possible missing Scores
Dec 12, 2023
6b55ddf
Merge branch 'master' into master
CM000n Dec 15, 2023
669fd16
Add Trips
Dec 15, 2023
0e01c54
Merge branch 'master' of github.com:GitOldGrumpy/mytoyota
Dec 15, 2023
48650c2
lint only on pr
CM000n Dec 17, 2023
2e1ff4d
prevent commit to master
CM000n Dec 17, 2023
3369a62
set preferred default to false
CM000n Dec 18, 2023
8583df2
make preferred optional
CM000n Dec 18, 2023
df5e64d
make can_set_next_charging_event optional
CM000n Dec 19, 2023
69e21a3
revert formatting changes
CM000n Dec 20, 2023
9164494
revert workflow changes
CM000n Dec 20, 2023
aca119e
add whitespaces
CM000n Dec 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:
with:
poetry-version: 1.5.1
- name: "⚙️ Install dependencies"
run: "poetry install"
run: "poetry install --without dev"
CM000n marked this conversation as resolved.
Show resolved Hide resolved
- name: "🚀 Test package building"
run: "poetry build"
27 changes: 3 additions & 24 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
name: "Linting"
name: "Lint code"

on:
push:
branches: ["master", "main"]
pull_request:

jobs:
pre-commit:
name: "Pre-commit"
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: "ubuntu-latest"
env:
OS: "ubuntu-latest"
PYTHON: "${{ matrix.python-version }}"
steps:
- name: "⤵️ Check out code from GitHub"
uses: "actions/checkout@v4"
- name: "🐍 Set up Python ${{ matrix.python-version }}"
- name: "🐍 Set up Python"
uses: "actions/setup-python@v5"
with:
python-version: "${{ matrix.python-version }}"
python-version: 3.8
- name: "⚙️ Install Poetry"
uses: "abatilo/actions-poetry@v2.3.0"
with:
Expand All @@ -31,16 +23,3 @@ jobs:
- name: "🚀 Run pre-commit on all files"
run: |
poetry run pre-commit run --all-files --show-diff-on-failure --color=always
- name: "🚀 Run pytest with coverage"
run: |
poetry run pip install coverage
poetry run coverage run -m pytest
poetry run coverage xml
- name: "⬆️ Upload Coverage to Codecov"
uses: "codecov/codecov-action@v3"
with:
token: "${{ secrets.CODECOV_TOKEN }}"
env_vars: OS,PYTHON
fail_ci_if_error: true
flags: "unittests"
verbose: true
46 changes: 46 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "Test code"

env:
COLUMNS: 120

on:
push:
branches: ["master", "main"]
pull_request:

jobs:
pytest:
name: "Pytest"
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: "ubuntu-latest"
env:
OS: "ubuntu-latest"
PYTHON: "${{ matrix.python-version }}"
steps:
- name: "⤵️ Check out code from GitHub"
uses: "actions/checkout@v4"
- name: "🐍 Set up Python ${{ matrix.python-version }}"
uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"
- name: "⚙️ Install Poetry"
uses: "abatilo/actions-poetry@v2.3.0"
with:
poetry-version: 1.5.1
- name: "⚙️ Install dependencies"
run: "poetry install"
- name: "🚀 Run pytest with coverage"
run: |
poetry run pip install coverage
poetry run coverage run --source=mytoyota/ -m pytest
poetry run coverage xml
- name: "⬆️ Upload Coverage to Codecov"
uses: "codecov/codecov-action@v3"
with:
token: "${{ secrets.CODECOV_TOKEN }}"
env_vars: OS,PYTHON
fail_ci_if_error: true
flags: "unittests"
verbose: true
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ dmypy.json
# MS Visual studio
.vs/
TestResults/
.vscode/

# Ruff
.ruff_cache/

.myt_app/
/blahblah.py
.idea/
/credentials.json
43 changes: 15 additions & 28 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,36 @@ repos:
hooks:
- id: check-added-large-files
- id: check-yaml
- id: check-json
- id: check-merge-conflict
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- id: no-commit-to-branch
args: [--branch, master, --branch, main]
- repo: https://github.com/python-poetry/poetry
rev: "1.3"
hooks:
- id: poetry-lock
args: ["--check"]
- repo: local
hooks:
- id: black
name: black
entry: poetry run black
language: system
types: [python]
require_serial: true
- id: isort
name: isort
entry: poetry run isort
language: system
types: [python]
require_serial: true
- id: flake8
name: flake8
entry: poetry run flake8
language: system
types: [python]
- id: pylint
name: pylint
entry: poetry run pylint
language: system
types: [python]
- id: pytest-check
name: pytest-check
entry: pytest
language: system
pass_filenames: false
always_run: true
- id: codespell
name: codespell
entry: poetry run codespell --write-changes --skip="./*"
language: system
pass_filenames: false
always_run: true
- id: ruff format
name: ruff format
entry: poetry run ruff format
language: system
types: [python]
- id: ruff lint
name: ruff lint
entry: poetry run ruff
language: system
types: [python]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
hooks:
Expand Down
106 changes: 56 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
[![GitHub Workflow Status][workflow-shield]][workflow]
[![GitHub Release][releases-shield]][releases]
![Codecov](https://img.shields.io/codecov/c/github/DurgNomis-drol/mytoyota)
CM000n marked this conversation as resolved.
Show resolved Hide resolved
[![GitHub Activity][commits-shield]][commits]
[![GitHub Release][releases-shield]][releases]
![PyPI - Downloads](https://img.shields.io/pypi/dm/mytoyota)

# Toyota Connected Services Europe Python module

### [!] **This is still in beta**
<b><p align=center> 🚨 Breaking changes ahead 🚨 </p></b>

<p align=center> Version 1.0.0 only supports the new ctpa-oneapi API endpoints that were introduced with the new MyToyota app. Some functions are not yet implemented and must first be determined due to the lack of API documentation. </p>
<p align=center> Users of the old MyT app should use a mytoyota python module version < 1.0.0. </p>

### [!] **Only EU is supported, other regions are not possible so far. See [this](https://github.com/widewing/toyota-na) for North America**
⚠️ _This is still in beta_

⚠️ _Only EU is supported, other regions are not possible so far. See [this](https://github.com/widewing/toyota-na) for North America_

## Description

Expand All @@ -24,81 +31,80 @@ pip install mytoyota
## Usage

```python
import json
import asyncio
import json
import pprint

from mytoyota.client import MyT

username = "jane@doe.com"
password = "MyPassword"
brand = "toyota" # or lexus
pp = pprint.PrettyPrinter(indent=4)

# Get supported regions, can be passed to the optional 'region' argument of MyT
# At this moment, only the 'europe' region is supported
print(MyT.get_supported_regions())
# Set your username and password in a file on top level called "credentials.json" in the format:
# {
# "username": "<username>",
# "password": "<password>"
# }

client = MyT(username=username, password=password, brand=brand)

async def get_information():
print("Logging in...")
await client.login()
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

print("Retrieving cars...")
# Returns cars registered to your account + information about each car.
cars = await client.get_vehicles()

for car in cars:
credentials = load_credentials()
if not credentials:
raise ValueError("Did you forget to set your username and password? Or supply the credentials file")

# Returns live data from car/last time you used it as an object.
vehicle = await client.get_vehicle_status(car)
USERNAME = credentials["username"]
PASSWORD = credentials["password"]

# You can either get them all async (Recommended) or sync (Look further down).
data = await asyncio.gather(
*[
client.get_driving_statistics(vehicle.vin, interval="day"),
client.get_driving_statistics(vehicle.vin, interval="isoweek"),
client.get_driving_statistics(vehicle.vin),
client.get_driving_statistics(vehicle.vin, interval="year"),
]
)
client = MyT(username=USERNAME, password=PASSWORD)

# You can access odometer data like this:
mileage = vehicle.dashboard.odometer
# Or retrieve the energy level (electric or gasoline)
fuel = vehicle.dashboard.fuel_level
battery = vehicle.dashboard.battery_level
# Or Parking information:
latitude = vehicle.parkinglocation.latitude

# Daily stats
daily_stats = await client.get_driving_statistics(vehicle.vin, interval="day")
async def get_information():
"""Test login and output from endpoints."""
print("Logging in...")
await client.login()

# ISO 8601 week stats
iso_weekly_stats = await client.get_driving_statistics(vehicle.vin, interval="isoweek")
print("Retrieving cars...")
cars = await client.get_vehicles(metric=False)

for car in cars:
await car.update()

# Monthly stats is returned by default
monthly_stats = await client.get_driving_statistics(vehicle.vin)
# 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]}")

# Get year to date stats.
yearly_stats = await client.get_driving_statistics(vehicle.vin, interval="year")
# Dump all the information collected so far:
# pp.pprint(car._dump_all()) # pylint: disable=W0212


loop = asyncio.get_event_loop()
loop.run_until_complete(get_information())
loop.close()

```

## Known issues

- Statistical endpoint will return `None` if no trip have been performed in the requested timeframe. This problem will often happen at the start of each week, month or year. Also daily stats will of course also be unavailable if no trip have been performed.
- tbd

## Docs

Coming soon...

## Contributing

This python module uses poetry (>= 1.2.2) and pre-commit.
This python module uses poetry (>= 1.5.1) and pre-commit.

To start contributing, fork this repository and run `poetry install`. Then create a new branch. Before making a PR, please run pre-commit `poetry run pre-commit run --all-files` and make sure that all tests passes locally first.

Expand All @@ -110,9 +116,9 @@ As I [@DurgNomis-drol](https://github.com/DurgNomis-drol) am not a professional

A huge thanks go to [@calmjm](https://github.com/calmjm) for making [tojota](https://github.com/calmjm/tojota).

[releases-shield]: https://img.shields.io/github/release/DurgNomis-drol/mytoyota.svg?style=for-the-badge
[releases-shield]: https://img.shields.io/github/release/DurgNomis-drol/mytoyota.svg?style=flat
[releases]: https://github.com/DurgNomis-drol/mytoyota/releases
[workflow-shield]: https://img.shields.io/github/actions/workflow/status/DurgNomis-drol/mytoyota/build.yml?branch=master&style=for-the-badge
[workflow-shield]: https://img.shields.io/github/actions/workflow/status/DurgNomis-drol/mytoyota/build.yml?branch=master&style=flat
[workflow]: https://github.com/DurgNomis-drol/mytoyota/actions
[commits-shield]: https://img.shields.io/github/commit-activity/y/DurgNomis-drol/mytoyota.svg?style=for-the-badge
[commits-shield]: https://img.shields.io/github/commit-activity/y/DurgNomis-drol/mytoyota.svg?style=flat
[commits]: https://github.com/DurgNomis-drol/mytoyota/commits/master
2 changes: 1 addition & 1 deletion mytoyota/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Toyota Connected Services Client"""
"""Toyota Connected Services Client."""
from .client import MyT # pylint: disable=unused-import # NOQA

try:
Expand Down
Loading