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;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * The {@link SoulissT11Handler} is responsible for handling commands, which are
33 * sent to one of the channels.
35 * @author Tonino Fazio - Initial contribution
36 * @author Luca Calcaterra - Refactor for OH3
40 public class SoulissT11Handler extends SoulissGenericHandler {
42 private final Logger logger = LoggerFactory.getLogger(SoulissT11Handler.class);
43 private byte t1nRawState = 0xF; // dummy value for first init
44 private byte xSleepTime = 0;
46 public SoulissT11Handler(Thing thing) {
51 public void handleCommand(ChannelUID channelUID, Command command) {
52 if (command instanceof RefreshType) {
53 switch (channelUID.getId()) {
54 case SoulissBindingConstants.ONOFF_CHANNEL:
55 OnOffType val = getOhStateOnOffFromSoulissVal(t1nRawState);
57 updateState(channelUID, val);
61 logger.debug("Unknown channel for T11 thing: {}", channelUID);
64 switch (channelUID.getId()) {
65 case SoulissBindingConstants.ONOFF_CHANNEL:
66 if (command.equals(OnOffType.ON)) {
67 commandSEND(SoulissProtocolConstants.SOULISS_T1N_ON_CMD);
68 } else if (command.equals(OnOffType.OFF)) {
69 commandSEND(SoulissProtocolConstants.SOULISS_T1N_OFF_CMD);
73 case SoulissBindingConstants.SLEEP_CHANNEL:
74 if (command.equals(OnOffType.ON)) {
75 commandSEND((byte) (SoulissProtocolConstants.SOULISS_T1N_TIMED + xSleepTime));
77 updateState(channelUID, OnOffType.OFF);
82 logger.debug("Unknown channel for T11 thing: {}", channelUID);
88 public void initialize() {
91 updateStatus(ThingStatus.UNKNOWN);
93 var configurationMap = getThing().getConfiguration();
94 if (configurationMap.get(SoulissBindingConstants.SLEEP_CHANNEL) != null) {
95 xSleepTime = ((BigDecimal) configurationMap.get(SoulissBindingConstants.SLEEP_CHANNEL)).byteValue();
97 if (configurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND) != null) {
98 bSecureSend = ((Boolean) configurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND)).booleanValue();
103 public byte getExpectedRawState(byte bCmd) {
105 if (bCmd == SoulissProtocolConstants.SOULISS_T1N_ON_CMD) {
106 return SoulissProtocolConstants.SOULISS_T1N_ON_COIL;
107 } else if (bCmd == SoulissProtocolConstants.SOULISS_T1N_OFF_CMD) {
108 return SoulissProtocolConstants.SOULISS_T1N_OFF_COIL;
109 } else if (bCmd >= SoulissProtocolConstants.SOULISS_T1N_TIMED) {
111 return SoulissProtocolConstants.SOULISS_T1N_ON_COIL;
117 void setState(@Nullable PrimitiveType state) {
119 this.updateState(SoulissBindingConstants.SLEEP_CHANNEL, OnOffType.OFF);
120 this.updateState(SoulissBindingConstants.ONOFF_CHANNEL, (OnOffType) state);
125 public void setRawState(byte rawState) {
126 // update Last Status stored time
127 super.setLastStatusStored();
128 // update item state only if it is different from previous
129 if (t1nRawState != rawState) {
130 this.setState(getOhStateOnOffFromSoulissVal(rawState));
132 t1nRawState = rawState;
136 public byte getRawState() {