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.openhab.binding.enocean.internal.eep.Base._VLDMessage;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.UnDefType;
30 * @author Thomas Lauterbach - Initial contribution
32 public class D2_06_50 extends _VLDMessage {
38 public D2_06_50(ERP1Message packet) {
42 protected State getWindowSashState() {
43 int sashState = bytes[1] & 0x7f;
44 if (sashState == 0x00) {
45 return UnDefType.UNDEF;
47 if (sashState < 0x04) {
48 return new StringType("CLOSED");
49 } else if (sashState < 0x07) {
50 return new StringType("OPEN");
51 } else if (sashState < 0x0A) {
52 return new StringType("TILTED");
55 return UnDefType.UNDEF;
58 protected State getWindowHandleState() {
59 int handleState = bytes[1] & 0x7f;
60 if (handleState == 0x01 || handleState == 0x04 || handleState == 0x07) {
61 return new StringType("CLOSED");
62 } else if (handleState == 0x02 || handleState == 0x05 || handleState == 0x08) {
63 return new StringType("OPEN");
64 } else if (handleState == 0x03 || handleState == 0x06 || handleState == 0x09) {
65 return new StringType("TILTED");
68 return UnDefType.UNDEF;
71 protected State getCalibrationState() {
72 int calibrationState = bytes[1] >>> 6;
73 if (calibrationState == 0x00) {
74 return new StringType("OK");
75 } else if (calibrationState == 0x01) {
76 return new StringType("ERROR");
77 } else if (calibrationState == 0x02) {
78 return new StringType("INVALID");
81 return UnDefType.UNDEF;
84 protected State getCalibrationStep() {
85 int calibrationStep = bytes[1] & 0x3F;
86 switch (calibrationStep) {
88 return new StringType("NONE");
90 return new StringType("SASH CLOSED HANDLE CLOSED");
92 return new StringType("SASH CLOSED HANDLE OPEN");
94 return new StringType("SASH CLOSED HANDLE TILTED");
96 return new StringType("SASH OPEN HANDLE CLOSED");
98 return new StringType("SASH OPEN HANDLE OPEN");
100 return new StringType("SASH OPEN HANDLE TILTED");
102 return new StringType("SASH TILTED HANDLE CLOSED");
104 return new StringType("SASH TILTED HANDLE OPEN");
106 return new StringType("SASH TILTED HANDLE TILTED");
108 return new StringType("FRAME MAGNET VALIDATION");
111 return UnDefType.UNDEF;
115 protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
116 Configuration config) {
119 if (bytes[0] == 0x02) {
121 case CHANNEL_WINDOWBREACHEVENT:
122 if (bytes[1] == 0x01) {
131 public State convertToStateImpl(String channelId, String channelTypeId, Function<String, State> getCurrentStateFunc,
132 Configuration config) {
135 if (bytes[0] == 0x01) {
137 case CHANNEL_WINDOWSASHSTATE:
138 return getWindowSashState();
139 case CHANNEL_WINDOWHANDLESTATE:
140 return getWindowHandleState();
141 case CHANNEL_BATTERY_LEVEL:
142 return new DecimalType(bytes[6] & 0x7f);
143 case CHANNEL_BATTERYLOW:
144 return getBit(bytes[6], 7) ? OnOffType.ON : OnOffType.OFF;
149 if (bytes[0] == 0x11) {
151 case CHANNEL_WINDOWCALIBRATIONSTATE:
152 return getCalibrationState();
153 case CHANNEL_WINDOWCALIBRATIONSTEP:
154 return getCalibrationStep();
158 return UnDefType.UNDEF;