]> git.basschouten.com Git - openhab-addons.git/blob
276edf02f6ae9c5b727aa37de2af0803aa785d71
[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_3F;
14
15 import java.util.function.Function;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.enocean.internal.config.EnOceanChannelTransformationConfig;
20 import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
21 import org.openhab.binding.enocean.internal.messages.ERP1Message;
22 import org.openhab.core.config.core.Configuration;
23 import org.openhab.core.transform.actions.Transformation;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.State;
26 import org.openhab.core.util.HexUtils;
27
28 /**
29  *
30  * @author Daniel Weber - Initial contribution
31  */
32 @NonNullByDefault
33 public class A5_3F_7F_Universal extends _4BSMessage {
34
35     // This class is currently not used => instead use Generic4BS
36
37     public A5_3F_7F_Universal() {
38         super();
39     }
40
41     public A5_3F_7F_Universal(ERP1Message packet) {
42         super(packet);
43     }
44
45     @Override
46     protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
47             Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
48         if (config == null) {
49             logger.error("Command {} could not transformed without proper configuration", command.toString());
50             return;
51         }
52         try {
53             EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class);
54             String c = Transformation.transform(transformationInfo.transformationType,
55                     transformationInfo.transformationFunction, command.toString());
56
57             if (c != null && !c.equals(command.toString())) {
58                 setData(HexUtils.hexToBytes(c));
59             }
60         } catch (IllegalArgumentException e) {
61             logger.debug("Command {} could not transformed", command.toString());
62             throw e;
63         }
64     }
65 }