[astro] Adds dynamic icons for Sun Eclipses (#20007)

* Adds dynamic icons for Sun Eclipse

Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital
2026-01-09 13:27:14 +01:00
committed by GitHub
parent dfa2adf2c1
commit 3292fb1ec0
8 changed files with 74 additions and 24 deletions
+6 -20
View File
@@ -32,26 +32,12 @@ This is done by setting `useMeteorologicalSeason` to true in the advanced settin
This binding has its own IconProvider and makes available the following list of icons
| Icon Name | Dynamic | Illustration |
|-----------------------------|---------|--------------|
| oh:astro:zodiac | Yes | ![Zodiac](doc/images/zodiac.svg) |
| oh:astro:zodiac-aquarius | Yes | ![Aquarius](doc/images/zodiac-aquarius.svg) |
| oh:astro:zodiac-aries | Yes | ![Aries](doc/images/zodiac-aries.svg) |
| oh:astro:zodiac-cancer | Yes | ![Cancer](doc/images/zodiac-cancer.svg) |
| oh:astro:zodiac-capricorn | Yes | ![Capricorn](doc/images/zodiac-capricorn.svg) |
| oh:astro:zodiac-gemini | Yes | ![Gemini](doc/images/zodiac-gemini.svg) |
| oh:astro:zodiac-leo | Yes | ![Leo](doc/images/zodiac-leo.svg) |
| oh:astro:zodiac-libra | Yes | ![Libra](doc/images/zodiac-libra.svg) |
| oh:astro:zodiac-pisces | Yes | ![Pisces](doc/images/zodiac-pisces.svg) |
| oh:astro:zodiac-sagittarius | Yes | ![Sagittarius](doc/images/zodiac-sagittarius.svg) |
| oh:astro:zodiac-scorpio | Yes | ![Scorpio](doc/images/zodiac-scorpio.svg) |
| oh:astro:zodiac-taurus | Yes | ![Taurus](doc/images/zodiac-taurus.svg) |
| oh:astro:zodiac-virgo | Yes | ![Virgo](doc/images/zodiac-virgo.svg) |
| oh:astro:season | Yes | ![Season](doc/images/season.svg) |
| oh:astro:season-autumn | Yes | ![Autumn](doc/images/season-autumn.svg) |
| oh:astro:season-spring | Yes | ![Spring](doc/images/season-spring.svg) |
| oh:astro:season-summer | Yes | ![Summer](doc/images/season-summer.svg) |
| oh:astro:season-winter | Yes | ![Winter](doc/images/season-winter.svg) |
| Icon Name | Dynamic | Illustration |
| --------------------------- | ------- | ------------------------------------------------- |
| oh:astro:zodiac | Yes | ![Zodiac](doc/images/zodiac.svg) |
| oh:astro:season | Yes | ![Season](doc/images/season.svg) |
| oh:astro:sun_eclipse | Yes | ![Sun Eclipse](doc/images/sun_eclipse.svg) |
## Channels
@@ -0,0 +1,12 @@
<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="prefix__a" cx="32" cy="32" r="31" gradientUnits="userSpaceOnUse">
<stop stop-color="#f8f5e5" stop-opacity="0" offset=".8" />
<stop stop-color="#ffde52" stop-opacity=".2" offset=".8" />
<stop stop-color="#ffde52" stop-opacity="0" offset="1" />
</radialGradient>
</defs>
<circle cx="32" cy="32" r="31" fill="url(#prefix__a)" />
<circle cx="32" cy="32" r="23" fill="#ffde52" />
<ellipse cx="40.787" cy="32.567" rx="21.7" ry="21.824" />
</svg>

After

Width:  |  Height:  |  Size: 581 B

@@ -24,6 +24,7 @@ import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.astro.internal.model.EclipseKind;
import org.openhab.binding.astro.internal.model.SeasonName;
import org.openhab.binding.astro.internal.model.ZodiacSign;
import org.openhab.core.i18n.TranslationProvider;
@@ -50,7 +51,8 @@ public class AstroIconProvider implements IconProvider {
private static final String DEFAULT_DESCRIPTION = "Icons provided for the Astro Binding";
private static final String ZODIAC_SET = "zodiac";
private static final String SEASON_SET = "season";
private static final Set<String> ICON_SETS = Set.of(SEASON_SET, ZODIAC_SET);
private static final String SUN_ECLIPSE_SET = "sun_eclipse";
private static final Set<String> ICON_SETS = Set.of(SEASON_SET, SUN_ECLIPSE_SET, ZODIAC_SET);
private final Logger logger = LoggerFactory.getLogger(AstroIconProvider.class);
private final TranslationProvider i18nProvider;
@@ -93,6 +95,7 @@ public class AstroIconProvider implements IconProvider {
Enum<?> stateEnum = switch (category) {
case ZODIAC_SET -> ZodiacSign.valueOf(state);
case SEASON_SET -> SeasonName.valueOf(state);
case SUN_ECLIPSE_SET -> EclipseKind.valueOf(state);
default -> throw new IllegalArgumentException("Category of icon not found: %s".formatted(category));
};
iconName = iconName.replace(".", "-%s.".formatted(stateEnum.name().toLowerCase(Locale.US)));
@@ -314,7 +314,7 @@
<item-type>DateTime</item-type>
<label>Total Eclipse</label>
<description>The DateTime of the next total eclipse</description>
<category>calendar</category>
<category>Calendar</category>
<tags>
<tag>Calculation</tag>
<tag>Timestamp</tag>
@@ -326,7 +326,7 @@
<item-type>DateTime</item-type>
<label>Partial Eclipse</label>
<description>The DateTime of the next partial eclipse</description>
<category>calendar</category>
<category>Calendar</category>
<tags>
<tag>Calculation</tag>
<tag>Timestamp</tag>
@@ -338,7 +338,7 @@
<item-type>DateTime</item-type>
<label>Ring Eclipse</label>
<description>The DateTime of the next ring eclipse</description>
<category>calendar</category>
<category>Calendar</category>
<tags>
<tag>Calculation</tag>
<tag>Timestamp</tag>
@@ -350,6 +350,7 @@
<kind>trigger</kind>
<label>Sun Eclipse Event</label>
<description>Sun eclipse event</description>
<category>oh:astro:sun_eclipse</category>
<event>
<options>
<option value="TOTAL">total</option>
@@ -0,0 +1,12 @@
<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="prefix__a" cx="32" cy="32" r="31" gradientUnits="userSpaceOnUse">
<stop stop-color="#f8f5e5" stop-opacity="0" offset=".8" />
<stop stop-color="#ffde52" stop-opacity=".2" offset=".8" />
<stop stop-color="#ffde52" stop-opacity="0" offset="1" />
</radialGradient>
</defs>
<circle cx="32" cy="32" r="31" fill="url(#prefix__a)" />
<circle cx="32" cy="32" r="23" fill="#ffde52" />
<ellipse cx="40.787" cy="32.567" rx="21.7" ry="21.824" />
</svg>

After

Width:  |  Height:  |  Size: 581 B

@@ -0,0 +1,12 @@
<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="prefix__a" cx="32" cy="32" r="31" gradientUnits="userSpaceOnUse">
<stop stop-color="#f8f5e5" stop-opacity="0" offset=".8" />
<stop stop-color="#ffde52" stop-opacity=".2" offset=".8" />
<stop stop-color="#ffde52" stop-opacity="0" offset="1" />
</radialGradient>
</defs>
<circle cx="32" cy="32" r="31" fill="url(#prefix__a)" />
<circle cx="32" cy="32" r="23" fill="#ffde52" />
<circle cx="32" cy="-32" transform="rotate(90)" r="20.957" />
</svg>

After

Width:  |  Height:  |  Size: 585 B

@@ -0,0 +1,12 @@
<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="prefix__a" cx="32" cy="32" r="31" gradientUnits="userSpaceOnUse">
<stop stop-color="#f8f5e5" stop-opacity="0" offset=".618" />
<stop stop-color="#ffde52" stop-opacity=".836" offset=".798" />
<stop stop-color="#ffde52" stop-opacity="0" offset="1" />
</radialGradient>
</defs>
<circle cx="32" cy="32" r="31" fill="url(#prefix__a)" />
<circle cx="32" cy="32" r="23" fill="#ffde52" />
<circle cx="32" cy="32" r="23" />
</svg>

After

Width:  |  Height:  |  Size: 563 B

@@ -0,0 +1,12 @@
<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="prefix__a" cx="32" cy="32" r="31" gradientUnits="userSpaceOnUse">
<stop stop-color="#f8f5e5" stop-opacity="0" offset=".8" />
<stop stop-color="#ffde52" stop-opacity=".2" offset=".8" />
<stop stop-color="#ffde52" stop-opacity="0" offset="1" />
</radialGradient>
</defs>
<circle cx="32" cy="32" r="31" fill="url(#prefix__a)" />
<circle cx="32" cy="32" r="23" fill="#ffde52" />
<ellipse cx="40.787" cy="32.567" rx="21.7" ry="21.824" />
</svg>

After

Width:  |  Height:  |  Size: 581 B