]> git.basschouten.com Git - openhab-addons.git/blob
1ae6a91aab918c4b5ec480c3b5518b0402e16fd5
[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.souliss.internal.handler;
14
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;
22
23 /**
24  * The {@link SoulissT1AHandler} is responsible for handling commands, which are
25  * sent to one of the channels.
26  *
27  * @author Luca Remigio - Initial contribution
28  * @author Luca Calcaterra - Refactor for OH3
29  */
30 @NonNullByDefault
31 public class SoulissT1AHandler extends SoulissGenericHandler {
32     byte t1nRawState = 0xF;
33
34     public SoulissT1AHandler(Thing thing) {
35         super(thing);
36     }
37
38     @Override
39     public void handleCommand(ChannelUID channelUID, Command command) {
40         throw new UnsupportedOperationException("Unsupported operation. Read Only");
41     }
42
43     @Override
44     public void initialize() {
45         super.initialize();
46
47         updateStatus(ThingStatus.UNKNOWN);
48     }
49
50     private OpenClosedType getTypeFromBool(boolean value) {
51         if (!value) {
52             return OpenClosedType.CLOSED;
53         }
54         return OpenClosedType.OPEN;
55     }
56
57     private boolean getBitState(int value, int bit) {
58         return ((value & (1L << bit)) != 0);
59     }
60
61     @Override
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)));
75         }
76         t1nRawState = rawState;
77     }
78
79     @Override
80     public byte getRawState() {
81         return t1nRawState;
82     }
83
84     @Override
85     public byte getExpectedRawState(byte bCommand) {
86         // Secure Send is disabled
87         return -1;
88     }
89 }