Open
Conversation
… test cases [by wanzi]
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
…ion missing channel arg [by wanzi]
Small position values (< 16) produced odd-length hex strings causing fromhex() ValueError. Format position as 02X to ensure even hex digits. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… mode - Format position as 2-digit hex (02X) to prevent odd-length hex string causing fromhex() ValueError on small position values - Add _update_motion_direction override with HA semantics (new > prev = opening) - Convert device positions (0=open, 100=closed) to HA positions before direction comparison in set_position - Fix test expectations to match device/HA semantic mapping Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…h2PM The method was defined twice; the first definition was dead code that caused 8 lines of missing coverage reported by codecov. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds roller/cover mode support for SwitchbotRelaySwitch2PM by having it additionally inherit from SwitchbotBaseCover. It also refactors the SwitchbotBaseCover constructor to accept reverse as a keyword argument, updates the advertisement parser for 2PM to include mode, position, and calibration fields, and updates tests accordingly.
Changes:
SwitchbotRelaySwitch2PMnow inherits from bothSwitchbotRelaySwitchandSwitchbotBaseCover, gaining cover/roller commands (open,close,stop,set_position) and properties (position,mode).SwitchbotBaseCover.__init__changedreversefrom a positional to a keyword argument; all subclass call sites updated.- Advertisement parser and
_parse_common_dataextended withmode,position,calibrationfields for 2PM devices.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
switchbot/devices/base_cover.py |
Refactored constructor to accept reverse as keyword-only via kwargs.pop |
switchbot/devices/relay_switch.py |
Added cover inheritance, roller commands, position/mode properties, motion direction logic, and refactored 2PM get_basic_info |
switchbot/adv_parsers/relay_switch.py |
Added mode, position, calibration fields to 2PM advertisement parser |
switchbot/devices/curtain.py |
Updated super().__init__ call for new keyword arg signature |
switchbot/devices/blind_tilt.py |
Updated super().__init__ call for new keyword arg signature |
switchbot/devices/roller_shade.py |
Updated super().__init__ call for new keyword arg signature |
tests/test_relay_switch.py |
Added tests for cover operations, position, mode, and motion direction |
tests/test_base_cover.py |
Updated SwitchbotBaseCover instantiation to match new keyword arg signature |
tests/test_adv_parser.py |
Added expected mode, position, calibration fields to 2PM test cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| "sequence_number": mfr_data[6], | ||
| "isOn": bool(mfr_data[7] & 0b01000000), | ||
| "power": parse_power_data(mfr_data, 12), | ||
| "mode": mfr_data[9] & 0b11110000 >> 4, |
|
|
||
|
|
||
| class SwitchbotRelaySwitch2PM(SwitchbotRelaySwitch): | ||
| class SwitchbotRelaySwitch2PM(SwitchbotRelaySwitch, SwitchbotBaseCover): |
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
Add roller/cover mode support for
SwitchbotRelaySwitch2PMand fix related test cases.Changes
Features
SwitchbotRelaySwitch2PMnow inherits fromSwitchbotBaseCover, enabling cover/roller control support.open(),close(),stop(),set_position()commands for roller mode.positionandmodeproperties toSwitchbotRelaySwitch2PM.COMMAND_OPEN,COMMAND_CLOSE,COMMAND_POSITION,COMMAND_STOP.Parser
process_relay_switch_2pm: Addedmode,position,calibrationfields to both channel 1 and channel 2 advertisement data.Refactor
SwitchbotBaseCover.__init__: Changedreverseto a keyword-only argument, updated all subclass call sites (curtain.py,blind_tilt.py,roller_shade.py)._parse_common_datainSwitchbotRelaySwitch:sequence_numbernow reads fromraw_data[0](wasraw_data[1]).Tests
test_adv_parser.py: Added expectedmode,position,calibrationfields toSwitchbotRelaySwitch2PMtest cases.test_base_cover.py: FixedSwitchbotBaseCoverinstantiation to use new keyword argument signature.