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.Collection;
17 import java.util.HashMap;
20 import org.openhab.binding.homematic.internal.model.HmDevice;
21 import org.openhab.binding.homematic.internal.model.TclScriptDataEntry;
22 import org.openhab.binding.homematic.internal.model.TclScriptDataList;
25 * Parses a TclRega script result containing names for devices.
27 * @author Gerhard Riegler - Initial contribution
29 public class CcuLoadDeviceNamesParser extends CommonRpcParser<TclScriptDataList, Void> {
30 private Collection<HmDevice> devices;
32 public CcuLoadDeviceNamesParser(Collection<HmDevice> devices) {
33 this.devices = devices;
37 public Void parse(TclScriptDataList resultList) throws IOException {
38 if (resultList.getEntries() != null) {
39 Map<String, HmDevice> devicesByAddress = new HashMap<>();
40 for (HmDevice device : devices) {
41 devicesByAddress.put(device.getAddress(), device);
44 for (TclScriptDataEntry entry : resultList.getEntries()) {
45 HmDevice device = devicesByAddress.get(getSanitizedAddress(entry.name));
47 device.setName(entry.value);