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