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.CHANNEL_ID_SUN_PHASE_NAME;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.astro.internal.AstroHandlerFactory;
19 import org.openhab.binding.astro.internal.handler.AstroThingHandler;
20 import org.openhab.binding.astro.internal.model.Planet;
21 import org.openhab.binding.astro.internal.model.Sun;
22 import org.openhab.binding.astro.internal.model.SunPhaseName;
23 import org.openhab.core.thing.Channel;
26 * Scheduled job for Sun phase change
28 * @author Gerhard Riegler - Initial contribution
29 * @author Amit Kumar Mondal - Implementation to be compliant with ESH Scheduler
32 public final class SunPhaseJob extends AbstractJob {
34 private final SunPhaseName sunPhaseName;
39 * @param thingUID thing UID
40 * @param sunPhaseName {@link SunPhaseName} name
41 * @throws IllegalArgumentException
42 * if any of the arguments is {@code null}
44 public SunPhaseJob(String thingUID, SunPhaseName sunPhaseName) {
46 this.sunPhaseName = sunPhaseName;
51 AstroThingHandler astroHandler = AstroHandlerFactory.getHandler(getThingUID());
52 if (astroHandler != null) {
53 Channel phaseNameChannel = astroHandler.getThing().getChannel(CHANNEL_ID_SUN_PHASE_NAME);
54 if (phaseNameChannel != null) {
55 Planet planet = astroHandler.getPlanet();
56 if (planet != null && planet instanceof Sun) {
57 final Sun typedSun = (Sun) planet;
58 typedSun.getPhase().setName(sunPhaseName);
59 astroHandler.publishChannelIfLinked(phaseNameChannel.getUID());
62 LOGGER.trace("{}", "Phase Name Channel is null");
65 LOGGER.trace("AstroThingHandler is null");
70 public String toString() {
71 return "Sun phase job " + getThingUID() + "/" + sunPhaseName;