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;
16 import java.util.ArrayList;
17 import java.util.List;
20 import org.openhab.binding.homematic.internal.common.HomematicConfig;
21 import org.openhab.binding.homematic.internal.model.HmRssiInfo;
24 * Parses a result with all rssi values of all datapoints.
26 * @author Gerhard Riegler - Initial contribution
28 public class RssiInfoParser extends CommonRpcParser<Object[], List<HmRssiInfo>> {
29 private HomematicConfig config;
31 public RssiInfoParser(HomematicConfig config) {
36 @SuppressWarnings("unchecked")
37 public List<HmRssiInfo> parse(Object[] result) throws IOException {
38 List<HmRssiInfo> rssiList = new ArrayList<>();
39 if (result != null && result.length > 0 && result[0] instanceof Map) {
40 Map<String, ?> devices = (Map<String, ?>) result[0];
42 for (String sourceDevice : devices.keySet()) {
43 Map<String, Object[]> targetDevices = (Map<String, Object[]>) devices.get(sourceDevice);
44 if (targetDevices != null) {
45 for (String targetDevice : targetDevices.keySet()) {
46 if (targetDevice.equals(config.getGatewayInfo().getAddress())) {
47 Integer rssiDevice = getAdjustedRssiValue((Integer) targetDevices.get(targetDevice)[0]);
48 Integer rssiPeer = getAdjustedRssiValue((Integer) targetDevices.get(targetDevice)[1]);
49 HmRssiInfo rssiInfo = new HmRssiInfo(sourceDevice, rssiDevice, rssiPeer);
50 rssiList.add(rssiInfo);