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.HmInterface;
20 import org.openhab.binding.homematic.internal.model.HmParamsetType;
21 import org.openhab.binding.homematic.internal.model.TclScriptDataEntry;
22 import org.openhab.binding.homematic.internal.model.TclScriptDataList;
25 * Parses parameter descriptions from a CCU script and extracts datapoint metadata.
27 * @author Gerhard Riegler - Initial contribution
29 public class CcuParamsetDescriptionParser extends CommonRpcParser<TclScriptDataList, Void> {
30 private HmParamsetType paramsetType;
31 private HmChannel channel;
32 private boolean isHmIpDevice;
34 public CcuParamsetDescriptionParser(HmChannel channel, HmParamsetType paramsetType) {
35 this.channel = channel;
36 this.paramsetType = paramsetType;
37 this.isHmIpDevice = channel.getDevice().getHmInterface() == HmInterface.HMIP;
41 public Void parse(TclScriptDataList resultList) throws IOException {
42 if (resultList.getEntries() != null) {
43 for (TclScriptDataEntry entry : resultList.getEntries()) {
44 HmDatapoint dp = assembleDatapoint(entry.name, entry.unit, entry.valueType,
45 this.toOptionList(entry.options), convertToType(entry.minValue), convertToType(entry.maxValue),
46 toInteger(entry.operations), convertToType(entry.value), paramsetType, isHmIpDevice);
47 channel.addDatapoint(dp);
53 private String[] toOptionList(String options) {
54 String[] result = options == null ? null : options.split(";");
55 return result == null || result.length == 0 ? null : result;