2 * Copyright (c) 2010-2023 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.openhab.binding.homematic.internal.model.HmChannel;
18 import org.openhab.binding.homematic.internal.model.HmDatapoint;
19 import org.openhab.binding.homematic.internal.model.HmParamsetType;
20 import org.openhab.binding.homematic.internal.model.HmValueType;
21 import org.openhab.binding.homematic.internal.model.TclScriptDataEntry;
22 import org.openhab.binding.homematic.internal.model.TclScriptDataList;
25 * Parses a TclRega script result containing variables and scripts.
27 * @author Gerhard Riegler - Initial contribution
29 public class CcuVariablesAndScriptsParser extends CommonRpcParser<TclScriptDataList, Void> {
30 private HmChannel channel;
32 public CcuVariablesAndScriptsParser(HmChannel channel) {
33 this.channel = channel;
37 public Void parse(TclScriptDataList resultList) throws IOException {
38 if (resultList.getEntries() != null) {
39 for (TclScriptDataEntry entry : resultList.getEntries()) {
40 HmDatapoint dp = channel.getDatapoint(HmParamsetType.VALUES, entry.name);
42 dp.setValue(convertToType(entry.value));
44 dp = new HmDatapoint();
45 dp.setName(entry.name);
46 dp.setInfo(entry.name);
47 dp.setDescription(entry.description);
48 dp.setType(HmValueType.parse(entry.valueType));
49 dp.setValue(convertToType(entry.value));
50 if (dp.isIntegerType()) {
51 dp.setMinValue(toInteger(entry.minValue));
52 dp.setMaxValue(toInteger(entry.maxValue));
53 } else if (dp.isFloatType()) {
54 dp.setMinValue(toDouble(entry.minValue));
55 dp.setMaxValue(toDouble(entry.maxValue));
57 dp.setReadOnly(entry.readOnly);
58 dp.setUnit(entry.unit);
59 String[] result = entry.options == null ? null : entry.options.split(";");
60 dp.setOptions(result == null || result.length == 0 ? null : result);
62 if (dp.getOptions() != null) {
64 dp.setMaxValue(dp.getOptions().length - 1);
67 dp.setParamsetType(HmParamsetType.VALUES);
68 channel.addDatapoint(dp);