2 * Copyright (c) 2010-2023 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;
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;
26 * Parses a parameter description message and extracts datapoint metadata.
28 * @author Gerhard Riegler - Initial contribution
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;
36 public GetParamsetDescriptionParser(HmChannel channel, HmParamsetType paramsetType) {
37 this.channel = channel;
38 this.paramsetType = paramsetType;
39 this.isHmIpDevice = channel.getDevice().getHmInterface() == HmInterface.HMIP;
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());
49 Map<String, Map<String, Object>> dpNames = (Map<String, Map<String, Object>>) message[0];
51 for (String datapointName : dpNames.keySet()) {
52 Map<String, Object> dpMeta = dpNames.get(datapointName);
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,
58 channel.addDatapoint(dp);