]> git.basschouten.com Git - openhab-addons.git/blob
6c5b4f440cc74b287feb451639b98bc16c7af858
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.enocean.internal.eep.F6_10;
14
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANNEL_CONTACT;
16
17 import java.util.function.Function;
18
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.types.State;
27 import org.openhab.core.types.UnDefType;
28
29 /**
30  *
31  * @author Holger Englert - Initial contribution
32  */
33 @NonNullByDefault
34 public class F6_10_00_EltakoFPE extends _RPSMessage {
35
36     protected static final byte OPEN = 0x00;
37     protected static final byte CLOSED = 0x10;
38
39     public F6_10_00_EltakoFPE() {
40         super();
41     }
42
43     public F6_10_00_EltakoFPE(ERP1Message packet) {
44         super(packet);
45     }
46
47     @Override
48     protected State convertToStateImpl(String channelId, String channelTypeId,
49             Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
50         if (channelId.equals(CHANNEL_CONTACT)) {
51             EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
52             if (c.inverted) {
53                 return bytes[0] == CLOSED ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
54             } else {
55                 return bytes[0] == CLOSED ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
56             }
57         }
58
59         return UnDefType.UNDEF;
60     }
61
62     @Override
63     protected boolean validateData(byte[] bytes) {
64         // FPE just sends 0b00010000 or 0b00000000 value, so we apply mask 0b11101111
65         return super.validateData(bytes) && ((bytes[0] & (byte) 0xEF) == (byte) 0x00);
66     }
67
68     @Override
69     public boolean isValidForTeachIn() {
70         // just treat CLOSED as teach in
71         return bytes[0] == CLOSED;
72     }
73 }