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.enocean.internal.eep.D2_06;
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
17 import java.util.function.Function;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
22 import org.openhab.binding.enocean.internal.messages.ERP1Message;
23 import org.openhab.core.config.core.Configuration;
24 import org.openhab.core.library.types.DecimalType;
25 import org.openhab.core.library.types.OnOffType;
26 import org.openhab.core.library.types.StringType;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.UnDefType;
32 * @author Thomas Lauterbach - Initial contribution
35 public class D2_06_50 extends _VLDMessage {
41 public D2_06_50(ERP1Message packet) {
45 protected State getWindowSashState() {
46 int sashState = bytes[1] & 0x7f;
47 if (sashState == 0x00) {
48 return UnDefType.UNDEF;
50 if (sashState < 0x04) {
51 return new StringType("CLOSED");
52 } else if (sashState < 0x07) {
53 return new StringType("OPEN");
54 } else if (sashState < 0x0A) {
55 return new StringType("TILTED");
58 return UnDefType.UNDEF;
61 protected State getWindowHandleState() {
62 int handleState = bytes[1] & 0x7f;
63 if (handleState == 0x01 || handleState == 0x04 || handleState == 0x07) {
64 return new StringType("CLOSED");
65 } else if (handleState == 0x02 || handleState == 0x05 || handleState == 0x08) {
66 return new StringType("OPEN");
67 } else if (handleState == 0x03 || handleState == 0x06 || handleState == 0x09) {
68 return new StringType("TILTED");
71 return UnDefType.UNDEF;
74 protected State getCalibrationState() {
75 int calibrationState = bytes[1] >>> 6;
76 if (calibrationState == 0x00) {
77 return new StringType("OK");
78 } else if (calibrationState == 0x01) {
79 return new StringType("ERROR");
80 } else if (calibrationState == 0x02) {
81 return new StringType("INVALID");
84 return UnDefType.UNDEF;
87 protected State getCalibrationStep() {
88 int calibrationStep = bytes[1] & 0x3F;
89 switch (calibrationStep) {
91 return new StringType("NONE");
93 return new StringType("SASH CLOSED HANDLE CLOSED");
95 return new StringType("SASH CLOSED HANDLE OPEN");
97 return new StringType("SASH CLOSED HANDLE TILTED");
99 return new StringType("SASH OPEN HANDLE CLOSED");
101 return new StringType("SASH OPEN HANDLE OPEN");
103 return new StringType("SASH OPEN HANDLE TILTED");
105 return new StringType("SASH TILTED HANDLE CLOSED");
107 return new StringType("SASH TILTED HANDLE OPEN");
109 return new StringType("SASH TILTED HANDLE TILTED");
111 return new StringType("FRAME MAGNET VALIDATION");
114 return UnDefType.UNDEF;
118 protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
119 Configuration config) {
121 if (bytes[0] == 0x02) {
123 case CHANNEL_WINDOWBREACHEVENT:
124 if (bytes[1] == 0x01) {
133 public State convertToStateImpl(String channelId, String channelTypeId, Function<String, State> getCurrentStateFunc,
134 Configuration config) {
136 if (bytes[0] == 0x01) {
138 case CHANNEL_WINDOWSASHSTATE:
139 return getWindowSashState();
140 case CHANNEL_WINDOWHANDLESTATE:
141 return getWindowHandleState();
142 case CHANNEL_BATTERY_LEVEL:
143 return new DecimalType(bytes[6] & 0x7f);
144 case CHANNEL_BATTERYLOW:
145 return getBit(bytes[6], 7) ? OnOffType.ON : OnOffType.OFF;
150 if (bytes[0] == 0x11) {
152 case CHANNEL_WINDOWCALIBRATIONSTATE:
153 return getCalibrationState();
154 case CHANNEL_WINDOWCALIBRATIONSTEP:
155 return getCalibrationStep();
159 return UnDefType.UNDEF;