Repository navigation
fix(curtain): parse curtain advertisements as pySwitchbot does (pySwitchbot 3.8.2) - #364
Merged
Merged
Conversation
Port of pySwitchbot's process_wocurtain, found while porting pySwitchbot 3.8.2: - read the state from the manufacturer data when present (mfr[8:11]), and the Curtain 3 battery from mfr[12]; fall back to the service data - moving is bit 7 of the position byte, not the calibration bit - calibrated is bit 6 of byte 1, not bit 5 - light level is the high nibble of byte 4 and the device chain its low 3 bits - accept the legacy 0x0D00 service UUID that pySwitchbot accepts The position stays as the curtain reports it (0 open, 100 closed). pySwitchbot 3.8.2 (#614) needs no port: node-switchbot never assigns a model to an advertisement without service data. A test pins that with pySwitchbot's fixtures. 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.
Ports pySwitchbot 3.8.2, and fixes curtain advertisement parsing that turned up while checking it.
pySwitchbot 3.8.2
The release has one behaviour change, #614. pySwitchbot gave a device that was first heard without service data the caller's fallback model, then kept that model even after a later advertisement identified the device. node-switchbot doesn't need the fix: it ignores advertisements without service data, so it never assigns a fallback model. A new test runs pySwitchbot's #614 fixtures through the scanner. The first advertisement is ignored and the second identifies a Curtain 3.
The rest of the release is dependency and CI bumps, which don't apply here.
Curtain advertisement fixes
Running those fixtures showed that node-switchbot's curtain parsing didn't match pySwitchbot's
process_wocurtainor the SwitchBotAPI-BLE curtain docs:inMotioncalibrationlightLevelbyte 4 & 0x7FdeviceChainbyte 5 & 0x03byte 4 & 0x07mfr[8:11]), service data otherwisemfr[12]on Curtain 3, service data otherwiseThe parser is now
src/utils/curtain-advertisement.ts(parseCurtainAdvertisement), alongside the lock and sensor parsers.The scanner also accepts the legacy
0x0D00service UUID that pySwitchbot accepts. It already accepted000d, which is how the docs write it byte-wise; that spelling still works.Position meaning is unchanged: 0 = open, 100 = closed, as the curtain reports it. pySwitchbot reverses it by default, but homebridge-switchbot and other consumers already convert. The tests use pySwitchbot's fixtures, with positions written as 100 minus pySwitchbot's.
Tests
test/utils/curtain-advertisement.test.ts: pySwitchbot's curtain fixtures (Curtain, firmware 6, Curtain 3), the motion bit, the #614 sequence and the legacy UUID.test/types/model-identities.test.ts: the Curtain 3[test had pinned the old bits and a 5-byte payload. It now uses the documented layout.Build, test (526) and lint pass. This hasn't been tested on a real curtain.
Consumers: no breaking changes. homebridge-switchbot reads only
position, so it needs no follow-up; it picks up the fix through the automatic dependency PR.Generated by Claude Code