]> git.basschouten.com Git - openhab-addons.git/blob
de0f496f572850e4576eadcb83e0fd94390db788
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.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;
23
24 /**
25  * Parses parameter descriptions from a CCU script and extracts datapoint metadata.
26  *
27  * @author Gerhard Riegler - Initial contribution
28  */
29 public class CcuParamsetDescriptionParser extends CommonRpcParser<TclScriptDataList, Void> {
30     private HmParamsetType paramsetType;
31     private HmChannel channel;
32     private boolean isHmIpDevice;
33
34     public CcuParamsetDescriptionParser(HmChannel channel, HmParamsetType paramsetType) {
35         this.channel = channel;
36         this.paramsetType = paramsetType;
37         this.isHmIpDevice = channel.getDevice().getHmInterface() == HmInterface.HMIP;
38     }
39
40     @Override
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);
48             }
49         }
50         return null;
51     }
52
53     private String[] toOptionList(String options) {
54         String[] result = options == null ? null : options.split(";");
55         return result == null || result.length == 0 ? null : result;
56     }
57 }