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.eclipse.jdt.annotation.Nullable;
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.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;
25 import org.openhab.core.types.RefreshType;
28 * The {@link SoulissT14Handler} is responsible for handling commands, which are
29 * sent to one of the channels.
31 * @author Tonino Fazio - Initial contribution
32 * @author Luca Calcaterra - Refactor for OH3
36 public class SoulissT14Handler extends SoulissGenericHandler {
38 private byte t1nRawState = 0xF;
40 public SoulissT14Handler(Thing thing) {
45 public void initialize() {
48 updateStatus(ThingStatus.UNKNOWN);
52 public void handleCommand(ChannelUID channelUID, Command command) {
53 if (command instanceof RefreshType) {
54 switch (channelUID.getId()) {
55 case SoulissBindingConstants.PULSE_CHANNEL:
56 OnOffType valPulse = getOhStateOnOffFromSoulissVal(t1nRawState);
57 if (valPulse != null) {
58 updateState(channelUID, valPulse);
65 switch (channelUID.getId()) {
66 case SoulissBindingConstants.PULSE_CHANNEL:
67 if (command.equals(OnOffType.ON)) {
68 commandSEND(SoulissProtocolConstants.SOULISS_T1N_ON_CMD);
69 } else if (command.equals(OnOffType.OFF)) {
70 commandSEND(SoulissProtocolConstants.SOULISS_T1N_OFF_CMD);
79 public void setState(@Nullable PrimitiveType state) {
80 super.setLastStatusStored();
82 this.updateState(SoulissBindingConstants.PULSE_CHANNEL, (OnOffType) state);
87 public void setRawState(byte rawState) {
88 // update Last Status stored time
89 super.setLastStatusStored();
90 // update item state only if it is different from previous
91 if (t1nRawState != rawState) {
92 this.setState(getOhStateOnOffFromSoulissVal(rawState));
94 t1nRawState = rawState;
98 public byte getRawState() {
103 public byte getExpectedRawState(byte bCommand) {
104 // Secure Send is disabled for T14