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.core.library.types.OnOffType;
19 import org.openhab.core.library.types.OpenClosedType;
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 SoulissT13Handler} 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 SoulissT13Handler extends SoulissGenericHandler {
38 private byte t1nRawState = 0xF;
40 public SoulissT13Handler(Thing thing) {
45 public void initialize() {
48 updateStatus(ThingStatus.UNKNOWN);
51 public void setState(@Nullable PrimitiveType state) {
52 super.setLastStatusStored();
54 if (state instanceof OnOffType) {
55 this.updateState(SoulissBindingConstants.STATEONOFF_CHANNEL, (OnOffType) state);
58 if (state instanceof OpenClosedType) {
59 this.updateState(SoulissBindingConstants.STATEOPENCLOSE_CHANNEL, (OpenClosedType) state);
65 public void handleCommand(ChannelUID channelUID, Command command) {
66 if (command instanceof RefreshType) {
67 switch (channelUID.getId()) {
68 case SoulissBindingConstants.STATEONOFF_CHANNEL:
69 OnOffType valonOff = getOhStateOnOffFromSoulissVal(t1nRawState);
70 if (valonOff != null) {
71 updateState(channelUID, valonOff);
74 case SoulissBindingConstants.STATEOPENCLOSE_CHANNEL:
75 OpenClosedType valOpenClose = getOhStateOpenCloseFromSoulissVal(t1nRawState);
76 if (valOpenClose != null) {
77 updateState(channelUID, valOpenClose);
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(getOhStateOpenCloseFromSoulissVal(rawState));
93 this.setState(getOhStateOnOffFromSoulissVal(rawState));
95 t1nRawState = rawState;
99 public byte getRawState() {
104 public byte getExpectedRawState(byte bCommand) {
105 // Secure Send is disabled