]> git.basschouten.com Git - openhab-addons.git/blob
0fe8b8d62dcee602cf942df2bc58129b9d221fd2
[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.QbusRolHandler;
20
21 /**
22  * The {@link QbusRol} class represents the action Qbus Shutter/Slats output.
23  *
24  * @author Koen Schockaert - Initial Contribution
25  */
26
27 @NonNullByDefault
28 public final class QbusRol {
29
30     private @Nullable QbusCommunication qComm;
31
32     private Integer id;
33
34     private @Nullable Integer state;
35
36     private @Nullable Integer slats;
37
38     private @Nullable QbusRolHandler thingHandler;
39
40     QbusRol(Integer id) {
41         this.id = id;
42     }
43
44     /**
45      * This method should be called if the ThingHandler for the thing corresponding to this Shutter/Slats is
46      * initialized.
47      * It keeps a record of the thing handler in this object so the thing can be updated when
48      * the shutter/slat receives an update from the Qbus client.
49      *
50      * @param qbusRolHandler
51      */
52     public void setThingHandler(QbusRolHandler qbusRolHandler) {
53         this.thingHandler = qbusRolHandler;
54     }
55
56     /**
57      * This method sets a pointer to the qComm Shutter/Slats of class {@link QbusCommunication}.
58      * This is then used to be able to call back the sendCommand method in this class to send a command to the
59      * Qbus IP-interface when..
60      *
61      * @param qComm
62      */
63     public void setQComm(QbusCommunication qComm) {
64         this.qComm = qComm;
65     }
66
67     /**
68      * Update the value of the Shutter.
69      *
70      * @param state Shutter value
71      */
72     public void updateState(@Nullable Integer state) {
73         this.state = state;
74         QbusRolHandler handler = this.thingHandler;
75         if (handler != null) {
76             handler.handleStateUpdate(this);
77         }
78     }
79
80     /**
81      * Update the value of the Slats.
82      *
83      * @param Slats slat value
84      */
85     public void updateSlats(@Nullable Integer Slats) {
86         this.slats = Slats;
87         QbusRolHandler handler = this.thingHandler;
88         if (handler != null) {
89             handler.handleStateUpdate(this);
90         }
91     }
92
93     /**
94      * Get the value of the Shutter.
95      *
96      * @return shutter value
97      */
98     public @Nullable Integer getState() {
99         return this.state;
100     }
101
102     /**
103      * Get the value of the Slats.
104      *
105      * @return slats value
106      */
107     public @Nullable Integer getStateSlats() {
108         return this.slats;
109     }
110
111     /**
112      * Sends shutter state to Qbus.
113      *
114      * @throws IOException
115      * @throws InterruptedException
116      */
117     public void execute(int value, String sn) throws InterruptedException, IOException {
118         QbusMessageCmd qCmd = new QbusMessageCmd(sn, "executeStore").withId(this.id).withState(value);
119         QbusCommunication comm = qComm;
120         if (comm != null) {
121             comm.sendMessage(qCmd);
122         }
123     }
124
125     /**
126      * Sends slats state to Qbus.
127      *
128      * @throws IOException
129      * @throws InterruptedException
130      */
131     public void executeSlats(int value, String sn) throws InterruptedException, IOException {
132         QbusMessageCmd qCmd = new QbusMessageCmd(sn, "executeSlats").withId(this.id).withState(value);
133         QbusCommunication comm = qComm;
134         if (comm != null) {
135             comm.sendMessage(qCmd);
136         }
137     }
138 }