Skip to content

Commit b1c0ef9

Browse files
authored
Merge pull request #207 from dknowles2/changed-by
Teach last_changed_by about 1-touch locking
2 parents 8b71968 + 067e813 commit b1c0ef9

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

pyschlage/lock.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,22 @@ def last_changed_by(
255255
if self.lock_state_metadata is None:
256256
return None
257257

258-
if self.lock_state_metadata.action_type == "thumbTurn":
259-
return "thumbturn"
260-
258+
user_suffix = ""
261259
uuid = self.lock_state_metadata.uuid
262-
263-
if self.lock_state_metadata.action_type == "AppleHomeNFC":
264-
if uuid is not None and (user := self.users.get(uuid)):
265-
return f"apple nfc device - {user.name}"
266-
return "apple nfc device"
267-
268-
if self.lock_state_metadata.action_type == "accesscode":
269-
return f"keypad - {self.lock_state_metadata.name}"
270-
271-
if self.lock_state_metadata.action_type == "virtualKey":
272-
if uuid is not None and (user := self.users.get(uuid)):
273-
return f"mobile device - {user.name}"
274-
return "mobile device"
275-
260+
if uuid is not None and (user := self.users.get(uuid)):
261+
user_suffix = f" - {user.name}"
262+
263+
match self.lock_state_metadata.action_type:
264+
case "thumbTurn":
265+
return "thumbturn"
266+
case "1touchLocking":
267+
return "1-touch locking"
268+
case "accesscode":
269+
return f"keypad - {self.lock_state_metadata.name}"
270+
case "AppleHomeNFC":
271+
return f"apple nfc device{user_suffix}"
272+
case "virtualKey":
273+
return f"mobile device{user_suffix}"
276274
return "unknown"
277275

278276
def keypad_disabled(self, logs: list[LockLog] | None = None) -> bool:

tests/test_lock.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ def test_thumbturn(self, wifi_lock: Lock) -> None:
458458
wifi_lock.lock_state_metadata.action_type = "thumbTurn"
459459
assert wifi_lock.last_changed_by() == "thumbturn"
460460

461+
def test_one_touch_locking(self, wifi_lock: Lock) -> None:
462+
assert wifi_lock.lock_state_metadata is not None
463+
wifi_lock.lock_state_metadata.action_type = "1touchLocking"
464+
assert wifi_lock.last_changed_by() == "1-touch locking"
465+
461466
def test_nfc_device(self, wifi_lock: Lock) -> None:
462467
assert wifi_lock.lock_state_metadata is not None
463468
wifi_lock.lock_state_metadata.action_type = "AppleHomeNFC"

0 commit comments

Comments
 (0)