[astro] Fix circadian luminosity bounds#20085
Merged
lsiepel merged 2 commits intoopenhab:mainfrom Jan 17, 2026
Merged
Conversation
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
Nadahar
commented
Jan 17, 2026
| Calendar sunrise = newCalendar(2024, Calendar.JANUARY, 1, 7, 0); | ||
| Calendar sunset = newCalendar(2024, Calendar.JANUARY, 1, 19, 0); | ||
| Calendar now = newCalendar(2024, Calendar.JANUARY, 1, 21, 0); | ||
| Calendar now = newCalendar(2024, Calendar.JANUARY, 1, 17, 0); |
Contributor
Author
There was a problem hiding this comment.
I adjusted this because to test the difference between start and end of events, the time must be where the sun hasn't set.
clinique
approved these changes
Jan 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug in the circadian luminosity calculation where brightness values could exceed the valid range of 0-100%. The fix adds proper bounds checking to clamp calculated percentage values to the valid range.
Changes:
- Added bounds checking to the circadian brightness calculation to ensure values stay within [0, 100] range
- Updated existing unit tests to reflect the corrected behavior (brightness = 0 before sunrise instead of 56)
- Added comprehensive parameterized tests covering various times of day for circadian brightness and temperature
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| CircadianCalc.java | Added Math.max and Math.min calls to clamp the percentage calculation to [0.0, 100.0] range |
| CircadianCalcTest.java | Updated test expectations to reflect corrected behavior (0% brightness before sunrise, adjusted test time to daytime hours) |
| ParametrizedStateTestCases.java | Added 11 new parameterized test cases for circadian brightness and temperature at various time offsets to ensure proper behavior across day/night cycles |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
Merlin10437
pushed a commit
to Merlin10437/openhab-addons
that referenced
this pull request
Mar 24, 2026
* [astro] Fix circadian luminosity bounds Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com> Signed-off-by: Merlin10437 <152161717+Merlin10437@users.noreply.github.com>
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.
Fixes #20076.
As I reported in #20076 (comment), the tests codify the current behavior. I have assumed that it is still wrong, and have adjusted the tests accordingly. In addition, I've added some parameterized tests to better capture the behavior.
In case it's supposed to have 100% luminosity at solar midnight, the "fix" isn't a fix.