2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.astro.internal.job;
15 import static org.openhab.binding.astro.internal.AstroBindingConstants.*;
16 import static org.openhab.binding.astro.internal.job.Job.*;
17 import static org.openhab.binding.astro.internal.model.SunPhaseName.*;
19 import java.util.Calendar;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.astro.internal.handler.AstroThingHandler;
23 import org.openhab.binding.astro.internal.model.Eclipse;
24 import org.openhab.binding.astro.internal.model.Planet;
25 import org.openhab.binding.astro.internal.model.Sun;
28 * Daily scheduled jobs For Sun planet
30 * @author Gerhard Riegler - Initial contribution
31 * @author Amit Kumar Mondal - Implementation to be compliant with ESH Scheduler
34 public final class DailyJobSun extends AbstractJob {
36 private final AstroThingHandler handler;
41 * @param thingUID the Thing UID
42 * @param handler the {@link AstroThingHandler} instance
43 * @throws IllegalArgumentException
44 * if {@code thingUID} or {@code handler} is {@code null}
46 public DailyJobSun(String thingUID, AstroThingHandler handler) {
48 this.handler = handler;
53 handler.publishDailyInfo();
54 String thingUID = getThingUID();
55 LOGGER.debug("Scheduled Astro event-jobs for thing {}", thingUID);
57 Planet planet = handler.getPlanet();
59 LOGGER.error("Planet not instantiated");
62 Sun sun = (Sun) planet;
63 scheduleRange(thingUID, handler, sun.getRise(), EVENT_CHANNEL_ID_RISE);
64 scheduleRange(thingUID, handler, sun.getSet(), EVENT_CHANNEL_ID_SET);
65 scheduleRange(thingUID, handler, sun.getNoon(), EVENT_CHANNEL_ID_NOON);
66 scheduleRange(thingUID, handler, sun.getNight(), EVENT_CHANNEL_ID_NIGHT);
67 scheduleRange(thingUID, handler, sun.getMorningNight(), EVENT_CHANNEL_ID_MORNING_NIGHT);
68 scheduleRange(thingUID, handler, sun.getAstroDawn(), EVENT_CHANNEL_ID_ASTRO_DAWN);
69 scheduleRange(thingUID, handler, sun.getNauticDawn(), EVENT_CHANNEL_ID_NAUTIC_DAWN);
70 scheduleRange(thingUID, handler, sun.getCivilDawn(), EVENT_CHANNEL_ID_CIVIL_DAWN);
71 scheduleRange(thingUID, handler, sun.getAstroDusk(), EVENT_CHANNEL_ID_ASTRO_DUSK);
72 scheduleRange(thingUID, handler, sun.getNauticDusk(), EVENT_CHANNEL_ID_NAUTIC_DUSK);
73 scheduleRange(thingUID, handler, sun.getCivilDusk(), EVENT_CHANNEL_ID_CIVIL_DUSK);
74 scheduleRange(thingUID, handler, sun.getEveningNight(), EVENT_CHANNEL_ID_EVENING_NIGHT);
75 scheduleRange(thingUID, handler, sun.getDaylight(), EVENT_CHANNEL_ID_DAYLIGHT);
77 Eclipse eclipse = sun.getEclipse();
78 eclipse.getKinds().forEach(eclipseKind -> {
79 Calendar eclipseDate = eclipse.getDate(eclipseKind);
80 if (eclipseDate != null) {
81 scheduleEvent(thingUID, handler, eclipseDate, eclipseKind.toString(), EVENT_CHANNEL_ID_ECLIPSE, false);
85 // schedule republish jobs
86 schedulePublishPlanet(thingUID, handler, sun.getZodiac().getEnd());
87 schedulePublishPlanet(thingUID, handler, sun.getSeason().getNextSeason());
89 // schedule phase jobs
90 scheduleSunPhase(thingUID, handler, SUN_RISE, sun.getRise().getStart());
91 scheduleSunPhase(thingUID, handler, SUN_SET, sun.getSet().getStart());
92 scheduleSunPhase(thingUID, handler, NIGHT, sun.getNight().getStart());
93 scheduleSunPhase(thingUID, handler, DAYLIGHT, sun.getDaylight().getStart());
94 scheduleSunPhase(thingUID, handler, ASTRO_DAWN, sun.getAstroDawn().getStart());
95 scheduleSunPhase(thingUID, handler, NAUTIC_DAWN, sun.getNauticDawn().getStart());
96 scheduleSunPhase(thingUID, handler, CIVIL_DAWN, sun.getCivilDawn().getStart());
97 scheduleSunPhase(thingUID, handler, ASTRO_DUSK, sun.getAstroDusk().getStart());
98 scheduleSunPhase(thingUID, handler, NAUTIC_DUSK, sun.getNauticDusk().getStart());
99 scheduleSunPhase(thingUID, handler, CIVIL_DUSK, sun.getCivilDusk().getStart());
103 public String toString() {
104 return "Daily job sun " + getThingUID();