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.CHANNEL_CONTACT;
17 import java.util.function.Function;
19 import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig;
20 import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
21 import org.openhab.binding.enocean.internal.messages.ERP1Message;
22 import org.openhab.core.config.core.Configuration;
23 import org.openhab.core.library.types.OpenClosedType;
24 import org.openhab.core.types.State;
25 import org.openhab.core.types.UnDefType;
29 * @author Holger Englert - Initial contribution
31 public class F6_10_00_EltakoFPE extends _RPSMessage {
33 final byte OPEN = 0x00;
34 final byte CLOSED = 0x10;
36 public F6_10_00_EltakoFPE() {
40 public F6_10_00_EltakoFPE(ERP1Message packet) {
45 protected State convertToStateImpl(String channelId, String channelTypeId,
46 Function<String, State> getCurrentStateFunc, Configuration config) {
47 if (channelId.equals(CHANNEL_CONTACT)) {
48 EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
50 return bytes[0] == CLOSED ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
52 return bytes[0] == CLOSED ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
56 return UnDefType.UNDEF;
60 protected boolean validateData(byte[] bytes) {
61 // FPE just sends 0b00010000 or 0b00000000 value, so we apply mask 0b11101111
62 return super.validateData(bytes) && ((bytes[0] & (byte) 0xEF) == (byte) 0x00);
66 public boolean isValidForTeachIn() {
67 // just treat CLOSED as teach in
68 return bytes[0] == CLOSED;