]> git.basschouten.com Git - openhab-addons.git/blob
cd39959ec184ded933e1ff9cdc6e10554470fda2
[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.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.souliss.internal.SoulissBindingConstants;
18 import org.openhab.binding.souliss.internal.SoulissProtocolConstants;
19 import org.openhab.core.library.types.OnOffType;
20 import org.openhab.core.thing.ChannelUID;
21 import org.openhab.core.thing.Thing;
22 import org.openhab.core.thing.ThingStatus;
23 import org.openhab.core.types.Command;
24 import org.openhab.core.types.PrimitiveType;
25 import org.openhab.core.types.RefreshType;
26
27 /**
28  * The {@link SoulissT14Handler} is responsible for handling commands, which are
29  * sent to one of the channels.
30  *
31  * @author Tonino Fazio - Initial contribution
32  * @author Luca Calcaterra - Refactor for OH3
33  */
34
35 @NonNullByDefault
36 public class SoulissT14Handler extends SoulissGenericHandler {
37
38     private byte t1nRawState = 0xF;
39
40     public SoulissT14Handler(Thing thing) {
41         super(thing);
42     }
43
44     @Override
45     public void initialize() {
46         super.initialize();
47
48         updateStatus(ThingStatus.UNKNOWN);
49     }
50
51     @Override
52     public void handleCommand(ChannelUID channelUID, Command command) {
53         if (command instanceof RefreshType) {
54             switch (channelUID.getId()) {
55                 case SoulissBindingConstants.PULSE_CHANNEL:
56                     OnOffType valPulse = getOhStateOnOffFromSoulissVal(t1nRawState);
57                     if (valPulse != null) {
58                         updateState(channelUID, valPulse);
59                     }
60                     break;
61                 default:
62                     break;
63             }
64         } else {
65             switch (channelUID.getId()) {
66                 case SoulissBindingConstants.PULSE_CHANNEL:
67                     if (command.equals(OnOffType.ON)) {
68                         commandSEND(SoulissProtocolConstants.SOULISS_T1N_ON_CMD);
69                     } else if (command.equals(OnOffType.OFF)) {
70                         commandSEND(SoulissProtocolConstants.SOULISS_T1N_OFF_CMD);
71                     }
72                     break;
73                 default:
74                     break;
75             }
76         }
77     }
78
79     public void setState(@Nullable PrimitiveType state) {
80         super.setLastStatusStored();
81         if (state != null) {
82             this.updateState(SoulissBindingConstants.PULSE_CHANNEL, (OnOffType) state);
83         }
84     }
85
86     @Override
87     public void setRawState(byte rawState) {
88         // update Last Status stored time
89         super.setLastStatusStored();
90         // update item state only if it is different from previous
91         if (t1nRawState != rawState) {
92             this.setState(getOhStateOnOffFromSoulissVal(rawState));
93         }
94         t1nRawState = rawState;
95     }
96
97     @Override
98     public byte getRawState() {
99         return t1nRawState;
100     }
101
102     @Override
103     public byte getExpectedRawState(byte bCommand) {
104         // Secure Send is disabled for T14
105         return -1;
106     }
107 }