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.qbus.internal.protocol;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.qbus.internal.handler.QbusRolHandler;
22 * The {@link QbusRol} class represents the action Qbus Shutter/Slats output.
24 * @author Koen Schockaert - Initial Contribution
28 public final class QbusRol {
30 private @Nullable QbusCommunication qComm;
34 private @Nullable Integer state;
36 private @Nullable Integer slats;
38 private @Nullable QbusRolHandler thingHandler;
45 * This method should be called if the ThingHandler for the thing corresponding to this Shutter/Slats is
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.
50 * @param qbusRolHandler
52 public void setThingHandler(QbusRolHandler qbusRolHandler) {
53 this.thingHandler = qbusRolHandler;
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..
63 public void setQComm(QbusCommunication qComm) {
68 * Update the value of the Shutter.
70 * @param state Shutter value
72 public void updateState(@Nullable Integer state) {
74 QbusRolHandler handler = this.thingHandler;
75 if (handler != null) {
76 handler.handleStateUpdate(this);
81 * Update the value of the Slats.
83 * @param Slats slat value
85 public void updateSlats(@Nullable Integer Slats) {
87 QbusRolHandler handler = this.thingHandler;
88 if (handler != null) {
89 handler.handleStateUpdate(this);
94 * Get the value of the Shutter.
96 * @return shutter value
98 public @Nullable Integer getState() {
103 * Get the value of the Slats.
105 * @return slats value
107 public @Nullable Integer getStateSlats() {
112 * Sends shutter state to Qbus.
114 * @throws IOException
115 * @throws InterruptedException
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;
121 comm.sendMessage(qCmd);
126 * Sends slats state to Qbus.
128 * @throws IOException
129 * @throws InterruptedException
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;
135 comm.sendMessage(qCmd);