]> git.basschouten.com Git - openhab-addons.git/blob
a530caf169f87d759095be949610d92626460a84
[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.HmInterface;
21 import org.openhab.binding.homematic.internal.model.HmParamsetType;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * Parses a parameter description message and extracts datapoint metadata.
27  *
28  * @author Gerhard Riegler - Initial contribution
29  */
30 public class GetParamsetDescriptionParser extends CommonRpcParser<Object[], Void> {
31     private final Logger logger = LoggerFactory.getLogger(GetParamsetDescriptionParser.class);
32     private HmParamsetType paramsetType;
33     private HmChannel channel;
34     private boolean isHmIpDevice;
35
36     public GetParamsetDescriptionParser(HmChannel channel, HmParamsetType paramsetType) {
37         this.channel = channel;
38         this.paramsetType = paramsetType;
39         this.isHmIpDevice = channel.getDevice().getHmInterface() == HmInterface.HMIP;
40     }
41
42     @Override
43     @SuppressWarnings("unchecked")
44     public Void parse(Object[] message) throws IOException {
45         if (!(message[0] instanceof Map)) {
46             logger.debug("Unexpected datatype '{}',  ignoring message", message[0].getClass());
47             return null;
48         }
49         Map<String, Map<String, Object>> dpNames = (Map<String, Map<String, Object>>) message[0];
50
51         for (String datapointName : dpNames.keySet()) {
52             Map<String, Object> dpMeta = dpNames.get(datapointName);
53
54             HmDatapoint dp = assembleDatapoint(datapointName, toString(dpMeta.get("UNIT")),
55                     toString(dpMeta.get("TYPE")), toOptionList(dpMeta.get("VALUE_LIST")), dpMeta.get("MIN"),
56                     dpMeta.get("MAX"), toInteger(dpMeta.get("OPERATIONS")), dpMeta.get("DEFAULT"), paramsetType,
57                     isHmIpDevice);
58             channel.addDatapoint(dp);
59         }
60
61         return null;
62     }
63 }