]> git.basschouten.com Git - openhab-addons.git/blob
c9dd477130980976d342bc841c892930a6dd991a
[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.ArrayList;
17 import java.util.List;
18 import java.util.Map;
19
20 import org.openhab.binding.homematic.internal.common.HomematicConfig;
21 import org.openhab.binding.homematic.internal.model.HmRssiInfo;
22
23 /**
24  * Parses a result with all rssi values of all datapoints.
25  *
26  * @author Gerhard Riegler - Initial contribution
27  */
28 public class RssiInfoParser extends CommonRpcParser<Object[], List<HmRssiInfo>> {
29     private HomematicConfig config;
30
31     public RssiInfoParser(HomematicConfig config) {
32         this.config = config;
33     }
34
35     @Override
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];
41
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);
51                         }
52                     }
53                 }
54             }
55         }
56         return rssiList;
57     }
58 }