Skip to content

fix(curtain): parse curtain advertisements as pySwitchbot does (pySwitchbot 3.8.2) - #364

Merged
donavanbecker merged 1 commit into
latestfrom
fix/curtain-advertisement
Nov 16, 2026
Merged

donavanbecker merged 1 commit into
latestfrom
fix/curtain-advertisement

Conversation

@donavanbecker

Copy link
Copy Markdown
Contributor

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_wocurtain or the SwitchBotAPI-BLE curtain docs:

Field Before Now
inMotion byte 1 bit 6 (the calibration bit) byte 3 bit 7
calibration byte 1 bit 5 (unused) byte 1 bit 6
lightLevel byte 4 & 0x7F high nibble of byte 4 (1–10)
deviceChain byte 5 & 0x03 byte 4 & 0x07
Source service data only manufacturer data when present (mfr[8:11]), service data otherwise
Battery service data mfr[12] on Curtain 3, service data otherwise

The parser is now src/utils/curtain-advertisement.ts (parseCurtainAdvertisement), alongside the lock and sensor parsers.

The scanner also accepts the legacy 0x0D00 service UUID that pySwitchbot accepts. It already accepted 000d, 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

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
@donavanbecker donavanbecker added the patch label Nov 16, 2026 — with Claude
@donavanbecker
donavanbecker merged commit 8e2b5f9 into latest Nov 16, 2026
3 checks passed
@donavanbecker
donavanbecker deleted the fix/curtain-advertisement branch November 16, 2026 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants