]> git.basschouten.com Git - openhab-addons.git/blob
b839ceb1bf4e40a2826cbab8176548418f166bfc
[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.A5_14;
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.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.OpenClosedType;
23 import org.openhab.core.types.State;
24
25 /**
26  * Single Input Contact (Window/Door), Supply voltage monitor
27  *
28  * @author Dominik Krickl-Vorreiter - Initial contribution
29  */
30 public class A5_14_01 extends A5_14 {
31
32     public A5_14_01(ERP1Message packet) {
33         super(packet);
34     }
35
36     private State getContact(boolean inverted) {
37         boolean ct = getBit(getDB_0(), 0);
38
39         if (inverted) {
40             return ct ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
41         } else {
42             return ct ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
43         }
44     }
45
46     @Override
47     protected State convertToStateImpl(String channelId, String channelTypeId,
48             Function<String, State> getCurrentStateFunc, Configuration config) {
49         switch (channelId) {
50             case CHANNEL_CONTACT:
51                 EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
52                 return getContact(c.inverted);
53         }
54
55         return super.convertToStateImpl(channelId, channelTypeId, getCurrentStateFunc, config);
56     }
57 }