Add SwitchbotKeypad device class for classic Keypad#488
Add SwitchbotKeypad device class for classic Keypad#488italo-lombardi wants to merge 13 commits into
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 1 file 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.
|
What's the status here? Would love to have this in the upcoming HA release. Seems like the bot did not fire again. |
bdraco
left a comment
There was a problem hiding this comment.
The code as-is doesn't do anything. There is nothing to review
|
This PR was AI-assisted. The goal is to expose battery % for the classic WoKeypad in Home Assistant. The pySwitchbot side should be complete: A companion HA PR is needed to wire it up ( I have the physical device but no experience testing pySwitchbot integrations. Any guidance on how to validate this locally (e.g. with a BLE sniffer or test harness against real hardware) would be appreciated. |
Exposes attempt_state via _get_adv_value, consistent with how get_battery_percent is implemented in the base class.
Replace raw parsed_data dict access with device.attempt_state property so the new property is exercised by the test suite.
|
Update: tested on real hardware. Ran the parser against a live WoKeypad using BLE scanning on macOS. Results from advertisement data:
Parser correctly extracts both values from All 3 unit tests pass locally. |
|
Really cool, would love to see this merged! :-) |
Adds support for SwitchBot Keypad (WoKeypad) — exposes battery level and attempt_state from BLE advertisements.
https://eu.switch-bot.com/products/switchbot-keypad
Tested on a real device — scanner confirmed
battery: 100andattempt_stateparsed correctly from live BLE advertisement data.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_state are correctly parsed from advertisement dataTest results
All 3 unit tests pass. Verified against real WoKeypad hardware — advertisement data parsed correctly.