Skip to content

Commit

Permalink
Add initial ServiceHistoryResponseModel
Browse files Browse the repository at this point in the history
  • Loading branch information
CM000n committed Jan 19, 2024
1 parent 2c133e0 commit 38d42df
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mytoyota/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from mytoyota.models.endpoints.electric import ElectricResponseModel
from mytoyota.models.endpoints.location import LocationResponseModel
from mytoyota.models.endpoints.notifications import NotificationResponseModel
from mytoyota.models.endpoints.service_history import ServiceHistoryResponseModel
from mytoyota.models.endpoints.status import RemoteStatusResponseModel
from mytoyota.models.endpoints.telemetry import TelemetryResponseModel
from mytoyota.models.endpoints.trips import TripsResponseModel
Expand Down Expand Up @@ -242,3 +243,22 @@ async def get_trips_endpoint( # noqa: PLR0913
)
_LOGGER.debug(msg=f"Parsed 'TripsResponseModel': {parsed_response}")
return parsed_response

async def get_service_history_endpoint(self, vin: str) -> ServiceHistoryResponseModel:
"""Get the current servic history.
Response includes service category, date and dealer.
Args:
----
vin: str: The vehicles VIN
Returns:
-------
ServicHistoryResponseModel: A pydantic model for the service history response
"""
parsed_response = await self._request_and_parse(

Check warning on line 260 in mytoyota/api.py

View check run for this annotation

Codecov / codecov/patch

mytoyota/api.py#L260

Added line #L260 was not covered by tests
ServiceHistoryResponseModel, "GET", VEHICLE_TELEMETRY_ENDPOINT, vin=vin
)
_LOGGER.debug(msg=f"Parsed 'ServiceHistoryResponseModel': {parsed_response}")
return parsed_response

Check warning on line 264 in mytoyota/api.py

View check run for this annotation

Codecov / codecov/patch

mytoyota/api.py#L263-L264

Added lines #L263 - L264 were not covered by tests
1 change: 1 addition & 0 deletions mytoyota/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
VEHICLE_TELEMETRY_ENDPOINT = "/v3/telemetry"
VEHICLE_NOTIFICATION_HISTORY_ENDPOINT = "/v2/notification/history"
VEHICLE_TRIPS_ENDPOINT = "/v1/trips?from={from_date}&to={to_date}&route={route}&summary={summary}&limit={limit}&offset={offset}" # noqa: E501
VEHICLE_SERVICE_HISTORY_ENDPONT = "/v1/servicehistory/vehicle/summary"

# Timestamps
UNLOCK_TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
66 changes: 66 additions & 0 deletions mytoyota/models/endpoints/service_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Toyota Connected Services API - Service History Models."""

from typing import Any, List, Optional

from pydantic import BaseModel, Field


class ServiceHistoryModel(BaseModel):
"""Represents a service history record.
Attributes
----------
customer_created_record (bool): Indicates if the record was created by the customer.
mileage (Optional[str]): The mileage at the time of the service.
notes (Any): Additional notes about the service.
operations_performed (Any): The operations performed during the service.
ro_number (Any): The RO (Repair Order) number associated with the service.
service_category (str): The category of the service.
service_date (str): The date of the service.
service_history_id (str): The ID of the service history record.
service_provider (str): The service provider.
servicing_dealer (Any): The dealer that performed the service.
unit (Optional[str]): The unit associated with the service mileage.
"""

customer_created_record: bool = Field(alias="customerCreatedRecord")
mileage: Optional[str]
notes: Any
operations_performed: Any = Field(alias="operationsPerformed")
ro_number: Any = Field(alias="roNumber")
service_category: str = Field(alias="customerCreatedRecord")
service_date: str = Field(alias="serviceCategory")
service_history_id: str = Field(alias="serviceHistoryId")
service_provider: str = Field(alias="serviceProvider")
servicing_dealer: Any = Field(alias="servicingDealer")
unit: Optional[str]


class ServiceHistoriesModel(BaseModel):
r"""Model representing a list of service histories.
Attributes
----------
service_histories (List[Optional[ServiceHistoryModel]]): A list of all service histories.
Defaults to [].
"""

service_histories: List[Optional[ServiceHistoryModel]] = Field(
alias="serviceHistories", default=[]
)


class ServiceHistoryResponseModel(BaseModel):
"""Model representing a service history response.
Inherits from BaseModel.
Attributes
----------
payload (Optional[ServiceHistoriesModel]): The service history payload. Defaults to None.
"""

payload: Optional[ServiceHistoriesModel] = None

0 comments on commit 38d42df

Please sign in to comment.