]> git.basschouten.com Git - openhab-addons.git/blob
e30c80c0e0105343cf250714d6435d4b1e1aa272
[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.core.library.types.OnOffType;
19 import org.openhab.core.library.types.OpenClosedType;
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 SoulissT13Handler} 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 SoulissT13Handler extends SoulissGenericHandler {
37
38     private byte t1nRawState = 0xF;
39
40     public SoulissT13Handler(Thing thing) {
41         super(thing);
42     }
43
44     @Override
45     public void initialize() {
46         super.initialize();
47
48         updateStatus(ThingStatus.UNKNOWN);
49     }
50
51     public void setState(@Nullable PrimitiveType state) {
52         super.setLastStatusStored();
53         if (state != null) {
54             if (state instanceof OnOffType onOffCommand) {
55                 this.updateState(SoulissBindingConstants.STATEONOFF_CHANNEL, onOffCommand);
56             }
57
58             if (state instanceof OpenClosedType openClosedCommand) {
59                 this.updateState(SoulissBindingConstants.STATEOPENCLOSE_CHANNEL, openClosedCommand);
60             }
61         }
62     }
63
64     @Override
65     public void handleCommand(ChannelUID channelUID, Command command) {
66         if (command instanceof RefreshType) {
67             switch (channelUID.getId()) {
68                 case SoulissBindingConstants.STATEONOFF_CHANNEL:
69                     OnOffType valonOff = getOhStateOnOffFromSoulissVal(t1nRawState);
70                     if (valonOff != null) {
71                         updateState(channelUID, valonOff);
72                     }
73                     break;
74                 case SoulissBindingConstants.STATEOPENCLOSE_CHANNEL:
75                     OpenClosedType valOpenClose = getOhStateOpenCloseFromSoulissVal(t1nRawState);
76                     if (valOpenClose != null) {
77                         updateState(channelUID, valOpenClose);
78                     }
79                     break;
80                 default:
81                     break;
82             }
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(getOhStateOpenCloseFromSoulissVal(rawState));
93             this.setState(getOhStateOnOffFromSoulissVal(rawState));
94         }
95         t1nRawState = rawState;
96     }
97
98     @Override
99     public byte getRawState() {
100         return 0;
101     }
102
103     @Override
104     public byte getExpectedRawState(byte bCommand) {
105         // Secure Send is disabled
106         return -1;
107     }
108 }