-
-
Notifications
You must be signed in to change notification settings - Fork 12
fix: fix litra-brightness command and setBrightnessPercentage function so 0% and 1% are distinct
#557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: timrogers <[email protected]>
- Updated percentageWithinRange function to use standard 0-100 percentage formula - Removed special case for 0% in setBrightnessPercentage - Updated tests to reflect new expected behavior - Added test to verify 0% and 1% produce different brightness values Co-authored-by: timrogers <[email protected]>
There was a problem hiding this 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 PR fixes an off-by-one error where both 0% and 1% brightness incorrectly mapped to the same lumen value (the device minimum). The fix updates the percentage calculation formula to use standard percentage math and removes the now-unnecessary special case handling.
Key Changes:
- Updated
percentageWithinRangeformula from(p-1)/99top/100to correctly map the full 0-100% range - Removed redundant 0% special case in
setBrightnessPercentage - Added test to verify 0% and 1% produce distinct brightness values
Reviewed changes
Copilot reviewed 4 out of 14 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/utils.ts | Updated percentage formula to use standard p/100 calculation |
| src/driver.ts | Removed special case handling for 0% brightness |
| tests/utils.test.ts | Updated test expectations to reflect new formula behavior |
| tests/driver.test.ts | Added test verifying 0% and 1% produce distinct brightness values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot Is it implemented so that values are properly distributed and: 0% returns the exact minimum |
Math.ceil always returns an integer, making the outer Math.round redundant. This simplifies the code while maintaining the same behavior. Co-authored-by: timrogers <[email protected]>
Yes, the implementation correctly:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 14 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Fixes #556. |
litra-brightness command and setBrightnessPercentage function so 0% and 1% are distinct
|
🎉 This PR is included in version 4.5.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Plan to fix brightness percentage off-by-one bug
percentageWithinRangefunction insrc/utils.tsto use standard percentage formula (0-100)setBrightnessPercentagefunction insrc/driver.tstests/utils.test.tsto reflect new expected behaviortests/driver.test.tsfor setBrightnessPercentage to reflect new expected valuesSummary
Successfully fixed the off-by-one bug where 0% and 1% brightness produced the same value (minimum brightness).
Changes:
percentageWithinRangeformula:((percentage - 1) / (100 - 1))→(percentage / 100)setBrightnessPercentageMath.round(Math.ceil already returns integers)Verification:
Behavior (Litra Glow 20-250 lumen):
Fixes #556
Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.