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.A5_14;
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.config.EnOceanChannelContactConfig;
22 import org.openhab.binding.enocean.internal.messages.ERP1Message;
23 import org.openhab.core.config.core.Configuration;
24 import org.openhab.core.library.types.OpenClosedType;
25 import org.openhab.core.library.types.StringType;
26 import org.openhab.core.types.State;
27 import org.openhab.core.types.UnDefType;
30 * Window/Door-Sensor with States Open/Closed/Tilt, Supply voltage monitor
32 * @author Dominik Krickl-Vorreiter - Initial contribution
35 public class A5_14_09 extends A5_14 {
36 public static final byte CLOSED = (byte) 0x00;
37 public static final byte TILTED = (byte) 0x01;
38 public static final byte OPEN = (byte) 0x03;
40 public A5_14_09(ERP1Message packet) {
44 private State getWindowhandleState() {
45 byte ct = (byte) ((getDB0() & 0x06) >> 1);
49 return new StringType("CLOSED");
51 return new StringType("OPEN");
53 return new StringType("TILTED");
56 return UnDefType.UNDEF;
59 private State getContact(boolean inverted) {
60 byte ct = (byte) ((getDB0() & 0x06) >> 1);
64 return inverted ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
67 return inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
70 return UnDefType.UNDEF;
74 protected State convertToStateImpl(String channelId, String channelTypeId,
75 Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
77 case CHANNEL_WINDOWHANDLESTATE:
78 return getWindowhandleState();
80 EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
81 return getContact(c.inverted);
84 return super.convertToStateImpl(channelId, channelTypeId, getCurrentStateFunc, config);