]> git.basschouten.com Git - openhab-addons.git/blob
779d36db6df16489dff37ec61642196050c98f96
[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.HmDatapointInfo;
20 import org.openhab.binding.homematic.internal.model.TclScriptDataEntry;
21 import org.openhab.binding.homematic.internal.model.TclScriptDataList;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * Parses a TclRega script result containing datapoint values for a channel.
27  *
28  * @author Gerhard Riegler - Initial contribution
29  */
30 public class CcuValueParser extends CommonRpcParser<TclScriptDataList, Void> {
31     private final Logger logger = LoggerFactory.getLogger(CcuValueParser.class);
32
33     private HmChannel channel;
34
35     public CcuValueParser(HmChannel channel) {
36         this.channel = channel;
37     }
38
39     @Override
40     public Void parse(TclScriptDataList resultList) throws IOException {
41         if (resultList.getEntries() != null) {
42             for (TclScriptDataEntry entry : resultList.getEntries()) {
43                 HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, entry.name);
44                 HmDatapoint dp = channel.getDatapoint(dpInfo);
45                 if (dp != null) {
46                     dp.setValue(convertToType(dp, entry.value));
47                     adjustRssiValue(dp);
48                 } else {
49                     // should never happen, but in case ...
50                     logger.warn("Can't set value for datapoint '{}'", dpInfo);
51                 }
52             }
53         }
54         return null;
55     }
56 }