]> git.basschouten.com Git - openhab-addons.git/blob
62f8b665332d8492216ba5f9cb0b89fc4c881e94
[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.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
51         byte data = (byte) (bytes[0] & 0x0F);
52
53         // todo localization
54         switch (channelId) {
55             case CHANNEL_WINDOWHANDLESTATE:
56                 if (data == Closed) {
57                     return new StringType("CLOSED");
58                 } else if (data == Tilted) {
59                     return new StringType("TILTED");
60                 } else if (data == Open1 || data == Open2) {
61                     return new StringType("OPEN");
62                 }
63
64             case CHANNEL_CONTACT:
65                 EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
66                 if (data == Closed) {
67                     return c.inverted ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
68                 } else if (data == Tilted) {
69                     return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
70                 } else if (data == Open1 || data == Open2) {
71                     return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
72                 }
73         }
74
75         return UnDefType.UNDEF;
76     }
77
78     @Override
79     protected boolean validateData(byte[] bytes) {
80         return super.validateData(bytes) && getBit(bytes[0], 6) && getBit(bytes[0], 3) && getBit(bytes[0], 2);
81     }
82
83     @Override
84     public boolean isValidForTeachIn() {
85         return !getBit(bytes[0], 7) && getBit(bytes[0], 6) && !getBit(bytes[0], 5) && !getBit(bytes[0], 4)
86                 && getBit(bytes[0], 3) && getBit(bytes[0], 2);
87     }
88 }