]> git.basschouten.com Git - openhab-addons.git/blob
3ceca8361899ffc3877a92e8b87d1da733849f7f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.binding.haywardomnilogic.internal.config.HaywardConfig;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingStatus;
26 import org.openhab.core.thing.ThingStatusDetail;
27
28 /**
29  * The Heater Handler
30  *
31  * @author Matt Myers - Initial contribution
32  */
33 @NonNullByDefault
34 public class HaywardHeaterHandler extends HaywardThingHandler {
35
36     HaywardConfig config = getConfig().as(HaywardConfig.class);
37
38     public HaywardHeaterHandler(Thing thing) {
39         super(thing);
40     }
41
42     @Override
43     public void getTelemetry(String xmlResponse) throws HaywardException {
44         List<String> systemIDs = new ArrayList<>();
45         List<String> data = new ArrayList<>();
46
47         Bridge bridge = getBridge();
48         if (bridge != null) {
49             HaywardBridgeHandler bridgehandler = (HaywardBridgeHandler) bridge.getHandler();
50             if (bridgehandler != null) {
51                 systemIDs = bridgehandler.evaluateXPath("//Heater/@systemId", xmlResponse);
52                 String thingSystemID = getThing().getUID().getId();
53                 for (int i = 0; i < systemIDs.size(); i++) {
54                     if (systemIDs.get(i).equals(thingSystemID)) {
55                         // State
56                         data = bridgehandler.evaluateXPath("//Heater/@heaterState", xmlResponse);
57                         updateData(HaywardBindingConstants.CHANNEL_HEATER_STATE, data.get(i));
58
59                         // Enable
60                         data = bridgehandler.evaluateXPath("//Heater/@enable", xmlResponse);
61                         if ("0".equals(data.get(i))) {
62                             updateData(HaywardBindingConstants.CHANNEL_HEATER_ENABLE, "0");
63                         } else {
64                             updateData(HaywardBindingConstants.CHANNEL_HEATER_ENABLE, "1");
65                         }
66                     }
67                 }
68                 this.updateStatus(ThingStatus.ONLINE);
69             } else {
70                 this.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED);
71             }
72         }
73     }
74 }