Skip to content

Conversation

@hnw
Copy link

@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.

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.

1 participant