2 * Copyright (c) 2010-2022 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.Collection;
17 import java.util.HashMap;
20 import org.openhab.binding.homematic.internal.model.HmDevice;
23 * Parses a Homegear message containing names for devices.
25 * @author Gerhard Riegler - Initial contribution
27 public class HomegearLoadDeviceNamesParser extends CommonRpcParser<Object[], Void> {
28 private Collection<HmDevice> devices;
30 public HomegearLoadDeviceNamesParser(Collection<HmDevice> devices) {
31 this.devices = devices;
35 @SuppressWarnings("unchecked")
36 public Void parse(Object[] message) throws IOException {
37 Map<String, HmDevice> devicesById = new HashMap<>();
38 for (HmDevice device : devices) {
39 devicesById.put(device.getHomegearId(), device);
42 message = (Object[]) message[0];
43 for (int i = 0; i < message.length; i++) {
44 Map<String, ?> data = (Map<String, ?>) message[i];
45 String id = toString(data.get("ID"));
46 String name = toString(data.get("NAME"));
48 HmDevice device = devicesById.get(getSanitizedAddress(id));