Skip to content

Commit

Permalink
Merge pull request #207 from dknowles2/changed-by
Browse files Browse the repository at this point in the history
Teach last_changed_by about 1-touch locking
  • Loading branch information
dknowles2 authored Nov 25, 2024
2 parents 8b71968 + 067e813 commit b1c0ef9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
32 changes: 15 additions & 17 deletions pyschlage/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,22 @@ def last_changed_by(
if self.lock_state_metadata is None:
return None

if self.lock_state_metadata.action_type == "thumbTurn":
return "thumbturn"

user_suffix = ""
uuid = self.lock_state_metadata.uuid

if self.lock_state_metadata.action_type == "AppleHomeNFC":
if uuid is not None and (user := self.users.get(uuid)):
return f"apple nfc device - {user.name}"
return "apple nfc device"

if self.lock_state_metadata.action_type == "accesscode":
return f"keypad - {self.lock_state_metadata.name}"

if self.lock_state_metadata.action_type == "virtualKey":
if uuid is not None and (user := self.users.get(uuid)):
return f"mobile device - {user.name}"
return "mobile device"

if uuid is not None and (user := self.users.get(uuid)):
user_suffix = f" - {user.name}"

match self.lock_state_metadata.action_type:
case "thumbTurn":
return "thumbturn"
case "1touchLocking":
return "1-touch locking"
case "accesscode":
return f"keypad - {self.lock_state_metadata.name}"
case "AppleHomeNFC":
return f"apple nfc device{user_suffix}"
case "virtualKey":
return f"mobile device{user_suffix}"
return "unknown"

def keypad_disabled(self, logs: list[LockLog] | None = None) -> bool:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ def test_thumbturn(self, wifi_lock: Lock) -> None:
wifi_lock.lock_state_metadata.action_type = "thumbTurn"
assert wifi_lock.last_changed_by() == "thumbturn"

def test_one_touch_locking(self, wifi_lock: Lock) -> None:
assert wifi_lock.lock_state_metadata is not None
wifi_lock.lock_state_metadata.action_type = "1touchLocking"
assert wifi_lock.last_changed_by() == "1-touch locking"

def test_nfc_device(self, wifi_lock: Lock) -> None:
assert wifi_lock.lock_state_metadata is not None
wifi_lock.lock_state_metadata.action_type = "AppleHomeNFC"
Expand Down

0 comments on commit b1c0ef9

Please sign in to comment.