2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.homematic.internal.communicator.parser;
15 import java.io.IOException;
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.HmParamsetType;
21 import org.openhab.binding.homematic.internal.model.HmValueType;
22 import org.openhab.binding.homematic.internal.model.TclScriptDataEntry;
23 import org.openhab.binding.homematic.internal.model.TclScriptDataList;
26 * Parses a TclRega script result containing variables and scripts.
28 * @author Gerhard Riegler - Initial contribution
30 public class CcuVariablesAndScriptsParser extends CommonRpcParser<TclScriptDataList, Void> {
31 private HmChannel channel;
33 public CcuVariablesAndScriptsParser(HmChannel channel) {
34 this.channel = channel;
38 public Void parse(TclScriptDataList resultList) throws IOException {
39 if (resultList.getEntries() != null) {
40 for (TclScriptDataEntry entry : resultList.getEntries()) {
41 HmDatapoint dp = channel.getDatapoint(HmParamsetType.VALUES, entry.name);
43 dp.setValue(convertToType(entry.value));
45 dp = new HmDatapoint();
46 dp.setName(entry.name);
47 dp.setInfo(entry.name);
48 dp.setDescription(entry.description);
49 dp.setType(HmValueType.parse(entry.valueType));
50 dp.setValue(convertToType(entry.value));
51 if (dp.isIntegerType()) {
52 dp.setMinValue(toInteger(entry.minValue));
53 dp.setMaxValue(toInteger(entry.maxValue));
55 dp.setMinValue(toDouble(entry.minValue));
56 dp.setMaxValue(toDouble(entry.maxValue));
58 dp.setReadOnly(entry.readOnly);
59 dp.setUnit(entry.unit);
61 String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(entry.options, ";");
62 dp.setOptions(result == null || result.length == 0 ? null : result);
64 if (dp.getOptions() != null) {
66 dp.setMaxValue(dp.getOptions().length - 1);
69 dp.setParamsetType(HmParamsetType.VALUES);
70 channel.addDatapoint(dp);