]> git.basschouten.com Git - openhab-addons.git/blob
51ed9306212f08447f3827e11ec756a6a6f9d0c4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.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.library.types.StringType;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.UnDefType;
27
28 /**
29  *
30  * @author Daniel Weber - Initial contribution
31  */
32 public class F6_10_01 extends _RPSMessage {
33
34     public final byte Closed = 0x0F; // xxxx1111
35     public final byte Open1 = 0x0E; // xxxx1110
36     public final byte Open2 = 0x0C; // xxxx1100
37     public final byte Tilted = 0x0D; // xxxx1101
38
39     public F6_10_01() {
40         super();
41     }
42
43     public F6_10_01(ERP1Message packet) {
44         super(packet);
45     }
46
47     @Override
48     protected State convertToStateImpl(String channelId, String channelTypeId,
49             Function<String, State> getCurrentStateFunc, Configuration config) {
50         if (!isValid()) {
51             return UnDefType.UNDEF;
52         }
53
54         byte data = (byte) (bytes[0] & 0x0F);
55
56         // todo localization
57         switch (channelId) {
58             case CHANNEL_WINDOWHANDLESTATE:
59                 if (data == Closed) {
60                     return new StringType("CLOSED");
61                 } else if (data == Tilted) {
62                     return new StringType("TILTED");
63                 } else if (data == Open1 || data == Open2) {
64                     return new StringType("OPEN");
65                 }
66
67             case CHANNEL_CONTACT:
68                 EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
69                 if (data == Closed) {
70                     return c.inverted ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
71                 } else if (data == Tilted) {
72                     return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
73                 } else if (data == Open1 || data == Open2) {
74                     return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
75                 }
76         }
77
78         return UnDefType.UNDEF;
79     }
80
81     @Override
82     protected boolean validateData(byte[] bytes) {
83         return super.validateData(bytes) && getBit(bytes[0], 6) && getBit(bytes[0], 3) && getBit(bytes[0], 2);
84     }
85 }