]> git.basschouten.com Git - openhab-addons.git/blob
8af7707a2d8d1df70ba8ee2154698026c8288d7f
[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.*;
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.library.types.StringType;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.UnDefType;
29
30 /**
31  *
32  * @author Daniel Weber - Initial contribution
33  */
34 @NonNullByDefault
35 public class F6_10_00 extends _RPSMessage {
36
37     public static final byte CLOSED = (byte) 0xF0; // 1111xxxx
38     public static final byte OPEN_1 = (byte) 0xE0; // 1110xxxx
39     public static final byte OPEN_2 = (byte) 0xC0; // 1100xxxx
40     public static final byte TILTED = (byte) 0xD0; // 1101xxxx
41
42     public F6_10_00() {
43         super();
44     }
45
46     public F6_10_00(ERP1Message packet) {
47         super(packet);
48     }
49
50     @Override
51     protected State convertToStateImpl(String channelId, String channelTypeId,
52             Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
53         byte data = (byte) (bytes[0] & 0xF0);
54
55         // todo localization
56         switch (channelId) {
57             case CHANNEL_WINDOWHANDLESTATE:
58                 if (data == CLOSED) {
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");
64                 }
65
66             case CHANNEL_CONTACT:
67                 EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
68                 if (data == CLOSED) {
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;
74                 }
75         }
76
77         return UnDefType.UNDEF;
78     }
79
80     @Override
81     protected boolean validateData(byte[] bytes) {
82         return super.validateData(bytes) && getBit(bytes[0], 7) && getBit(bytes[0], 6);
83     }
84
85     @Override
86     public boolean isValidForTeachIn() {
87         return t21 && !nu && getBit(bytes[0], 7) && getBit(bytes[0], 6);
88     }
89 }