Skip to content

Conversation

@hnw
Copy link
Contributor

@hnw hnw commented Dec 7, 2025

Description

This PR updates the advertisement parser for the Presence Sensor.

Changes

  • Add duration parsing: Parse bytes 8-9 (big-endian). This value represents the duration of the current state (time elapsed since motion was detected or cleared).
  • Fix lightLevel mask: Expand the bitmask from 0x0F to 0x1F.

Motivation / Context

While testing with a real device, I observed a raw lightLevel value of 20 (0b10100).
The previous mask 0x0F (0b01111) truncated this value, resulting in incorrect data. Expanding the mask to 0x1F (0b11111) correctly captures values > 15.

This update complements the initial support added in #410.

- Parse `duration` from manufacturer data bytes 8-9 (big-endian).
- Expand `lightLevel` bitmask from 0x0F to 0x1F to support observed values > 15 (e.g., 20).
- Update unit tests to reflect these changes.
@codecov
Copy link

codecov bot commented Dec 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
switchbot/adv_parsers/presence_sensor.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zerzhang zerzhang requested a review from bdraco December 22, 2025 11:47
@bdraco
Copy link
Member

bdraco commented Dec 22, 2025

@zerzhang If this is a good fix, you should have rights to review and merge

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hnw

@bdraco bdraco merged commit eb25905 into sblibs:master Dec 24, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants