Skip to content

Commit

Permalink
Fix adv_parser for Switchbot Lock Pro (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
szclsya authored Jul 11, 2024
1 parent 4fffc63 commit 40f58c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions switchbot/adv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .adv_parsers.hub2 import process_wohub2
from .adv_parsers.humidifier import process_wohumidifier
from .adv_parsers.light_strip import process_wostrip
from .adv_parsers.lock import process_wolock
from .adv_parsers.lock import process_wolock, process_wolock_pro
from .adv_parsers.meter import process_wosensorth
from .adv_parsers.motion import process_wopresence
from .adv_parsers.plug import process_woplugmini
Expand Down Expand Up @@ -153,7 +153,7 @@ class SwitchbotSupportedType(TypedDict):
"$": {
"modelName": SwitchbotModel.LOCK_PRO,
"modelFriendlyName": "Lock Pro",
"func": process_wolock,
"func": process_wolock_pro,
"manufacturer_id": 2409,
},
"x": {
Expand Down
24 changes: 24 additions & 0 deletions switchbot/adv_parsers/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,27 @@ def process_wolock(data: bytes | None, mfr_data: bytes | None) -> dict[str, bool
"auto_lock_paused": bool(mfr_data[8] & 0b00000010),
"night_latch": bool(mfr_data[9] & 0b00000001) if len(mfr_data) > 9 else False,
}


def process_wolock_pro(
data: bytes | None, mfr_data: bytes | None
) -> dict[str, bool | int]:
_LOGGER.debug("mfr_data: %s", mfr_data.hex())
if data:
_LOGGER.debug("data: %s", data.hex())

res = {
"battery": data[2] & 0b01111111 if data else None,
"calibration": bool(mfr_data[7] & 0b10000000),
"status": LockStatus((mfr_data[7] & 0b00111000) >> 3),
"door_open": bool(mfr_data[8] & 0b01100000),
# Double lock mode is not supported on Lock Pro
"update_from_secondary_lock": False,
"double_lock_mode": False,
"unclosed_alarm": bool(mfr_data[11] & 0b10000000),
"unlocked_alarm": bool(mfr_data[11] & 0b01000000),
"auto_lock_paused": bool(mfr_data[8] & 0b100000),
"night_latch": bool(mfr_data[9] & 0b00000001),
}
_LOGGER.debug(res)
return res

0 comments on commit 40f58c3

Please sign in to comment.