]> git.basschouten.com Git - openhab-addons.git/blob
2e45cf468d44c686536a39fc954e782a593e7919
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.astro.internal.job;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.astro.internal.AstroHandlerFactory;
17 import org.openhab.binding.astro.internal.handler.AstroThingHandler;
18
19 /**
20  * Scheduled job to trigger events
21  *
22  * @author Gerhard Riegler - Initial contribution
23  * @author Amit Kumar Mondal - Implementation to be compliant with ESH Scheduler
24  */
25 @NonNullByDefault
26 public final class EventJob extends AbstractJob {
27
28     private final String channelID;
29     private final String event;
30
31     /**
32      * Constructor
33      *
34      * @param thingUID thing UID
35      * @param channelID channel ID
36      * @param event Event name
37      * @throws IllegalArgumentException
38      *             if any of the arguments is {@code null}
39      */
40     public EventJob(String thingUID, String channelID, String event) {
41         super(thingUID);
42         this.channelID = channelID;
43         this.event = event;
44     }
45
46     @Override
47     public void run() {
48         AstroThingHandler astroHandler = AstroHandlerFactory.getHandler(getThingUID());
49         if (astroHandler != null) {
50             astroHandler.triggerEvent(channelID, event);
51         } else {
52             LOGGER.trace("AstroThingHandler is null");
53         }
54     }
55
56     @Override
57     public String toString() {
58         return "Event job " + getThingUID() + "/" + channelID + "/" + event;
59     }
60 }