-
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.
add lock/unlock requests and lock request status endpoints
- Loading branch information
Showing
10 changed files
with
243 additions
and
12 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
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,53 @@ | ||
""" models for vehicle lock/unlock requests and responses """ | ||
from datetime import datetime | ||
|
||
from mytoyota.const import UNLOCK_TIMESTAMP_FORMAT | ||
|
||
from .data import VehicleData | ||
|
||
|
||
class VehicleLockUnlockActionResponse(VehicleData): | ||
"""Model of the response to a Vehicle Lock/Unlock Action Request.""" | ||
|
||
@property | ||
def status(self) -> str: | ||
"""Request Status.""" | ||
return self._data.get("status", "") | ||
|
||
@property | ||
def request_id(self) -> str: | ||
"""Request ID.""" | ||
return self._data.get("id", "") | ||
|
||
@property | ||
def type(self) -> str: | ||
"""Request Type.""" | ||
return self._data.get("type", "") | ||
|
||
|
||
class VehicleLockUnlockStatusResponse(VehicleData): | ||
"""Model of the response to a the request of the status of | ||
a Vehicle Lock/Unlock action.""" | ||
|
||
@property | ||
def status(self) -> str: | ||
"""Request Status.""" | ||
return self._data.get("status", "") | ||
|
||
@property | ||
def request_id(self) -> str: | ||
"""Request ID.""" | ||
return self._data.get("id", "") | ||
|
||
@property | ||
def type(self) -> str: | ||
"""Request Type.""" | ||
return self._data.get("type", "") | ||
|
||
@property | ||
def request_timestamp(self) -> datetime: | ||
"""Request Timestamp.""" | ||
raw_datetime = self._data.get("requestTimestamp") | ||
if not raw_datetime: | ||
return None | ||
return datetime.strptime(raw_datetime, UNLOCK_TIMESTAMP_FORMAT) |
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,5 @@ | ||
{ | ||
"id": "d4f873d2-5da2-494f-a6d9-6e56d18d2ce9", | ||
"status": "inprogress", | ||
"type": "controlLock" | ||
} |
6 changes: 6 additions & 0 deletions
6
...a/vehicle_JTMW1234565432109_lock_request_status_d4f873d2-5da2-494f-a6d9-6e56d18d2ce9.json
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,6 @@ | ||
{ | ||
"id": "d4f873d2-5da2-494f-a6d9-6e56d18d2ce9", | ||
"status": "completed", | ||
"requestTimestamp": "2022-10-22T08:49:20.071Z", | ||
"type": "controlLock" | ||
} |
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,56 @@ | ||
"""pytest tests for mytoyota.client.MyT sending lock/unlock requests""" | ||
import asyncio | ||
|
||
from mytoyota.models.lock_unlock import VehicleLockUnlockActionResponse | ||
from tests.test_myt import TestMyTHelper | ||
|
||
|
||
class TestLockUnlock(TestMyTHelper): | ||
"""Pytest functions to test locking and unlocking""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.lock_request_id = "d4f873d2-5da2-494f-a6d9-6e56d18d2ce9" | ||
|
||
def test_send_lock_request(self): | ||
"""Test sending the lock request""" | ||
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"]) | ||
) | ||
assert isinstance(result, VehicleLockUnlockActionResponse) | ||
assert result == { | ||
"id": self.lock_request_id, | ||
"status": "inprogress", | ||
"type": "controlLock", | ||
} | ||
|
||
def test_send_unlock_request(self): | ||
"""Test sending the unlock request""" | ||
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"]) | ||
) | ||
assert isinstance(result, VehicleLockUnlockActionResponse) | ||
assert result == { | ||
"id": self.lock_request_id, | ||
"status": "inprogress", | ||
"type": "controlLock", | ||
} | ||
|
||
def test_get_lock_status(self): | ||
"""Test getting the lock status""" | ||
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) | ||
) | ||
assert isinstance(result, VehicleLockUnlockActionResponse) | ||
assert result == { | ||
"id": self.lock_request_id, | ||
"status": "completed", | ||
"requestTimestamp": "2022-10-22T08:49:20.071Z", | ||
"type": "controlLock", | ||
} |
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