]> git.basschouten.com Git - openhab-addons.git/blob
f3aff9106bdd1926db381c24b442d8f9a4656923
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.homematic.internal.communicator.parser;
14
15 import java.io.IOException;
16
17 import org.apache.commons.lang.StringUtils;
18 import org.openhab.binding.homematic.internal.model.HmChannel;
19 import org.openhab.binding.homematic.internal.model.HmDatapoint;
20 import org.openhab.binding.homematic.internal.model.HmInterface;
21 import org.openhab.binding.homematic.internal.model.HmParamsetType;
22 import org.openhab.binding.homematic.internal.model.TclScriptDataEntry;
23 import org.openhab.binding.homematic.internal.model.TclScriptDataList;
24
25 /**
26  * Parses parameter descriptions from a CCU script and extracts datapoint metadata.
27  *
28  * @author Gerhard Riegler - Initial contribution
29  */
30 public class CcuParamsetDescriptionParser extends CommonRpcParser<TclScriptDataList, Void> {
31     private HmParamsetType paramsetType;
32     private HmChannel channel;
33     private boolean isHmIpDevice;
34
35     public CcuParamsetDescriptionParser(HmChannel channel, HmParamsetType paramsetType) {
36         this.channel = channel;
37         this.paramsetType = paramsetType;
38         this.isHmIpDevice = channel.getDevice().getHmInterface() == HmInterface.HMIP;
39     }
40
41     @Override
42     public Void parse(TclScriptDataList resultList) throws IOException {
43         if (resultList.getEntries() != null) {
44             for (TclScriptDataEntry entry : resultList.getEntries()) {
45                 HmDatapoint dp = assembleDatapoint(entry.name, entry.unit, entry.valueType,
46                         this.toOptionList(entry.options), convertToType(entry.minValue), convertToType(entry.maxValue),
47                         toInteger(entry.operations), convertToType(entry.value), paramsetType, isHmIpDevice);
48                 channel.addDatapoint(dp);
49             }
50         }
51         return null;
52     }
53
54     private String[] toOptionList(String options) {
55         String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(options, ";");
56         return result == null || result.length == 0 ? null : result;
57     }
58 }