Skip to content

Commit

Permalink
♻️ address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
apmechev committed Oct 30, 2022
1 parent 466236a commit 467042f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion mytoyota/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def set_lock_unlock_vehicle_endpoint(
body={"action": action},
)

async def check_lock_unlock_request_status(
async def get_lock_unlock_request_status(
self, vin: str, request_id: str
) -> dict[str, Any] | None:
"""Check lock/unlock status given a request ID"""
Expand Down
22 changes: 12 additions & 10 deletions mytoyota/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import asyncio
import json
import logging
from typing import Any, List
from typing import Any

import arrow

Expand Down Expand Up @@ -131,7 +131,7 @@ def uuid(self) -> str | None:
"""
return self.api.uuid

async def set_alias(self, vehicle_id: int, new_alias: str) -> dict[str, Any] | None:
async def set_alias(self, vehicle_id: int, new_alias: str) -> dict[str, Any]:
"""Set a new alias for your vehicle.
Sets a new alias for a vehicle specified by its vehicle id.
Expand All @@ -157,7 +157,7 @@ async def set_alias(self, vehicle_id: int, new_alias: str) -> dict[str, Any] | N
vehicle_id=vehicle_id, new_alias=new_alias
)

async def get_vehicles(self) -> List[dict[str, Any]] | None:
async def get_vehicles(self) -> list[dict[str, Any]]:
"""Returns a list of vehicles.
Retrieves list of vehicles associated with the account. The list contains static
Expand Down Expand Up @@ -461,7 +461,7 @@ async def get_driving_statistics_json(
await self.get_driving_statistics(vin, interval, from_date), indent=3
)

async def get_trips(self, vin: str) -> List[Trip]:
async def get_trips(self, vin: str) -> list[Trip]:
"""Returns a list of trips.
Retrieves and formats trips.
Expand Down Expand Up @@ -545,7 +545,7 @@ async def get_trip_json(self, vin: str, trip_id: str) -> str:
trip = await self.get_trip(vin, trip_id)
return json.dumps(trip.raw_json, indent=3)

async def request_lock_vehicle(self, vin: str) -> VehicleLockUnlockActionResponse:
async def set_lock_vehicle(self, vin: str) -> VehicleLockUnlockActionResponse:
"""Sends a lock command to the vehicle.
Args:
Expand All @@ -562,7 +562,7 @@ async def request_lock_vehicle(self, vin: str) -> VehicleLockUnlockActionRespons
response = VehicleLockUnlockActionResponse(raw_response)
return response

async def request_unlock_vehicle(self, vin: str) -> VehicleLockUnlockActionResponse:
async def set_unlock_vehicle(self, vin: str) -> VehicleLockUnlockActionResponse:
"""Send an unlock command to the vehicle.
Args:
Expand All @@ -573,27 +573,29 @@ async def request_unlock_vehicle(self, vin: str) -> VehicleLockUnlockActionRespo
ToyotaInternalError: An error occurred when making a request.
ToyotaApiError: Toyota's API returned an error.
"""
_LOGGER.debug(f"Locking {censor_vin(vin)}...")
_LOGGER.debug(f"Unlocking {censor_vin(vin)}...")
raw_response = await self.api.set_lock_unlock_vehicle_endpoint(vin, "unlock")
_LOGGER.debug(f"Locking {censor_vin(vin)}... {raw_response}")
_LOGGER.debug(f"Unlocking {censor_vin(vin)}... {raw_response}")
response = VehicleLockUnlockActionResponse(raw_response)
return response

async def get_lock_request_status(
async def get_lock_status(
self, vin: str, req_id: str
) -> VehicleLockUnlockStatusResponse:
"""Get the status of a lock request.
Args:
vin (str): Vehicle identification number.
req_id (str): Lock/Unlock request id returned by
set_<lock/unlock>_vehicle (UUID)
Raises:
ToyotaLoginError: An error returned when updating token or invalid login information.
ToyotaInternalError: An error occurred when making a request.
ToyotaApiError: Toyota's API returned an error.
"""
_LOGGER.debug(f"Getting lock request status for {censor_vin(vin)}...")
raw_response = await self.api.check_lock_unlock_request_status(vin, req_id)
raw_response = await self.api.get_lock_unlock_request_status(vin, req_id)
_LOGGER.debug(
f"Getting lock request status for {censor_vin(vin)}... {raw_response}"
)
Expand Down
1 change: 0 additions & 1 deletion mytoyota/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ async def request( # pylint: disable=too-many-branches
if response.status_code in [
HTTPStatus.OK,
HTTPStatus.ACCEPTED,
HTTPStatus.FOUND,
]:
result = response.json()
elif response.status_code == HTTPStatus.NO_CONTENT:
Expand Down
14 changes: 6 additions & 8 deletions mytoyota/models/trip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from __future__ import annotations

from datetime import datetime
from typing import List

from mytoyota.const import TRIP_TIMESTAMP_FORMAT
from mytoyota.models.data import VehicleData


Expand Down Expand Up @@ -46,14 +44,14 @@ class DetailedTrip(VehicleData):
"""Detailed Trip model."""

@property
def trip_events(self) -> List[TripEvent]:
def trip_events(self) -> list(TripEvent):
"""Trip events."""
if not self._data.get("tripEvents"):
return []
return [TripEvent(event) for event in self._data.get("tripEvents", [])]

@property
def trip_events_type(self) -> List[dict]:
def trip_events_type(self) -> list(dict):
"""Trip events type."""
return self._data.get("tripEventsType", [])

Expand All @@ -77,20 +75,20 @@ def start_address(self) -> str:
return self._data.get("startAddress", "")

@property
def start_time_gmt(self) -> datetime | None:
def start_time_gmt(self) -> datetime.datetime | None:
"""Trip Start time GMT."""
start_time_str = self._data.get("startTimeGmt", None)
if not start_time_str:
return None
return datetime.strptime(start_time_str, TRIP_TIMESTAMP_FORMAT)
return datetime.strptime(start_time_str, "%Y-%m-%dT%H:%M:%SZ")

@property
def end_time_gmt(self) -> datetime | None:
def end_time_gmt(self) -> datetime.datetime | None:
"""Trip End time GMT."""
end_time_str = self._data.get("endTimeGmt", None)
if not end_time_str:
return None
return datetime.strptime(end_time_str, TRIP_TIMESTAMP_FORMAT)
return datetime.strptime(end_time_str, "%Y-%m-%dT%H:%M:%SZ")

@property
def end_address(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_lock_unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_send_lock_request(self):
myt = self._create_offline_myt()
vehicle = self._lookup_vehicle(myt, 4444444)
result = asyncio.get_event_loop().run_until_complete(
myt.request_lock_vehicle(vehicle["vin"])
myt.set_lock_vehicle(vehicle["vin"])
)
assert isinstance(result, VehicleLockUnlockActionResponse)
assert result == {
Expand All @@ -34,7 +34,7 @@ def test_send_unlock_request(self):
myt = self._create_offline_myt()
vehicle = self._lookup_vehicle(myt, 4444444)
result = asyncio.get_event_loop().run_until_complete(
myt.request_unlock_vehicle(vehicle["vin"])
myt.set_unlock_vehicle(vehicle["vin"])
)
assert isinstance(result, VehicleLockUnlockActionResponse)
assert result == {
Expand All @@ -48,7 +48,7 @@ def test_get_lock_status(self):
myt = self._create_offline_myt()
vehicle = self._lookup_vehicle(myt, 4444444)
result = asyncio.get_event_loop().run_until_complete(
myt.get_lock_request_status(vehicle["vin"], self.lock_request_id)
myt.get_lock_status(vehicle["vin"], self.lock_request_id)
)
assert isinstance(result, VehicleLockUnlockActionResponse)
assert result == {
Expand Down
3 changes: 2 additions & 1 deletion tests/test_myt.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def _load_from_file(self, filename: str):
with open(filename, encoding="UTF-8") as json_file:
return json.load(json_file)

async def request( # pylint: disable=R0915; # noqa
# Disables pylint warning about too many statements when matching API paths
async def request( # pylint: disable=R0915;
self,
method: str,
endpoint: str,
Expand Down

0 comments on commit 467042f

Please sign in to comment.