]> git.basschouten.com Git - openhab-addons.git/blob
34606816f458b22a0bdec6985ab26a59fece76ee
[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.D5_00;
14
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANNEL_CONTACT;
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._1BSMessage;
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;
26
27 /**
28  *
29  * @author Daniel Weber - Initial contribution
30  */
31 public class D5_00_01 extends _1BSMessage {
32
33     final byte OPEN = 0 | TeachInBit;
34     final byte CLOSED = 1 | TeachInBit;
35
36     public D5_00_01() {
37         super();
38     }
39
40     public D5_00_01(ERP1Message packet) {
41         super(packet);
42     }
43
44     @Override
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);
49             if (c.inverted) {
50                 return bytes[0] == CLOSED ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
51             } else {
52                 return bytes[0] == CLOSED ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
53             }
54         }
55
56         return UnDefType.UNDEF;
57     }
58 }