]> git.basschouten.com Git - openhab-addons.git/blob
281a958192abecaaff8bdd4d8bded9ab1edf7a8a
[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.Base;
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.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.library.types.OpenClosedType;
24 import org.openhab.core.library.types.PercentType;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.State;
27 import org.openhab.core.types.UnDefType;
28
29 /**
30  *
31  * @author Daniel Weber - Initial contribution
32  */
33 public class PTM200Message extends _RPSMessage {
34
35     static final byte On = 0x70;
36     static final byte Off = 0x50;
37     static final byte Up = 0x70;
38     static final byte Down = 0x50;
39     static final byte Open = (byte) 0xE0;
40     static final byte Closed = (byte) 0xF0;
41
42     public PTM200Message() {
43         super();
44     }
45
46     public PTM200Message(ERP1Message packet) {
47         super(packet);
48     }
49
50     @Override
51     protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
52             Function<String, State> getCurrentStateFunc, Configuration config) {
53     }
54
55     @Override
56     protected State convertToStateImpl(String channelId, String channelTypeId,
57             Function<String, State> getCurrentStateFunc, Configuration config) {
58
59         switch (channelId) {
60             case CHANNEL_GENERAL_SWITCHING:
61                 return bytes[0] == On ? OnOffType.ON : OnOffType.OFF;
62             case CHANNEL_ROLLERSHUTTER:
63                 return bytes[0] == Up ? PercentType.ZERO : (bytes[0] == Down ? PercentType.HUNDRED : UnDefType.UNDEF);
64             case CHANNEL_CONTACT:
65                 EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
66                 if (c.inverted) {
67                     return bytes[0] == Open ? OpenClosedType.CLOSED
68                             : (bytes[0] == Closed ? OpenClosedType.OPEN : UnDefType.UNDEF);
69                 } else {
70                     return bytes[0] == Open ? OpenClosedType.OPEN
71                             : (bytes[0] == Closed ? OpenClosedType.CLOSED : UnDefType.UNDEF);
72                 }
73         }
74
75         return UnDefType.UNDEF;
76     }
77
78     @Override
79     public boolean isValidForTeachIn() {
80         return false;
81     }
82 }