]> git.basschouten.com Git - openhab-addons.git/blob
5254b2f586ad1e41fcc8ae3a130a8996661d1fcf
[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 import java.util.Map;
17
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.HmDatapointInfo;
21 import org.openhab.binding.homematic.internal.model.HmInterface;
22 import org.openhab.binding.homematic.internal.model.HmParamsetType;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Parses a paramset message and extracts datapoint values.
28  *
29  * @author Gerhard Riegler - Initial contribution
30  */
31 public class GetParamsetParser extends CommonRpcParser<Object[], Void> {
32     private final Logger logger = LoggerFactory.getLogger(GetParamsetParser.class);
33
34     private HmChannel channel;
35     private HmParamsetType paramsetType;
36
37     public GetParamsetParser(HmChannel channel, HmParamsetType paramsetType) {
38         this.channel = channel;
39         this.paramsetType = paramsetType;
40     }
41
42     @Override
43     @SuppressWarnings("unchecked")
44     public Void parse(Object[] message) throws IOException {
45         if (message == null || message.length == 0 || !(message[0] instanceof Map)) {
46             return null;
47         }
48
49         Map<String, ?> mapMessage = (Map<String, ?>) message[0];
50         for (String dpName : mapMessage.keySet()) {
51             HmDatapointInfo dpInfo = new HmDatapointInfo(paramsetType, channel, dpName);
52             HmDatapoint dp = channel.getDatapoint(dpInfo);
53             if (dp != null) {
54                 dp.setValue(convertToType(dp, mapMessage.get(dpName)));
55                 adjustRssiValue(dp);
56             } else {
57                 // should never happen, but in case ...
58
59                 // suppress warning for this datapoint due wrong CCU metadata
60                 String deviceType = channel.getDevice().getType();
61                 boolean isHmSenMdirNextTrans = "NEXT_TRANSMISSION".equals(dpInfo.getName())
62                         && (deviceType.startsWith("HM-Sen-MDIR-O") || deviceType.startsWith("HM-Sen-MDIR-WM55")
63                                 || deviceType.startsWith("HM-Sec-MDIR-2"));
64                 if (!isHmSenMdirNextTrans) {
65                     if (dpInfo.getParamsetType() == HmParamsetType.MASTER
66                             && channel.getDevice().getHmInterface() == HmInterface.HMIP) {
67                         // These data points can't currently be recognized and therefore can't be created
68                         logger.debug("Can't set value for channel configuration datapoint '{}'", dpInfo);
69                     } else {
70                         logger.warn("Can't set value for datapoint '{}'", dpInfo);
71                     }
72                 }
73             }
74         }
75         return null;
76     }
77 }