Skip to content

Conversation

@elgris
Copy link
Contributor

@elgris elgris commented Dec 31, 2025

This series of changes adds some control over datetime settings on the SwitchBot Meter Pro CO2 Monitor and aims to support HomeAssistant (see this request to allow syncing the device's time from HA).

This functionality was reverse-engineered, I don't have any access to the Switchbot documentation.

The change can contribute to #430, as it focuses on datetime exclusively and provides more precise control over that.

@elgris elgris force-pushed the co2_meter_time_control branch 3 times, most recently from 951ce6e to 6045f29 Compare December 31, 2025 20:52
@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
switchbot/__init__.py 100.00% <100.00%> (ø)
switchbot/devices/meter_pro.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@elgris elgris force-pushed the co2_meter_time_control branch 3 times, most recently from 92bd5b7 to d459632 Compare December 31, 2025 21:30
@elgris elgris force-pushed the co2_meter_time_control branch from 32b013e to 0b4a4c3 Compare December 31, 2025 23:56
pre-commit-ci bot and others added 6 commits December 31, 2025 23:57
First, the comment is device-specific. Other devices might implement it differently. Second, top-level comment breaks CI checks.
…replaced byte value comparison with a bit op for consistency with the rest of the codebase.
@elgris
Copy link
Contributor Author

elgris commented Jan 1, 2026

Note: this change provides necessary tools for #416.

elgris and others added 2 commits January 4, 2026 19:29
Also replaces a comparison with "80" byte with a bit op for consistency with the rest of the codebase.
@zerzhang
Copy link
Collaborator

zerzhang commented Jan 6, 2026

Rename the file Meter to Meterpro to avoid confusion., The current protocol only applies to MeterPro series devices and does not support Meter type devices.

@elgris
Copy link
Contributor Author

elgris commented Jan 6, 2026

Rename the file Meter to Meterpro to avoid confusion., The current protocol only applies to MeterPro series devices and does not support Meter type devices.

But that would make it inconsistent with the advertisement parsers: switchbot/adv_parser/meter.py handles the Pro series too (see process_wosensorth_c). Is that OK?

@zerzhang
Copy link
Collaborator

zerzhang commented Jan 7, 2026

The advertisements for these devices are the same in the first part, but the device setup instructions are quite different.
You only need to rename the file you have currently modified.

To avoid clashing with meter devices, device instructions are different between regular meter vs pro devices.
@elgris
Copy link
Contributor Author

elgris commented Jan 7, 2026

The advertisements for these devices are the same in the first part, but the device setup instructions are quite different. You only need to rename the file you have currently modified.

Ack, thanks for explaining! Restored meter.py and moved the pro-related code to meter_pro.py, also renamed the test file.

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.

Please see comments above

@elgris elgris force-pushed the co2_meter_time_control branch from 6588767 to caf7902 Compare January 8, 2026 13:42
…turn types.

Also makes tests parameterized to remove code repetition.
@elgris elgris force-pushed the co2_meter_time_control branch from caf7902 to e97bc40 Compare January 8, 2026 13:47
@elgris elgris requested a review from bdraco January 8, 2026 14:41
@elgris
Copy link
Contributor Author

elgris commented Jan 22, 2026

Hi folks! Is there anything else I could do / fix / adjust?
Thanks!

@bdraco
Copy link
Member

bdraco commented Jan 25, 2026

Please don't force push after review has began. It means I have to recheck everything again which creates multi-day/week delays as I need to find a larger time window instead of just checking what has changed

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds datetime control functionality to the SwitchBot Meter Pro CO2 Monitor, enabling HomeAssistant and other applications to sync the device's time. The implementation is based on reverse-engineered protocol analysis and provides methods to get/set time offsets, get/set datetime with timezone support, and configure time display format.

Changes:

  • Added new SwitchbotMeterProCO2 class with datetime management methods
  • Implemented comprehensive test coverage for all datetime operations
  • Exported the new class in the package's public API

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
switchbot/devices/meter_pro.py New device class implementing datetime control methods including time offset, datetime with timezone, and display format configuration
tests/test_meter_pro.py Comprehensive test suite covering all datetime methods with success, failure, and edge case scenarios
switchbot/init.py Added import and export of SwitchbotMeterProCO2 class to package API

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

@bdraco bdraco merged commit 9e62748 into sblibs:master Jan 25, 2026
6 checks passed
fankai777 pushed a commit to fankai777/pySwitchbot that referenced this pull request Jan 26, 2026
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
@elgris
Copy link
Contributor Author

elgris commented Jan 26, 2026

Thanks @elgris

Woohoo! Glad to help! Sorry for the noise with force pushes, just wanted to keep the history tidy :) Lesson learned, I'll be more careful with future contributions. Pls don't hesitate to ping me in case of bugs with this code.

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.

3 participants