Add SwitchbotKeypad device class for classic Keypad#488
Conversation
The classic Keypad (WoKeypad) is a passive BLE-only device paired with SwitchBot Lock. The adv parser already exposes battery and attempt_state from advertisement data. This adds the device class and exports it so integrations can reference it explicitly.
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
@bluetoothbot review |
There was a problem hiding this comment.
Pull request overview
Adds a minimal SwitchbotKeypad device class that wraps the existing process_wokeypad advertisement parser, exposes it from the package's public API, and adds a fixture plus three tests verifying battery and attempt_state parsing.
Changes:
- New
switchbot/devices/keypad.pydefiningSwitchbotKeypad(subclass ofSwitchbotDevice, no commands). - Public export added in
switchbot/__init__.py(SwitchbotKeypad). - New
KEYPAD_INFOAdvTestCasefixture intests/__init__.pyand a newtests/test_keypad.pyexercising advertisement parsing.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| switchbot/devices/keypad.py | Adds the new passive SwitchbotKeypad device class. |
| switchbot/init.py | Imports and re-exports SwitchbotKeypad in the public API. |
| tests/init.py | Adds KEYPAD_INFO advertisement fixture used by the new tests. |
| tests/test_keypad.py | Adds tests verifying parsed battery and attempt_state values, including battery=None override. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Review — Add SwitchbotKeypad device class for classic KeypadSmall, well-scoped change that fills a real gap: the 🟢 Suggestions1. Repeated setup could be pulled into a fixture or parametrize (`tests/test_keypad.py`, L9-58)All three tests duplicate the BLE device + advertisement construction. With three short tests it is acceptable as-is, but extracting a small helper or using Not a blocker — the duplication is bounded and the intent is clear. 2. Consider also asserting attempt_state is None in the empty-mfr-data case (`tests/test_keypad.py`, L42-58)
3. Optional: reference SwitchbotModel.KEYPAD in the docstring (`switchbot/devices/keypad.py`, L7-14)The class body is intentionally empty (correct for a passive BLE device). To help discoverability — especially relative to the very similarly named Checklist
SummarySmall, well-scoped change that fills a real gap: the Automated review by Kōan570b216 |
Tests previously injected pre-parsed values, bypassing the parser. Now exercises parse_advertisement_data end-to-end so byte-layout regressions in adv_parsers/keypad.py are caught. - Assert get_battery_percent() instead of raw dict access - None test exercises parser's own None branch (empty mfr_data) - Extract make_advertisement_data to tests/__init__.py; remove duplicate in test_keypad_vision.py - Expand SwitchbotKeypad docstring: passive-only, no commands
|
Addressed all suggestions from the automated review:
|
|
@bluetoothbot review |
|
❌ Permission denied. Only users with write access can trigger bot commands. |
File was not in scope for this PR. Revert changes to it and remove the shared make_advertisement_data helper from tests/__init__.py that was added only to support that refactor.
|
@bluetoothbot review |
Completes coverage of the None-handling branch in process_wokeypad: both battery and attempt_state are None when manufacturer data absent.
AI-generated PR to support Switchbot Keypad and mainly expose battery levels
https://eu.switch-bot.com/products/switchbot-keypad
The code was not tested, but it would be great to get some help/feedback from you. Thanks
Description:
Summary
The classic SwitchBot Keypad (WoKeypad) is a passive BLE-only device
used to unlock doors paired with SwitchBot Lock. The advertisement
parser (
adv_parsers/keypad.py) already parsesbatteryandattempt_statefrom BLE advertisements, andSwitchbotModel.KEYPADis already defined, but no device class existed.
Changes
SwitchbotKeypaddevice class indevices/keypad.py, extendingSwitchbotDevice(passive-only, no BLE commands)SwitchbotKeypadfromswitchbot/__init__.pyKEYPAD_INFOtest fixture intests/__init__.pytests/test_keypad.pyverifying battery and attempt_stateare correctly parsed from advertisement data