]> git.basschouten.com Git - openhab-addons.git/blob
128be45716d4bad46838ff55a86d601669e5e826
[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.D2_01;
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.EnOceanBindingConstants;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
22 import org.openhab.core.config.core.Configuration;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.RefreshType;
27 import org.openhab.core.types.State;
28
29 /**
30  *
31  * @author Daniel Weber - Initial contribution
32  */
33 public class D2_01_09_Permundo extends D2_01 {
34
35     public D2_01_09_Permundo() {
36         super();
37     }
38
39     public D2_01_09_Permundo(ERP1Message packet) {
40         super(packet);
41     }
42
43     @Override
44     protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
45             Function<String, State> getCurrentStateFunc, Configuration config) {
46         if (channelId.equals(CHANNEL_REPEATERMODE)) {
47             setRepeaterMode(command);
48         } else if (channelId.equals(CHANNEL_ECOMODE)) {
49             setEcoMode(command);
50         } else {
51             super.convertFromCommandImpl(channelId, channelTypeId, command, getCurrentStateFunc, config);
52         }
53     }
54
55     private void setRepeaterMode(Command command) {
56         if (command == RefreshType.REFRESH) {
57             senderId = null; // make this message invalid as we do not support refresh of repeater status
58         } else if (command instanceof StringType) {
59             switch (((StringType) command).toString()) {
60                 case EnOceanBindingConstants.REPEATERMODE_LEVEL_1:
61                     setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x35, (byte) 0x01);
62                     break;
63                 case EnOceanBindingConstants.REPEATERMODE_LEVEL_2:
64                     setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x35, (byte) 0x02);
65                     break;
66                 default:
67                     setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x35, (byte) 0x00);
68             }
69         }
70     }
71
72     private void setEcoMode(Command command) {
73         if (command == RefreshType.REFRESH) {
74             senderId = null; // make this message invalid as we do not support refresh of ecomode status
75         } else if (command instanceof OnOffType) {
76             if (((OnOffType) command) == OnOffType.ON) {
77                 setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x36, (byte) 0x01);
78             } else {
79                 setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x36, (byte) 0x00);
80             }
81         }
82     }
83 }