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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.souliss.internal.SoulissBindingConstants;
17 import org.openhab.binding.souliss.internal.SoulissProtocolConstants;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.library.types.StringType;
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;
27 * The {@link SoulissT42Handler} is responsible for handling commands, which are
28 * sent to one of the channels.
30 * @author Tonino Fazio - Initial contribution
31 * @author Luca Calcaterra - Refactor for OH3
35 public class SoulissT42Handler extends SoulissGenericHandler {
36 byte t4nRawState = 0xF;
38 public SoulissT42Handler(Thing thing) {
42 // called on every status change or change request
44 public void handleCommand(ChannelUID channelUID, Command command) {
45 if ((channelUID.getAsString().split(":")[3].equals(SoulissBindingConstants.T4N_REARMALARM_CHANNEL))
46 && (command instanceof OnOffType) && (command.equals(OnOffType.ON))) {
47 commandSEND(SoulissProtocolConstants.SOULISS_T4N_REARM);
48 this.setState(StringType.valueOf(SoulissBindingConstants.T4N_REARMOFF_MESSAGE_CHANNEL));
53 public void initialize() {
56 updateStatus(ThingStatus.UNKNOWN);
58 var configurationMap = getThing().getConfiguration();
59 if (configurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND) != null) {
60 bSecureSend = ((Boolean) configurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND)).booleanValue();
64 public void setState(PrimitiveType state) {
65 if (state instanceof StringType) {
66 switch (String.valueOf(state)) {
67 case SoulissBindingConstants.T4N_ALARMON_MESSAGE_CHANNEL:
68 this.updateState(SoulissBindingConstants.T4N_STATUSALARM_CHANNEL, OnOffType.ON);
70 case SoulissBindingConstants.T4N_ALARMOFF_MESSAGE_CHANNEL:
71 this.updateState(SoulissBindingConstants.T4N_STATUSALARM_CHANNEL, OnOffType.OFF);
77 // Reset the rearm button. This is because if pressed, it does not turn off by itself
78 updateState(SoulissBindingConstants.T4N_REARMALARM_CHANNEL, OnOffType.OFF);
80 super.setLastStatusStored();
84 public void setRawState(byte rawState) {
85 // update Last Status stored time
86 super.setLastStatusStored();
87 // update item state only if it is different from previous
88 if (t4nRawState != rawState) {
89 OnOffType onOffVal = getOhStateOnOffFromSoulissVal(rawState);
90 if (onOffVal != null) {
91 this.setState(onOffVal);
94 t4nRawState = rawState;
98 public byte getRawState() {
103 public byte getExpectedRawState(byte bCmd) {
104 if ((bSecureSend) && (bCmd == SoulissProtocolConstants.SOULISS_T4N_REARM)) {
105 return SoulissProtocolConstants.SOULISS_T4N_ANTITHEFT;