Skip to content

Commit

Permalink
Merge pull request #102 from dknowles2/connected
Browse files Browse the repository at this point in the history
Assume lock is not connected if missing from JSON
  • Loading branch information
dknowles2 committed Oct 30, 2023
2 parents 17a507e + 1b01ce7 commit 9dcfd49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyschlage/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def from_json(cls, auth: Auth, json: dict) -> Lock:
name=json["name"],
model_name=json["modelName"],
device_type=json["devicetypeId"],
connected=json["connected"],
connected=json.get("connected", False),
battery_level=attributes.get("batteryLevel"),
is_locked=is_locked,
is_jammed=is_jammed,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

from copy import deepcopy
from datetime import datetime
from typing import Any
from unittest import mock

import pytest
Expand Down Expand Up @@ -33,6 +36,13 @@ def test_from_json(self, mock_auth, lock_json):
"foo-bar-uuid": User("Foo Bar", "foo@bar.xyz", "foo-bar-uuid"),
}

def test_from_json_no_connected(
self, mock_auth: mock.Mock, lock_json: dict[Any, Any]
) -> None:
lock_json.pop("connected")
lock = Lock.from_json(mock_auth, lock_json)
assert not lock.connected

def test_from_json_is_jammed(self, mock_auth, lock_json):
lock_json["attributes"]["lockState"] = 2
lock = Lock.from_json(mock_auth, lock_json)
Expand Down

0 comments on commit 9dcfd49

Please sign in to comment.