]> git.basschouten.com Git - openhab-addons.git/blob
c334159e59a7a4b5f6c28381fc880d2072add337
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.apache.commons.lang.StringUtils;
21
22 /**
23  * Parses a new device event received from a Homematic gateway.
24  *
25  * @author Gerhard Riegler - Initial contribution
26  */
27 public class NewDevicesParser extends CommonRpcParser<Object[], List<String>> {
28     @Override
29     @SuppressWarnings("unchecked")
30     public List<String> parse(Object[] message) throws IOException {
31         List<String> adresses = new ArrayList<>();
32         if (message != null && message.length > 1) {
33             message = (Object[]) message[1];
34             for (int i = 0; i < message.length; i++) {
35                 Map<String, ?> data = (Map<String, ?>) message[i];
36
37                 String address = toString(data.get("ADDRESS"));
38                 boolean isDevice = !StringUtils.contains(address, ":")
39                         && !StringUtils.startsWithIgnoreCase(address, "BidCos");
40                 if (isDevice) {
41                     adresses.add(getSanitizedAddress(address));
42                 }
43             }
44         }
45         return adresses;
46     }
47 }