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.souliss.internal.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.souliss.internal.SoulissBindingConstants;
17 import org.openhab.core.library.types.OpenClosedType;
18 import org.openhab.core.thing.ChannelUID;
19 import org.openhab.core.thing.Thing;
20 import org.openhab.core.thing.ThingStatus;
21 import org.openhab.core.types.Command;
24 * The {@link SoulissT1AHandler} is responsible for handling commands, which are
25 * sent to one of the channels.
27 * @author Luca Remigio - Initial contribution
28 * @author Luca Calcaterra - Refactor for OH3
31 public class SoulissT1AHandler extends SoulissGenericHandler {
32 byte t1nRawState = 0xF;
34 public SoulissT1AHandler(Thing thing) {
39 public void handleCommand(ChannelUID channelUID, Command command) {
40 throw new UnsupportedOperationException("Unsupported operation. Read Only");
44 public void initialize() {
47 updateStatus(ThingStatus.UNKNOWN);
50 private OpenClosedType getTypeFromBool(boolean value) {
52 return OpenClosedType.CLOSED;
54 return OpenClosedType.OPEN;
57 private boolean getBitState(int value, int bit) {
58 return ((value & (1L << bit)) != 0);
62 public void setRawState(byte rawState) {
63 // update Last Status stored time
64 super.setLastStatusStored();
65 // update item state only if it is different from previous
66 if (t1nRawState != rawState) {
67 this.updateState(SoulissBindingConstants.T1A_1_CHANNEL, getTypeFromBool(getBitState(rawState, 0)));
68 this.updateState(SoulissBindingConstants.T1A_2_CHANNEL, getTypeFromBool(getBitState(rawState, 1)));
69 this.updateState(SoulissBindingConstants.T1A_3_CHANNEL, getTypeFromBool(getBitState(rawState, 2)));
70 this.updateState(SoulissBindingConstants.T1A_4_CHANNEL, getTypeFromBool(getBitState(rawState, 3)));
71 this.updateState(SoulissBindingConstants.T1A_5_CHANNEL, getTypeFromBool(getBitState(rawState, 4)));
72 this.updateState(SoulissBindingConstants.T1A_6_CHANNEL, getTypeFromBool(getBitState(rawState, 5)));
73 this.updateState(SoulissBindingConstants.T1A_7_CHANNEL, getTypeFromBool(getBitState(rawState, 6)));
74 this.updateState(SoulissBindingConstants.T1A_8_CHANNEL, getTypeFromBool(getBitState(rawState, 7)));
76 t1nRawState = rawState;
80 public byte getRawState() {
85 public byte getExpectedRawState(byte bCommand) {
86 // Secure Send is disabled