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.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;
26 * Parses parameter descriptions from a CCU script and extracts datapoint metadata.
28 * @author Gerhard Riegler - Initial contribution
30 public class CcuParamsetDescriptionParser extends CommonRpcParser<TclScriptDataList, Void> {
31 private HmParamsetType paramsetType;
32 private HmChannel channel;
33 private boolean isHmIpDevice;
35 public CcuParamsetDescriptionParser(HmChannel channel, HmParamsetType paramsetType) {
36 this.channel = channel;
37 this.paramsetType = paramsetType;
38 this.isHmIpDevice = channel.getDevice().getHmInterface() == HmInterface.HMIP;
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);
54 private String[] toOptionList(String options) {
55 String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(options, ";");
56 return result == null || result.length == 0 ? null : result;