]> git.basschouten.com Git - openhab-addons.git/blob
45c7813ed8bad034558f227bcd98d38ea61dc4f0
[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.qbus.internal.protocol;
14
15 import java.io.IOException;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.qbus.internal.handler.QbusSceneHandler;
20
21 /**
22  * The {@link QbusScene} class represents the action Qbus Scene output.
23  *
24  * @author Koen Schockaert - Initial Contribution
25  */
26
27 @NonNullByDefault
28 public final class QbusScene {
29
30     private @Nullable QbusCommunication qComm;
31
32     public @Nullable QbusSceneHandler thingHandler;
33
34     private @Nullable Integer state;
35
36     private Integer id;
37
38     QbusScene(Integer id) {
39         this.id = id;
40     }
41
42     /**
43      * This method should be called if the ThingHandler for the thing corresponding to this scene is initialized.
44      * It keeps a record of the thing handler in this object so the thing can be updated when
45      * the scene output receives an update from the Qbus client.
46      *
47      * @param handler
48      */
49     public void setThingHandler(QbusSceneHandler handler) {
50         this.thingHandler = handler;
51     }
52
53     /**
54      * This method sets a pointer to the qComm SCENE of class {@link QbusCommunication}.
55      * This is then used to be able to call back the sendCommand method in this class to send a command to the
56      * Qbus client.
57      *
58      * @param qComm
59      */
60     public void setQComm(QbusCommunication qComm) {
61         this.qComm = qComm;
62     }
63
64     /**
65      * Get the value of the Scene.
66      *
67      * @return Scene value
68      */
69     public @Nullable Integer getState() {
70         return this.state;
71     }
72
73     /**
74      * Sends Scene state to Qbus.
75      * 
76      * @param value
77      * @param sn
78      * @throws InterruptedException
79      * @throws IOException
80      */
81     public void execute(int value, String sn) throws InterruptedException, IOException {
82         QbusMessageCmd qCmd = new QbusMessageCmd(sn, "executeScene").withId(this.id).withState(value);
83         QbusCommunication comm = qComm;
84         if (comm != null) {
85             comm.sendMessage(qCmd);
86         }
87     }
88 }