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.scheduleEvent;
18 import java.util.Calendar;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.astro.internal.handler.AstroThingHandler;
22 import org.openhab.binding.astro.internal.model.Eclipse;
23 import org.openhab.binding.astro.internal.model.Moon;
24 import org.openhab.binding.astro.internal.model.MoonPhase;
25 import org.openhab.binding.astro.internal.model.Planet;
28 * Daily scheduled jobs for Moon planet
30 * @author Gerhard Riegler - Initial contribution
31 * @author Amit Kumar Mondal - Implementation to be compliant with ESH Scheduler
34 public final class DailyJobMoon extends AbstractJob {
36 private final AstroThingHandler handler;
41 * @param thingUID the Thing UID
42 * @param handler the {@link AstroThingHandler} instance
43 * @throws IllegalArgumentException if {@code thingUID} or {@code handler} is {@code null}
45 public DailyJobMoon(String thingUID, AstroThingHandler handler) {
47 this.handler = handler;
52 handler.publishDailyInfo();
53 String thingUID = getThingUID();
54 LOGGER.debug("Scheduled Astro event-jobs for thing {}", thingUID);
56 Planet planet = handler.getPlanet();
58 LOGGER.error("Planet not instantiated");
61 Moon moon = (Moon) planet;
62 scheduleEvent(thingUID, handler, moon.getRise().getStart(), EVENT_START, EVENT_CHANNEL_ID_RISE, false);
63 scheduleEvent(thingUID, handler, moon.getSet().getEnd(), EVENT_END, EVENT_CHANNEL_ID_SET, false);
65 MoonPhase moonPhase = moon.getPhase();
66 scheduleEvent(thingUID, handler, moonPhase.getFirstQuarter(), EVENT_PHASE_FIRST_QUARTER,
67 EVENT_CHANNEL_ID_MOON_PHASE, false);
68 scheduleEvent(thingUID, handler, moonPhase.getThirdQuarter(), EVENT_PHASE_THIRD_QUARTER,
69 EVENT_CHANNEL_ID_MOON_PHASE, false);
70 scheduleEvent(thingUID, handler, moonPhase.getFull(), EVENT_PHASE_FULL, EVENT_CHANNEL_ID_MOON_PHASE, false);
71 scheduleEvent(thingUID, handler, moonPhase.getNew(), EVENT_PHASE_NEW, EVENT_CHANNEL_ID_MOON_PHASE, false);
73 Eclipse eclipse = moon.getEclipse();
74 eclipse.getKinds().forEach(eclipseKind -> {
75 Calendar eclipseDate = eclipse.getDate(eclipseKind);
76 if (eclipseDate != null) {
77 scheduleEvent(thingUID, handler, eclipseDate, eclipseKind.toString(), EVENT_CHANNEL_ID_ECLIPSE, false);
81 scheduleEvent(thingUID, handler, moon.getPerigee().getDate(), EVENT_PERIGEE, EVENT_CHANNEL_ID_PERIGEE, false);
82 scheduleEvent(thingUID, handler, moon.getApogee().getDate(), EVENT_APOGEE, EVENT_CHANNEL_ID_APOGEE, false);
86 public String toString() {
87 return "Daily job moon " + getThingUID();