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.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.OpenClosedType;
23 import org.openhab.core.library.types.StringType;
24 import org.openhab.core.types.State;
25 import org.openhab.core.types.UnDefType;
28 * Window/Door-Sensor with States Open/Closed/Tilt, Supply voltage monitor
30 * @author Dominik Krickl-Vorreiter - Initial contribution
32 public class A5_14_09 extends A5_14 {
33 public final byte CLOSED = (byte) 0x00;
34 public final byte TILTED = (byte) 0x01;
35 public final byte OPEN = (byte) 0x03;
37 public A5_14_09(ERP1Message packet) {
41 private State getWindowhandleState() {
42 byte ct = (byte) ((getDB_0() & 0x06) >> 1);
46 return new StringType("CLOSED");
48 return new StringType("OPEN");
50 return new StringType("TILTED");
53 return UnDefType.UNDEF;
56 private State getContact(boolean inverted) {
57 byte ct = (byte) ((getDB_0() & 0x06) >> 1);
61 return inverted ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
64 return inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
67 return UnDefType.UNDEF;
71 protected State convertToStateImpl(String channelId, String channelTypeId,
72 Function<String, State> getCurrentStateFunc, Configuration config) {
74 case CHANNEL_WINDOWHANDLESTATE:
75 return getWindowhandleState();
77 EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
78 return getContact(c.inverted);
81 return super.convertToStateImpl(channelId, channelTypeId, getCurrentStateFunc, config);