Skip to content

[astro] Fix circadian luminosity bounds#20085

Merged
lsiepel merged 2 commits intoopenhab:mainfrom
Nadahar:astro-circadian-fix
Jan 17, 2026
Merged

[astro] Fix circadian luminosity bounds#20085
lsiepel merged 2 commits intoopenhab:mainfrom
Nadahar:astro-circadian-fix

Conversation

@Nadahar
Copy link
Copy Markdown
Contributor

@Nadahar Nadahar commented Jan 17, 2026

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.

Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
@Nadahar Nadahar requested review from clinique and lsiepel January 17, 2026 05:44
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);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I adjusted this because to test the difference between start and end of events, the time must be where the sun hasn't set.

@lsiepel lsiepel requested a review from Copilot January 17, 2026 12:51
@lsiepel lsiepel added the bug An unexpected problem or unintended behavior of an add-on label Jan 17, 2026
Copy link
Copy Markdown
Contributor

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 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>
Copy link
Copy Markdown
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@lsiepel lsiepel merged commit 88c9e0b into openhab:main Jan 17, 2026
2 checks passed
@lsiepel lsiepel added this to the 5.2 milestone Jan 17, 2026
@Nadahar Nadahar deleted the astro-circadian-fix branch January 17, 2026 20:59
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An unexpected problem or unintended behavior of an add-on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[astro] Circadian light seems to have no floor value

4 participants