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