2 * Copyright (c) 2010-2022 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
14 package org.openhab.binding.souliss.internal.handler;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
17 import org.openhab.binding.souliss.internal.SoulissBindingConstants;
18 import org.openhab.binding.souliss.internal.SoulissProtocolConstants;
19 import org.openhab.core.library.types.OnOffType;
20 import org.openhab.core.library.types.StringType;
21 import org.openhab.core.thing.ChannelUID;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.thing.ThingStatus;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.PrimitiveType;
26 import org.openhab.core.types.RefreshType;
29 * The {@link SoulissT41Handler} is responsible for handling commands, which are
30 * sent to one of the channels.
32 * @author Luca Remigio - Initial contribution
33 * @author Luca Calcaterra - Refactor for OH3
37 public class SoulissT41Handler extends SoulissGenericHandler {
39 byte t4nRawState = 0xF;
41 public SoulissT41Handler(Thing thing) {
45 // called on every status change or change request
47 public void handleCommand(ChannelUID channelUID, Command command) {
48 if (!(command instanceof RefreshType)) {
49 if (channelUID.getId().equals(SoulissBindingConstants.T4N_ONOFFALARM_CHANNEL)) {
50 if (command instanceof OnOffType) {
51 if (command.equals(OnOffType.OFF)) {
52 commandSEND(SoulissProtocolConstants.SOULISS_T4N_NOT_ARMED);
53 } else if (command.equals(OnOffType.ON)) {
54 commandSEND(SoulissProtocolConstants.SOULISS_T4N_ARMED);
57 } else if ((channelUID.getAsString().split(":")[3].equals(SoulissBindingConstants.T4N_REARMALARM_CHANNEL))
58 && (command instanceof OnOffType) && (command.equals(OnOffType.OFF))) {
59 commandSEND(SoulissProtocolConstants.SOULISS_T4N_REARM);
60 this.setState(StringType.valueOf(SoulissBindingConstants.T4N_REARMOFF_MESSAGE_CHANNEL));
66 public void initialize() {
69 updateStatus(ThingStatus.UNKNOWN);
71 var configurationMap = getThing().getConfiguration();
72 if (configurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND) != null) {
73 bSecureSend = ((Boolean) configurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND)).booleanValue();
77 public void setState(PrimitiveType state) {
78 if (state instanceof OnOffType) {
79 this.updateState(SoulissBindingConstants.T4N_ONOFFALARM_CHANNEL, (OnOffType) state);
80 } else if (state instanceof StringType) {
81 switch (String.valueOf(state)) {
82 case SoulissBindingConstants.T4N_ALARMON_MESSAGE_CHANNEL:
83 this.updateState(SoulissBindingConstants.T4N_STATUSALARM_CHANNEL, OnOffType.ON);
85 case SoulissBindingConstants.T4N_ALARMOFF_MESSAGE_CHANNEL:
86 this.updateState(SoulissBindingConstants.T4N_STATUSALARM_CHANNEL, OnOffType.OFF);
92 // // Reset the rearm button. This is because if pressed, it does not turn off by itself
93 updateState(SoulissBindingConstants.T4N_REARMALARM_CHANNEL, OnOffType.OFF);
97 public void setRawState(byte rawState) {
98 // update Last Status stored time
99 super.setLastStatusStored();
100 // update item state only if it is different from previous
101 if (t4nRawState != rawState) {
103 case SoulissProtocolConstants.SOULISS_T4N_NO_ANTITHEFT:
104 this.setState(OnOffType.OFF);
105 this.setState(StringType.valueOf(SoulissBindingConstants.T4N_ALARMOFF_MESSAGE_CHANNEL));
107 case SoulissProtocolConstants.SOULISS_T4N_ANTITHEFT:
108 this.setState(OnOffType.ON);
109 this.setState(StringType.valueOf(SoulissBindingConstants.T4N_ALARMOFF_MESSAGE_CHANNEL));
111 case SoulissProtocolConstants.SOULISS_T4N_IN_ALARM:
112 this.setState(StringType.valueOf(SoulissBindingConstants.T4N_ALARMON_MESSAGE_CHANNEL));
114 case SoulissProtocolConstants.SOULISS_T4N_ARMED:
115 this.setState(StringType.valueOf(SoulissBindingConstants.T4N_ARMED_MESSAGE_CHANNEL));
121 t4nRawState = rawState;
125 public byte getRawState() {
130 public byte getExpectedRawState(byte bCmd) {
132 if (bCmd == SoulissProtocolConstants.SOULISS_T4N_ARMED) {
133 return SoulissProtocolConstants.SOULISS_T4N_ANTITHEFT;
134 } else if (bCmd == SoulissProtocolConstants.SOULISS_T4N_NOT_ARMED) {
135 return SoulissProtocolConstants.SOULISS_T4N_NO_ANTITHEFT;
136 } else if (bCmd >= SoulissProtocolConstants.SOULISS_T4N_REARM) {
137 return SoulissProtocolConstants.SOULISS_T4N_ANTITHEFT;