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.F6_10;
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.eep.Base._RPSMessage;
23 import org.openhab.binding.enocean.internal.messages.ERP1Message;
24 import org.openhab.core.config.core.Configuration;
25 import org.openhab.core.library.types.OpenClosedType;
26 import org.openhab.core.library.types.StringType;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.UnDefType;
32 * @author Daniel Weber - Initial contribution
35 public class F6_10_01 extends _RPSMessage {
37 public static final byte CLOSED = 0x0F; // xxxx1111
38 public static final byte OPEN_1 = 0x0E; // xxxx1110
39 public static final byte OPEN_2 = 0x0C; // xxxx1100
40 public static final byte TILTED = 0x0D; // xxxx1101
46 public F6_10_01(ERP1Message packet) {
51 protected State convertToStateImpl(String channelId, String channelTypeId,
52 Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
53 byte data = (byte) (bytes[0] & 0x0F);
57 case CHANNEL_WINDOWHANDLESTATE:
59 return new StringType("CLOSED");
60 } else if (data == TILTED) {
61 return new StringType("TILTED");
62 } else if (data == OPEN_1 || data == OPEN_2) {
63 return new StringType("OPEN");
67 EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
69 return c.inverted ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
70 } else if (data == TILTED) {
71 return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
72 } else if (data == OPEN_1 || data == OPEN_2) {
73 return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
77 return UnDefType.UNDEF;
81 protected boolean validateData(byte[] bytes) {
82 return super.validateData(bytes) && getBit(bytes[0], 6) && getBit(bytes[0], 3) && getBit(bytes[0], 2);
86 public boolean isValidForTeachIn() {
87 return !getBit(bytes[0], 7) && getBit(bytes[0], 6) && !getBit(bytes[0], 5) && !getBit(bytes[0], 4)
88 && getBit(bytes[0], 3) && getBit(bytes[0], 2);