Skip to content

Commit f8ba40c

Browse files
author
JacobAndrewSmith92
authored
feat: Lock Status Method
Lock Status: Add lock_status method to SDK
2 parents 6cd99d6 + c9b9b7d commit f8ba40c

4 files changed

Lines changed: 75 additions & 1 deletion

File tree

smartcar/types.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,31 @@ def format_capabilities(capabilities_list: List[dict]) -> List[Capability]:
266266

267267
Response = NamedTuple("Response", [("body", dict), ("meta", namedtuple)])
268268

269+
# ===========================================
270+
# Lock Status Tuples
271+
# ===========================================
272+
273+
Door = NamedTuple("Door", [("type", str), ("status", str)])
274+
Window = NamedTuple("Window", [("type", str), ("status", str)])
275+
Sunroof = NamedTuple("Sunroof", [("type", str), ("status", str)])
276+
Storage = NamedTuple("Storage", [("type", str), ("status", str)])
277+
ChargingPort = NamedTuple("ChargingPort", [("type", str), ("status", str)])
278+
279+
280+
LockStatus = NamedTuple(
281+
"LockStatus",
282+
[
283+
("is_locked", bool),
284+
("doors", List[Door]),
285+
("windows", List[Window]),
286+
("sunroof", List[Sunroof]),
287+
("storage", List[Storage]),
288+
("charging_port", List[ChargingPort]),
289+
("meta", namedtuple),
290+
],
291+
)
292+
293+
269294
# ===========================================
270295
# Named Tuple Selector Function
271296
# ===========================================
@@ -378,7 +403,16 @@ def select_named_tuple(path: str, response_or_dict) -> NamedTuple:
378403
Paging(data["paging"]["count"], data["paging"]["offset"]),
379404
headers,
380405
)
381-
406+
elif path == "security":
407+
return LockStatus(
408+
data["isLocked"],
409+
data["doors"],
410+
data["windows"],
411+
data["sunroof"],
412+
data["storage"],
413+
data["chargingPort"],
414+
headers,
415+
)
382416
elif path == "subscribe":
383417
return Subscribe(data["webhookId"], data["vehicleId"], headers)
384418

smartcar/vehicle.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,30 @@ def get_charge_limit(self) -> types.ChargeLimit:
264264
response = helpers.requester("GET", url, headers=headers)
265265
return types.select_named_tuple(path, response)
266266

267+
def lock_status(self) -> types.LockStatus:
268+
"""
269+
GET Vehicle.lock_status
270+
271+
Returns:
272+
LockStatus = NamedTuple("LockStatus", [
273+
("is_locked", bool)
274+
("doors", List[Door]),
275+
("windows", List[Window]),
276+
("sunroof", List[Sunroof]),
277+
("storage", List[Storage]),
278+
("charging_port", List[ChargingPort]),
279+
("meta", namedtuple)
280+
]
281+
)
282+
Raises:
283+
SmartcarException
284+
"""
285+
path = "security"
286+
url = self._format_url(path)
287+
headers = self._get_headers()
288+
response = helpers.requester("GET", url, headers=headers)
289+
return types.select_named_tuple(path, response)
290+
267291
# ===========================================
268292
# Action (POST) Requests
269293
# ===========================================

tests/auth_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"read_charge",
3939
"required:read_engine_oil",
4040
"required:read_tires",
41+
"required:read_security",
4142
]
4243

4344

tests/e2e/test_vehicle.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ def test_get_charge_limit(ford_car):
8989
assert charge_limit._fields == ("limit", "meta")
9090

9191

92+
def test_lock_status(chevy_volt):
93+
lock_status = chevy_volt.lock_status()
94+
assert lock_status is not None
95+
assert type(lock_status) == types.LockStatus
96+
assert lock_status._fields == (
97+
"is_locked",
98+
"doors",
99+
"windows",
100+
"sunroof",
101+
"storage",
102+
"charging_port",
103+
"meta",
104+
)
105+
106+
92107
def test_lock(chevy_volt):
93108
response = chevy_volt.lock()
94109
assert response.status == "success"

0 commit comments

Comments
 (0)