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 java.math.BigDecimal;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.souliss.internal.SoulissBindingConstants;
20 import org.openhab.binding.souliss.internal.SoulissProtocolConstants;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingStatus;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.PrimitiveType;
27 import org.openhab.core.types.RefreshType;
30 * The {@link SoulissT18Handler} is responsible for handling commands, which are
31 * sent to one of the channels.
33 * @author Tonino Fazio - Initial contribution
34 * @author Luca Calcaterra - Refactor for OH3
38 public class SoulissT18Handler extends SoulissGenericHandler {
40 byte t1nRawState = 0xF;
44 public void initialize() {
47 updateStatus(ThingStatus.UNKNOWN);
49 var configurationMap = getThing().getConfiguration();
51 if (configurationMap.get(SoulissBindingConstants.SLEEP_CHANNEL) != null) {
52 xSleepTime = ((BigDecimal) configurationMap.get(SoulissBindingConstants.SLEEP_CHANNEL)).byteValue();
54 if (configurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND) != null) {
55 bSecureSend = ((Boolean) configurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND)).booleanValue();
59 public SoulissT18Handler(Thing thing) {
64 public void handleCommand(ChannelUID channelUID, Command command) {
65 if (command instanceof RefreshType) {
66 switch (channelUID.getId()) {
67 case SoulissBindingConstants.PULSE_CHANNEL:
68 OnOffType valPulse = getOhStateOnOffFromSoulissVal(t1nRawState);
69 if (valPulse != null) {
70 updateState(channelUID, valPulse);
77 switch (channelUID.getId()) {
78 case SoulissBindingConstants.ONOFF_CHANNEL:
79 if (command.equals(OnOffType.ON)) {
80 commandSEND(SoulissProtocolConstants.SOULISS_T1N_ON_CMD);
81 } else if (command.equals(OnOffType.OFF)) {
82 commandSEND(SoulissProtocolConstants.SOULISS_T1N_OFF_CMD);
91 void setState(@Nullable PrimitiveType state) {
93 updateState(SoulissBindingConstants.SLEEP_CHANNEL, OnOffType.OFF);
94 this.updateState(SoulissBindingConstants.ONOFF_CHANNEL, (OnOffType) state);
99 public void setRawState(byte rawState) {
100 // update Last Status stored time
101 super.setLastStatusStored();
102 // update item state only if it is different from previous
103 if (t1nRawState != rawState) {
104 this.setState(getOhStateOnOffFromSoulissVal(rawState));
106 t1nRawState = rawState;
110 public byte getRawState() {
115 public byte getExpectedRawState(byte bCmd) {
117 if (bCmd == SoulissProtocolConstants.SOULISS_T1N_ON_CMD) {
118 return SoulissProtocolConstants.SOULISS_T1N_ON_FEEDBACK;
119 } else if (bCmd == SoulissProtocolConstants.SOULISS_T1N_OFF_CMD) {
120 return SoulissProtocolConstants.SOULISS_T1N_OFF_FEEDBACK;
121 } else if (bCmd >= SoulissProtocolConstants.SOULISS_T1N_TIMED) {
123 return SoulissProtocolConstants.SOULISS_T1N_ON_FEEDBACK;