Repository navigation
fix: OpenAPI fallback, BLE replies, discovery merging, OpenAPI commands and BLE model codes - #344
Merged
Merged
Conversation
…ds and BLE model codes
Transport
- Fall back to the OpenAPI when a BLE command fails. With connection
intelligence on (the default), a fallback was only set when it picked a
transport other than the preferred one, so BLE failures never reached
the API.
- Read BLE status, lock state and Bot state by peripheral id when the MAC
is empty (macOS); only commands handled that before.
- Enforce the circuit breaker's HALF_OPEN limit, and stop its recovery
timer keeping the process alive.
BLE replies
- Judge a reply by its status byte (byte 0), as pySwitchbot and the BLE
docs do. Scanning every byte read payload such as a 7% battery as
"password required", and an error reply containing 0x01 as success.
Discovery
- Merge an OpenAPI device into its BLE device by id (the MAC without
colons). Matching only on type strings, which differ between BLE and the
API, dropped the API record, and with two devices of one model could
attach the wrong device and lose the other.
- Only match by type for BLE devices with no MAC, comparing resolved
device classes, and send API calls to the OpenAPI deviceId (new
DeviceInfo.apiDeviceId).
OpenAPI commands (per the SwitchBotAPI device pages)
- Blind Tilt: fullyOpen, closeUp, closeDown, and setPosition as
`direction;position`, one attempt per call.
- Air purifiers: setMode {mode, fanGear}; there is no setFanSpeed or
setPresetMode.
- RGBIC Neon Wire Rope Light: setColor as "r:g:b".
- Color Bulb: setColorTemperature instead of the nonexistent setColorTemp.
- Vacuums: no parameters on start/dock; S10, S20, K10+ Pro Combo, K11+
and K20+ Pro use startClean. Map "Robot Vacuum Cleaner K20 Plus Pro",
and map S1/S1 Plus to the base vacuum class.
BLE model codes
- Align DEVICE_MODEL_MAP with pySwitchbot SUPPORTED_TYPES. Several codes
named the wrong product (0x06 Presence Sensor, 'y' Water Leak Detector,
0x0D Relay Switch 1PM, 0x07 Humidifier 2, ...) and many were missing
(Meter Pro, Relay Switches, Garage Door Opener, Plug Mini (EU), ...).
Status parsing uses the corrected Lock and Relay Switch codes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TYWa2RXoWsaUTWh76oNv8s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bugs found in a review of the library against pySwitchbot, the SwitchBotAPI-BLE protocol docs and the SwitchBotAPI device pages. Each fix has a test that fails without it.
Transport
sendCommandonly set a fallback when it chose a transport other than the preferred one. A failed BLE command on a BLE-preferring device therefore never reached the API.mac ?? id:<bleId>, which passes an empty-string MAC through. They now use the same address as commands.BLE replies
Discovery
Meter PlusvsMeterPlus), so the API record was dropped and the device never got API fallback. With two devices of one model, the wrong one could be attached and the other lost. Matching is now by id (the MAC without colons equals the OpenAPIdeviceId).deviceIdvia the newDeviceInfo.apiDeviceId.OpenAPI commands
turnOn,turnOff,setPosition {position}, plus a second API attempt on failurefullyOpen,closeUp,closeDown,setPosition "down;50", one attemptsetMode "auto",setFanSpeed,setPresetModesetMode {"mode", "fanGear"}setColor {red, green, blue}setColor "r:g:b"setColorTemp "min-max:temp"setColorTemperature tempstart {protocolVersion}start, orstartCleanfor S10, S20, K10+ Pro Combo, K11+, K20+ ProAlso mapped
Robot Vacuum Cleaner K20 Plus Pro(previously not created at all), and S1/S1 Plus to the base vacuum class.BLE model codes
DEVICE_MODEL_MAPis aligned with pySwitchbot'sSUPPORTED_TYPES. Several codes named the wrong product:0x06Presence Sensor → Leak Detector,yLeak Detector → Keypad,0x0DRelay Switch 1PM → Lock Lite,0x07Humidifier 2 → (Universal Remote, unsupported). Many products weren't recognised at all, including Meter Pro, Relay Switch 1/1PM/2PM, Garage Door Opener, Plug Mini (EU), Lock Pro ($), Roller Shade and Circulator Fan. Codes with no pySwitchbot equivalent are kept.SwitchBotBLEModelis unchanged, since changing its values would be a breaking change.Not changed (needs real hardware)
notify.read()rather than by waiting for a notification, as pySwitchbot does.setPositionputs the speed in the OpenAPImodefield. That's correct for the default speed (ff); other speeds don't map cleanly to the documented modes 0, 1 and ff.Checks
Build, 374 tests (+41) and lint pass. Labelled
minor(5.1.0): new devices are recognised, and the rest are fixes.Generated by Claude Code