Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adv_parser for Switchbot Lock Pro #243

Merged
merged 9 commits into from
Jul 11, 2024
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
Loading