Skip to content

[astro] Review Eclipses calculations#20077

Merged
lsiepel merged 10 commits intoopenhab:mainfrom
clinique:astro_eclipse
Jan 17, 2026
Merged

[astro] Review Eclipses calculations#20077
lsiepel merged 10 commits intoopenhab:mainfrom
clinique:astro_eclipse

Conversation

@clinique
Copy link
Copy Markdown
Contributor

Factorization of common Moon/Sun Eclipse parts.
Addition of Moon Eclipse Icon set
Eclipse model object now Instant based and Immutable
Unit testing for Eclipses added

Last part of PR #19910

@clinique clinique self-assigned this Jan 15, 2026
@clinique clinique added the enhancement An enhancement or new feature for an existing add-on label Jan 15, 2026
@clinique clinique requested review from Nadahar and lsiepel and removed request for lsiepel January 15, 2026 17:12
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 PR refactors eclipse calculations in the Astro binding by extracting common logic into reusable base classes, making the Eclipse model immutable and Instant-based, adding Moon eclipse icons, and introducing comprehensive unit tests for eclipse calculations.

Changes:

  • Refactored eclipse calculations into a hierarchy (AstroCalc → EclipseCalc → MoonEclipseCalc/SunEclipseCalc) to eliminate code duplication
  • Made Eclipse model immutable with Instant-based dates instead of mutable Calendar objects
  • Added Moon eclipse icon set with three SVG variants (default, total, partial)

Reviewed changes

Copilot reviewed 22 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
EclipseCalcTest.java New comprehensive unit tests for Sun and Moon eclipses using historical eclipse data
MoonCalcTest.java Updated tests to use new API (getDistanceType(), getEclipses())
moon_eclipse*.svg (3 files) New icon resources for Moon eclipse visualization
MathUtils.java Added frac() utility method for fractional part calculation
DateTimeUtils.java Added GMST/LMST conversion methods, JD constants, and addDays() utility
AstroConstants.java Added Earth radius, flattening, and prime meridian rate constants
Eclipse.java Refactored to be immutable with Instant-based dates and internal EclipseData record
Moon.java Changed to immutable eclipses field and removed deprecated getApogee()/getPerigee()/getDistance() methods
Sun.java Renamed eclipse field to eclipses and made it final, removed setter
MoonPosition.java Fixed NULL constant type from Position to MoonPosition
AstroCalc.java New base class with shared eclipse calculation helper methods
EclipseCalc.java Abstract class containing common eclipse calculation logic
MoonEclipseCalc.java Moon-specific eclipse detection logic
SunEclipseCalc.java Sun-specific eclipse detection logic
MoonCalc.java Extensively refactored to extend AstroCalc and use new eclipse hierarchy
SunCalc.java Refactored to use SunEclipseCalc and calculate eclipse elevations inline
AstroThingHandler.java Simplified getPositionAt() to return non-nullable Position
MoonHandler.java Updated to use new eclipse and distance APIs
SunHandler.java Updated to use new eclipse API and removed setElevations() call
DailyJobMoon.java Updated to schedule eclipse events using Instant instead of Calendar
DailyJobSun.java Updated to schedule eclipse events using Instant instead of Calendar
AstroIconProvider.java Added MOON_ECLIPSE_SET to supported icon sets
README.md Documented new moon_eclipse icon set
Comments suppressed due to low confidence (1)

bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/MathUtils.java:18

  • Corrected grammar from 'Common used DateTime functions' to 'Commonly used DateTime functions'.
 * Common used DateTime functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@Nadahar Nadahar left a comment

Choose a reason for hiding this comment

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

I have some minor comments (as always) and think it would be preferable to have #20081 merged first and the tests done that way, but I think the code itself LGTM as it is now.

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.

Only change that is left is to adapt to the tests to #20081

note: there is also something wrong with the DCO, please check.

Signed-off-by: Gaël L'hopital <gael@lhopital.org>
Signed-off-by: Gaël L'hopital <gael@lhopital.org>
Signed-off-by: Gaël L'hopital <gael@lhopital.org>
lspiel code review adressed.
Rebased and conflicts resolution
Nadahar and Copilot code review

Signed-off-by: clinique <gael@lhopital.org>
Signed-off-by: gael@lhopital.org <gael@lhopital.org>
Signed-off-by: gael@lhopital.org <gael@lhopital.org>
Signed-off-by: clinique <gael@lhopital.org>
Signed-off-by: clinique <gael@lhopital.org>
Signed-off-by: Nadahar <Nadahar@users.noreply.github.com>
@Nadahar
Copy link
Copy Markdown
Contributor

Nadahar commented Jan 17, 2026

I tried to use GitHub to resolve the conflict - I might have caused more trouble than I solved, because it seems like GitHub made a merge commit out of it. I'm sorry for that, but since squashing is the usual practice in OH, it might not matter. I "always" rebase everything, so I have all but forgotten that merge commits exist (they are an evil mess).

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

Copilot reviewed 33 out of 37 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…nding/astro/internal/model/EclipseSet.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Gaël L'hopital <gael@lhopital.org>
@lsiepel lsiepel merged commit c5b618c into openhab:main Jan 17, 2026
2 checks passed
@lsiepel lsiepel added this to the 5.2 milestone Jan 17, 2026
Merlin10437 pushed a commit to Merlin10437/openhab-addons that referenced this pull request Mar 24, 2026
* Instant and Immutable Eclipse

Signed-off-by: Gaël L'hopital <gael@lhopital.org>
Co-authored-by: Nadahar <Nadahar@users.noreply.github.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

enhancement An enhancement or new feature for an existing add-on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants