]> git.basschouten.com Git - openhab-addons.git/blob
e7293f5b13a603a113560a3e8a55b3a1ed87bfed
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.haywardomnilogic.internal.handler;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.haywardomnilogic.internal.HaywardBindingConstants;
20 import org.openhab.binding.haywardomnilogic.internal.HaywardException;
21 import org.openhab.binding.haywardomnilogic.internal.HaywardThingHandler;
22 import org.openhab.core.thing.Bridge;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingStatus;
25 import org.openhab.core.thing.ThingStatusDetail;
26
27 /**
28  * The Body of Water Handler
29  *
30  * @author Matt Myers - Initial contribution
31  */
32 @NonNullByDefault
33 public class HaywardBowHandler extends HaywardThingHandler {
34
35     public HaywardBowHandler(Thing thing) {
36         super(thing);
37     }
38
39     @Override
40     public void getTelemetry(String xmlResponse) throws HaywardException {
41         List<String> systemIDs = new ArrayList<>();
42         List<String> data = new ArrayList<>();
43
44         Bridge bridge = getBridge();
45         if (bridge != null) {
46             HaywardBridgeHandler bridgehandler = (HaywardBridgeHandler) bridge.getHandler();
47             if (bridgehandler != null) {
48                 systemIDs = bridgehandler.evaluateXPath("//BodyOfWater/@systemId", xmlResponse);
49
50                 String thingSystemID = getThing().getUID().getId();
51                 for (int i = 0; i < systemIDs.size(); i++) {
52                     if (systemIDs.get(i).equals(thingSystemID)) {
53                         // Flow
54                         data = bridgehandler.evaluateXPath("//BodyOfWater/@flow", xmlResponse);
55                         updateData(HaywardBindingConstants.CHANNEL_BOW_FLOW, data.get(i));
56
57                         // Water Temp
58                         data = bridgehandler.evaluateXPath("//BodyOfWater/@waterTemp", xmlResponse);
59                         updateData(HaywardBindingConstants.CHANNEL_BOW_WATERTEMP, data.get(i));
60                     }
61                 }
62                 this.updateStatus(ThingStatus.ONLINE);
63             } else {
64                 this.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED);
65             }
66         }
67     }
68 }