Skip to content

Commit 44cf359

Browse files
authored
Merge pull request #110 from dknowles2/model-name
Handle model name not being present
2 parents e745209 + 3122154 commit 44cf359

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pyschlage/lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def from_json(cls, auth: Auth, json: dict) -> Lock:
138138
_auth=auth,
139139
device_id=json["deviceId"],
140140
name=json["name"],
141-
model_name=json["modelName"],
141+
model_name=json.get("modelName", ""),
142142
device_type=json["devicetypeId"],
143143
connected=json.get("connected", False),
144144
battery_level=attributes.get("batteryLevel"),

tests/test_lock.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ def test_from_json_wifi_lock_unavailable(
5858
assert lock.is_locked is None
5959
assert lock.is_jammed is None
6060

61+
def test_from_json_no_model_name(
62+
self, mock_auth: mock.Mock, lock_json: dict[Any, Any]
63+
) -> None:
64+
lock_json.pop("modelName", None)
65+
lock = Lock.from_json(mock_auth, lock_json)
66+
assert lock.model_name == ""
67+
6168
def test_diagnostics(self, mock_auth: mock.Mock, lock_json: dict) -> None:
6269
lock = Lock.from_json(mock_auth, lock_json)
6370
want = {

0 commit comments

Comments
 (0)