-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add initial
ServiceHistoryResponseModel
(#312)
* Add initial ServiceHistoryResponseModel
- Loading branch information
Showing
8 changed files
with
354 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""Toyota Connected Services API - Service History Models.""" | ||
|
||
from datetime import date | ||
from typing import Any, List, Optional | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from mytoyota.models.endpoints.common import StatusModel | ||
|
||
|
||
class ServiceHistoryModel(BaseModel): | ||
"""Represents a service history record. | ||
Attributes | ||
---------- | ||
customer_created_record (bool): Indicates if the record was created by the customer. | ||
mileage (Optional[int]): 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 (date): 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[int] = None | ||
notes: Any | ||
operations_performed: Any = Field(alias="operationsPerformed") | ||
ro_number: Any = Field(alias="roNumber") | ||
service_category: str = Field(alias="serviceCategory") | ||
service_date: date = Field(alias="serviceDate") | ||
service_history_id: str = Field(alias="serviceHistoryId") | ||
service_provider: str = Field(alias="serviceProvider") | ||
servicing_dealer: Any = Field(alias="servicingDealer") | ||
unit: Optional[str] = None | ||
|
||
|
||
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(StatusModel): | ||
"""Model representing a service history response. | ||
Inherits from StatusModel. | ||
Attributes | ||
---------- | ||
payload (Optional[ServiceHistoriesModel]): The service history payload. Defaults to None. | ||
""" | ||
|
||
payload: Optional[ServiceHistoriesModel] = None |
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,132 @@ | ||
"""models for vehicle service history.""" | ||
from datetime import date | ||
from typing import Any, Optional | ||
|
||
from mytoyota.models.endpoints.service_history import ServiceHistoryModel | ||
from mytoyota.utils.conversions import convert_distance | ||
|
||
|
||
class ServiceHistory: | ||
"""ServiceHistory.""" | ||
|
||
def __init__( | ||
self, | ||
service_history: ServiceHistoryModel, | ||
metric: bool = True, | ||
): | ||
"""Initialise ServiceHistory.""" | ||
self._service_history = service_history | ||
self._distance_unit: str = "km" if metric else "mi" | ||
|
||
def __repr__(self): | ||
"""Representation of the model.""" | ||
return " ".join( | ||
[ | ||
f"{k}={getattr(self, k)!s}" | ||
for k, v in type(self).__dict__.items() | ||
if isinstance(v, property) | ||
], | ||
) | ||
|
||
@property | ||
def service_date(self) -> date: | ||
"""The date of the service. | ||
Returns | ||
------- | ||
date: The date of the service. | ||
""" | ||
return self._service_history.service_date | ||
|
||
@property | ||
def customer_created_record(self) -> bool: | ||
"""Indication whether it is an entry created by the user. | ||
Returns | ||
------- | ||
str: Category of notification | ||
""" | ||
return self._service_history.customer_created_record | ||
|
||
@property | ||
def odometer(self) -> Optional[float]: | ||
"""Odometer distance at the time of servicing. | ||
Returns | ||
------- | ||
int: Odometer distance at the time of servicing | ||
in the current selected units | ||
""" | ||
if ( | ||
self._service_history is not None | ||
and self._service_history.unit is not None | ||
and self._service_history.mileage is not None | ||
): | ||
return convert_distance( | ||
self._distance_unit, | ||
self._service_history.unit, | ||
self._service_history.mileage, | ||
) | ||
else: | ||
return None | ||
|
||
@property | ||
def notes(self) -> Any: | ||
"""Additional notes about the service. | ||
Returns | ||
------- | ||
Any: Additional notes about the service | ||
""" | ||
return self._service_history.notes | ||
|
||
@property | ||
def operations_performed(self) -> Any: | ||
"""The operations performed during the service. | ||
Returns | ||
------- | ||
Any: The operations performed during the service | ||
""" | ||
return self._service_history.operations_performed | ||
|
||
@property | ||
def ro_number(self) -> Any: | ||
"""The RO (Repair Order) number associated with the service. | ||
Returns | ||
------- | ||
Any: The RO (Repair Order) number associated with the service | ||
""" | ||
return self._service_history.ro_number | ||
|
||
@property | ||
def service_category(self) -> str: | ||
"""The category of the service. | ||
Returns | ||
------- | ||
str: The category of the service. | ||
""" | ||
return self._service_history.service_category | ||
|
||
@property | ||
def service_provider(self) -> str: | ||
"""The service provider. | ||
Returns | ||
------- | ||
str: The service provider | ||
""" | ||
return self._service_history.service_provider | ||
|
||
@property | ||
def servicing_dealer(self) -> Any: | ||
"""Dealer that performed the service. | ||
Returns | ||
------- | ||
Any: The dealer that performed the service | ||
""" | ||
return self._service_history.servicing_dealer |
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
Oops, something went wrong.