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