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.ihc.internal.ws.services;
15 import java.io.IOException;
16 import java.util.ArrayList;
17 import java.util.List;
19 import javax.xml.xpath.XPathExpressionException;
21 import org.openhab.binding.ihc.internal.ws.datatypes.WSRFDevice;
22 import org.openhab.binding.ihc.internal.ws.datatypes.XPathUtils;
23 import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
24 import org.openhab.binding.ihc.internal.ws.http.IhcConnectionPool;
25 import org.w3c.dom.Node;
26 import org.w3c.dom.NodeList;
29 * Class to handle IHC / ELKO LS Controller's airlink management service.
32 * @author Pauli Anttila - Initial contribution
34 public class IhcAirlinkManagementService extends IhcBaseService {
36 public IhcAirlinkManagementService(String host, int timeout, IhcConnectionPool ihcConnectionPool) {
37 super(ihcConnectionPool, timeout, host, "AirlinkManagementService");
41 * Query system information from the controller.
43 * @return system information.
44 * @throws IhcExecption
46 public synchronized List<WSRFDevice> getDetectedDeviceList() throws IhcExecption {
47 String response = sendSoapQuery("getDetectedDeviceList", EMPTY_QUERY);
49 List<WSRFDevice> resourceValueList = new ArrayList<>();
52 NodeList nodeList = XPathUtils.parseList(response,
53 "/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:getDetectedDeviceList1/ns1:arrayItem");
55 if (nodeList != null) {
56 for (int i = 0; i < nodeList.getLength(); i++) {
57 Node node = nodeList.item(i);
59 WSRFDevice dev = parseResourceValue(node);
61 resourceValueList.add(dev);
66 throw new IhcExecption("Illegal resource value notification response received");
68 return resourceValueList;
69 } catch (IOException | XPathExpressionException | NumberFormatException e) {
70 throw new IhcExecption("Error occured during XML data parsing", e);
74 private WSRFDevice parseResourceValue(Node n) throws XPathExpressionException, NumberFormatException {
76 int batteryLevel = Integer.parseInt(XPathUtils.getValueFromNode(n, "batteryLevel"));
77 int deviceType = Integer.parseInt(XPathUtils.getValueFromNode(n, "deviceType"));
78 long serialNumber = Long.parseLong(XPathUtils.getValueFromNode(n, "serialNumber"));
79 int signalStrength = Integer.parseInt(XPathUtils.getValueFromNode(n, "signalStrength"));
80 int version = Integer.parseInt(XPathUtils.getValueFromNode(n, "version"));
81 boolean detected = Boolean.valueOf(XPathUtils.getValueFromNode(n, "detected"));
82 return new WSRFDevice(batteryLevel, deviceType, serialNumber, signalStrength, version, detected);
83 } catch (NumberFormatException e) {