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.HmParamsetType;
21 import org.openhab.binding.homematic.internal.model.HmValueType;
24 * Parses a Homegear message with variables and generates the datapoints.
26 * @author Gerhard Riegler - Initial contribution
28 public class GetAllSystemVariablesParser extends CommonRpcParser<Object[], Void> {
29 private HmChannel channel;
31 public GetAllSystemVariablesParser(HmChannel channel) {
32 this.channel = channel;
36 @SuppressWarnings("unchecked")
37 public Void parse(Object[] message) throws IOException {
38 Map<String, ?> mapMessage = (Map<String, ?>) message[0];
39 for (String variableName : mapMessage.keySet()) {
40 Object value = mapMessage.get(variableName);
41 HmDatapoint dp = channel.getDatapoint(HmParamsetType.VALUES, variableName);
45 HmDatapoint dpVariable = new HmDatapoint(variableName, variableName, guessType(value), value, false,
46 HmParamsetType.VALUES);
47 dpVariable.setInfo(variableName);
48 channel.addDatapoint(dpVariable);
55 * Guesses the value type.
57 private HmValueType guessType(Object value) {
59 return HmValueType.UNKNOWN;
60 } else if (value instanceof Boolean) {
61 return HmValueType.BOOL;
62 } else if (value instanceof Integer || value instanceof Long) {
63 return HmValueType.INTEGER;
64 } else if (value instanceof Number) {
65 return HmValueType.FLOAT;
67 return HmValueType.STRING;