]> git.basschouten.com Git - openhab-addons.git/blob
d338f17afc359dabf0a3c38b0b1b3f703d674d77
[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.binding.souliss.internal.protocol.HalfFloatUtils;
18 import org.openhab.core.library.types.DecimalType;
19 import org.openhab.core.thing.ChannelUID;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.thing.ThingStatus;
22 import org.openhab.core.types.Command;
23 import org.openhab.core.types.PrimitiveType;
24
25 /**
26  * The {@link SoulissT6nHandler} is responsible for handling commands, which are
27  * sent to one of the channels.
28  *
29  * @author Luca Remigio - Initial contribution
30  * @author Luca Calcaterra - Refactor for OH3
31  */
32 @NonNullByDefault
33 public class SoulissT6nHandler extends SoulissGenericHandler {
34
35     private float fSetPointValue = 0xFFFF;
36
37     public SoulissT6nHandler(Thing thing) {
38         super(thing);
39     }
40
41     @Override
42     public void handleCommand(ChannelUID channelUID, Command command) {
43         if (command instanceof DecimalType decimalCommand) {
44             int uu = HalfFloatUtils.fromFloat(decimalCommand.floatValue());
45             byte b2 = (byte) (uu >> 8);
46             byte b1 = (byte) uu;
47             // setpoint command
48             commandSEND(b1, b2);
49         }
50     }
51
52     @Override
53     public void initialize() {
54         super.initialize();
55
56         updateStatus(ThingStatus.UNKNOWN);
57     }
58
59     public void setState(PrimitiveType state) {
60         this.updateState(SoulissBindingConstants.T6N_VALUE_CHANNEL, (DecimalType) state);
61     }
62
63     @Override
64     public void setRawState(byte rawState) {
65         throw new UnsupportedOperationException("Not Implemented, yet.");
66     }
67
68     public void setFloatValue(float valueOf) {
69         super.setLastStatusStored();
70         if (fSetPointValue != valueOf) {
71             this.setState(DecimalType.valueOf(Float.toString(valueOf)));
72             fSetPointValue = valueOf;
73         }
74     }
75
76     @Override
77     public byte getRawState() {
78         throw new UnsupportedOperationException("Not Implemented, yet.");
79     }
80
81     public float getFloatState() {
82         return fSetPointValue;
83     }
84
85     @Override
86     public byte getExpectedRawState(byte bCommand) {
87         return -1;
88     }
89 }