Skip to content

Commit

Permalink
Added support for Night Latch feature of EU firmware version of smart…
Browse files Browse the repository at this point in the history
… lock (#215)
  • Loading branch information
Michal4K committed Aug 17, 2023
1 parent 2db1006 commit 7a292cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions switchbot/adv_parsers/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ def process_wolock(data: bytes | None, mfr_data: bytes | None) -> dict[str, bool
"unclosed_alarm": bool(mfr_data[8] & 0b00100000),
"unlocked_alarm": bool(mfr_data[8] & 0b00010000),
"auto_lock_paused": bool(mfr_data[8] & 0b00000010),
"night_latch": bool(mfr_data[9] & 0b00000001),
}
13 changes: 12 additions & 1 deletion switchbot/devices/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
COMMAND_GET_CK_IV = f"{COMMAND_HEADER}0f2103"
COMMAND_LOCK_INFO = f"{COMMAND_HEADER}0f4f8101"
COMMAND_UNLOCK = f"{COMMAND_HEADER}0f4e01011080"
COMMAND_UNLOCK_WITHOUT_UNLATCH = f"{COMMAND_HEADER}0f4e010110a0"
COMMAND_LOCK = f"{COMMAND_HEADER}0f4e01011000"
COMMAND_ENABLE_NOTIFICATIONS = f"{COMMAND_HEADER}0e01001e00008101"
COMMAND_DISABLE_NOTIFICATIONS = f"{COMMAND_HEADER}0e00"
Expand Down Expand Up @@ -164,11 +165,17 @@ async def lock(self) -> bool:
)

async def unlock(self) -> bool:
"""Send unlock command."""
"""Send unlock command. If unlatch feature is enabled in EU firmware, also unlatches door"""
return await self._lock_unlock(
COMMAND_UNLOCK, {LockStatus.UNLOCKED, LockStatus.UNLOCKING}
)

async def unlock_without_unlatch(self) -> bool:
"""Send unlock command. This command will not unlatch the door."""
return await self._lock_unlock(
COMMAND_UNLOCK_WITHOUT_UNLATCH, {LockStatus.UNLOCKED, LockStatus.UNLOCKING, LockStatus.NOT_FULLY_LOCKED}
)

def _parse_basic_data(self, basic_data: bytes) -> dict[str, Any]:
"""Parse basic data from lock."""
return {
Expand Down Expand Up @@ -239,6 +246,10 @@ def is_auto_lock_paused(self) -> bool:
"""Return True if auto lock is paused."""
return self._get_adv_value("auto_lock_paused")

def is_night_latch_enabled(self) -> bool:
"""Return True if Night Latch is enabled on EU firmware."""
return self._get_adv_value("night_latch")

async def _get_lock_info(self) -> bytes | None:
"""Return lock info of device."""
_data = await self._send_command(key=COMMAND_LOCK_INFO, retry=self._retry_count)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_adv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@ def test_parsing_lock_active():
"calibration": True,
"door_open": False,
"double_lock_mode": False,
"night_latch": False,
"status": LockStatus.LOCKED,
"unclosed_alarm": False,
"unlocked_alarm": False,
Expand Down Expand Up @@ -1267,6 +1268,7 @@ def test_parsing_lock_passive():
"calibration": True,
"door_open": False,
"double_lock_mode": False,
"night_latch": False,
"status": LockStatus.LOCKED,
"unclosed_alarm": False,
"unlocked_alarm": False,
Expand Down

0 comments on commit 7a292cb

Please sign in to comment.