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.QbusBistabielHandler;
22 * The {@link QbusBistabiel} class represents the Qbus BISTABIEL output.
24 * @author Koen Schockaert - Initial Contribution
28 public final class QbusBistabiel {
30 private @Nullable QbusCommunication qComm;
34 private @Nullable Integer state;
36 private @Nullable QbusBistabielHandler thingHandler;
38 QbusBistabiel(Integer id) {
43 * This method should be called if the ThingHandler for the thing corresponding to this bistabiel is initialized.
44 * It keeps a record of the thing handler in this object so the thing can be updated when
45 * the bistable output receives an update from the Qbus client.
49 public void setThingHandler(QbusBistabielHandler handler) {
50 this.thingHandler = handler;
54 * This method sets a pointer to the qComm BISTABIEL of class {@link QbusCommuncation}.
55 * This is then used to be able to call back the sendCommand method in this class to send a command to the
60 public void setQComm(QbusCommunication qComm) {
65 * Update the value of the Bistabiel.
69 void updateState(@Nullable Integer state) {
71 QbusBistabielHandler handler = this.thingHandler;
72 if (handler != null) {
73 handler.handleStateUpdate(this);
78 * Get the value of the Bistabiel.
82 public @Nullable Integer getState() {
87 * Sends Bistabiel state to Qbus.
91 * @throws InterruptedException
94 public void execute(int value, String sn) throws InterruptedException, IOException {
95 QbusMessageCmd qCmd = new QbusMessageCmd(sn, "executeBistabiel").withId(this.id).withState(value);
96 QbusCommunication comm = this.qComm;
98 comm.sendMessage(qCmd);