Repository navigation
refactor(meter-pro): share input validation between setters - #624
Open
bvuillemin wants to merge 1 commit into
Open
bvuillemin wants to merge 1 commit into
bvuillemin wants to merge 1 commit into
Conversation
Bool and enum checks now both raise TypeError/ValueError from module helpers, and a single _invalid_input() context manager turns them into SwitchbotOperationError. It replaces _check_bool and the repeated try/except blocks in the display, weather, calibration and alarm setters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Summary
Follow-up to #622, addressing the last non-blocking point of its automated review: bool and enum inputs were validated in two different ways.
TypeError/ValueError: the existing_coerce_enumand a new_require_bool._invalid_input()context manager onSwitchbotMeterProturns those errors intoSwitchbotOperationError, with the original error as__cause__._check_booland the repeatedtry/except (TypeError, ValueError)blocks inset_display_zone,set_zone_icons,set_date_format,set_battery_icon,set_temperature_unit,set_button_functions,set_calibration,set_weather, and the comfort and temperature/humidity alarm setters.No behaviour or wire format changes. The only visible difference is that the comfort setter's
customerror message now includes the rejected value, like the other bool checks.Tests
test_setters_reject_wrong_typesalso checks that the error keeps the originalTypeError/ValueErroras its cause.pytest: 2403 passed;switchbot/devices/meter_pro.pystays at 100 % coverage.ruff check,ruff format --checkandcodespellare clean;mypyreports no new errors.I prepared this with an AI coding assistant; I'm the person responsible for this PR and will follow up on review.
🤖 Generated with Claude Code