Skip to content

Commit 68e796b

Browse files
committed
feat: remove cloud calls and add UDP handshake
1 parent bc45169 commit 68e796b

1 file changed

Lines changed: 11 additions & 169 deletions

File tree

  • bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/handler

bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/handler/HaywardBridgeHandler.java

Lines changed: 11 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,9 @@ public void initialize() {
109109
try {
110110
scheduledInitialize();
111111
} catch (UnknownHostException e) {
112-
// TODO Auto-generated catch block
113-
e.printStackTrace();
112+
logger.error("Initialization failed", e);
114113
}
115114
}, 1, TimeUnit.SECONDS);
116-
return;
117115
}
118116

119117
public void scheduledInitialize() throws UnknownHostException {
@@ -124,54 +122,21 @@ public void scheduledInitialize() throws UnknownHostException {
124122
clearPolling(pollTelemetryFuture);
125123
clearPolling(pollAlarmsFuture);
126124

127-
if (!(login())) {
125+
if (!handshake()) {
128126
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
129-
"Unable to Login to Hayward's server");
127+
"Unable to complete UDP handshake");
130128
clearPolling(pollTelemetryFuture);
131129
clearPolling(pollAlarmsFuture);
132130
commFailureCount = 50;
133131
initPolling(60);
134132
return;
135133
}
136134

137-
if (!(getSiteList())) {
138-
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
139-
"Unable to getMSP from Hayward's server");
140-
clearPolling(pollTelemetryFuture);
141-
clearPolling(pollAlarmsFuture);
142-
commFailureCount = 50;
143-
initPolling(60);
144-
return;
145-
}
146-
147-
if (!(mspConfigUnits())) {
148-
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
149-
"Unable to getMSPConfigUnits from Hayward's server");
150-
clearPolling(pollTelemetryFuture);
151-
clearPolling(pollAlarmsFuture);
152-
commFailureCount = 50;
153-
initPolling(60);
154-
return;
155-
}
156-
157-
if (logger.isTraceEnabled()) {
158-
if (!(getApiDef())) {
159-
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
160-
"Unable to getApiDef from Hayward's server");
161-
clearPolling(pollTelemetryFuture);
162-
clearPolling(pollAlarmsFuture);
163-
commFailureCount = 50;
164-
initPolling(60);
165-
return;
166-
}
167-
}
168-
169135
if (this.thing.getStatus() != ThingStatus.ONLINE) {
170136
updateStatus(ThingStatus.ONLINE);
171137
}
172138

173-
logger.debug("Succesfully opened connection to Hayward's server: {} Username:{}", config.endpointUrl,
174-
config.username);
139+
logger.debug("Successfully opened connection to Hayward controller: {}", config.endpointUrl);
175140

176141
initPolling(0);
177142
logger.trace("Hayward Telemetry polling scheduled");
@@ -186,145 +151,24 @@ public void scheduledInitialize() throws UnknownHostException {
186151
clearPolling(pollAlarmsFuture);
187152
commFailureCount = 50;
188153
initPolling(60);
189-
return;
190-
} catch (InterruptedException e) {
191-
return;
192-
}
193-
}
194-
195-
public synchronized boolean login() throws HaywardException {
196-
String xmlRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Request><Name>Login</Name><Parameters>"
197-
+ "<Parameter name=\"UserName\" dataType=\"String\">" + config.username + "</Parameter>"
198-
+ "<Parameter name=\"Password\" dataType=\"String\">" + config.password + "</Parameter>"
199-
+ "</Parameters></Request>";
200-
201-
String xmlResponse = udpXmlResponse(xmlRequest, MSG_TYPE_REQUEST);
202-
203-
if (xmlResponse.isEmpty()) {
204-
logger.debug("Hayward Connection thing: Login XML response was null");
205-
return false;
206-
}
207-
208-
String status = evaluateXPath("/Response/Parameters//Parameter[@name='Status']/text()", xmlResponse).get(0);
209-
210-
if (!("0".equals(status))) {
211-
logger.debug("Hayward Connection thing: Login XML response: {}", xmlResponse);
212-
return false;
213-
}
214-
215-
account.token = evaluateXPath("/Response/Parameters//Parameter[@name='Token']/text()", xmlResponse).get(0);
216-
account.userID = evaluateXPath("/Response/Parameters//Parameter[@name='UserID']/text()", xmlResponse).get(0);
217-
return true;
218-
}
219-
220-
221-
public synchronized boolean getApiDef() throws HaywardException, InterruptedException {
222-
String xmlResponse;
223-
224-
// *****getApiDef from Hayward server
225-
String urlParameters = """
226-
<?xml version="1.0" encoding="utf-8"?><Request><Name>GetAPIDef</Name><Parameters>\
227-
<Parameter name="Token" dataType="String">\
228-
""" + account.token + "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
229-
+ account.mspSystemID + "</Parameter>;"
230-
+ "<Parameter name=\"Version\" dataType=\"string\">0.4</Parameter >\r\n"
231-
+ "<Parameter name=\"Language\" dataType=\"string\">en</Parameter >\r\n"
232-
+ "</Parameters></GetTelemetry>";
233-
234-
xmlResponse = udpXmlResponse(urlParameters, MSG_TYPE_REQUEST);
235-
236-
if (xmlResponse.isEmpty()) {
237-
logger.debug("Hayward Connection thing: getApiDef XML response was null");
238-
return false;
239154
}
240-
return true;
241155
}
242156

243-
public synchronized boolean getSiteList() throws HaywardException, InterruptedException {
244-
String xmlResponse;
245-
String status;
246-
247-
// *****Get MSP
248-
String urlParameters = """
249-
<?xml version="1.0" encoding="utf-8"?><Request><Name>GetSiteList</Name><Parameters>\
250-
<Parameter name="Token" dataType="String">\
251-
""" + account.token + "</Parameter><Parameter name=\"UserID\" dataType=\"String\">" + account.userID
252-
+ "</Parameter></Parameters></GetTelemetry>";
253-
254-
xmlResponse = udpXmlResponse(urlParameters, MSG_TYPE_REQUEST);
255-
256-
if (xmlResponse.isEmpty()) {
257-
logger.debug("Hayward Connection thing: getSiteList XML response was null");
258-
return false;
259-
}
260-
261-
status = evaluateXPath("/Response/Parameters//Parameter[@name='Status']/text()", xmlResponse).get(0);
262-
263-
if (!("0".equals(status))) {
264-
logger.debug("Hayward Connection thing: getSiteList XML response: {}", xmlResponse);
265-
return false;
266-
}
267-
268-
account.mspSystemID = evaluateXPath("/Response/Parameters/Parameter/Item//Property[@name='MspSystemID']/text()",
269-
xmlResponse).get(0);
270-
account.backyardName = evaluateXPath(
271-
"/Response/Parameters/Parameter/Item//Property[@name='BackyardName']/text()", xmlResponse).get(0);
272-
account.address = evaluateXPath("/Response/Parameters/Parameter/Item//Property[@name='Address']/text()",
273-
xmlResponse).get(0);
274-
return true;
275-
}
276157

277-
public synchronized String getMspConfig() throws HaywardException, InterruptedException {
278-
// *****getMspConfig from Hayward server
279-
String urlParameters = """
280-
<?xml version="1.0" encoding="utf-8"?><Request><Name>GetMspConfigFile</Name><Parameters>\
281-
<Parameter name="Token" dataType="String">\
282-
""" + account.token + "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
283-
+ account.mspSystemID + "</Parameter><Parameter name=\"Version\" dataType=\"string\">0</Parameter>\r\n"
284-
+ "</Parameters></GetTelemetry>";
158+
private synchronized boolean handshake() throws HaywardException {
159+
String xmlRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Request><Name>Ping</Name><Parameters/></Request>";
285160

286-
String xmlResponse = udpXmlResponse(urlParameters, MSG_TYPE_REQUEST);
161+
String xmlResponse = udpXmlResponse(xmlRequest, MSG_TYPE_REQUEST);
287162

288163
if (xmlResponse.isEmpty()) {
289-
logger.debug("Hayward Connection thing: getMSPConfig XML response was null");
290-
return "Fail";
291-
}
292-
293-
if (evaluateXPath("//Backyard/Name/text()", xmlResponse).isEmpty()) {
294-
logger.debug("Hayward Connection thing: getMSPConfig XML response: {}", xmlResponse);
295-
return "Fail";
296-
}
297-
return xmlResponse;
298-
}
299-
300-
public synchronized boolean mspConfigUnits() throws HaywardException, InterruptedException {
301-
List<String> property1 = new ArrayList<>();
302-
List<String> property2 = new ArrayList<>();
303-
304-
String xmlResponse = getMspConfig();
305-
306-
if (xmlResponse.contentEquals("Fail")) {
164+
logger.debug("Hayward Connection thing: Handshake XML response was null");
307165
return false;
308166
}
309-
310-
// Get Units (Standard, Metric)
311-
property1 = evaluateXPath("//System/Units/text()", xmlResponse);
312-
account.units = property1.get(0);
313-
314-
// Get Variable Speed Pump Units (percent, RPM)
315-
property2 = evaluateXPath("//System/Msp-Vsp-Speed-Format/text()", xmlResponse);
316-
account.vspSpeedFormat = property2.get(0);
317-
318167
return true;
319168
}
320169

321-
public synchronized boolean getTelemetryData() throws HaywardException, InterruptedException {
322-
// *****getTelemetry from Hayward server
323-
String urlParameters = """
324-
<?xml version="1.0" encoding="utf-8"?><Request><Name>GetTelemetryData</Name><Parameters>\
325-
<Parameter name="Token" dataType="String">\
326-
""" + account.token + "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
327-
+ account.mspSystemID + "</Parameter></Parameters></GetTelemetry>";
170+
public synchronized boolean getTelemetryData() throws HaywardException {
171+
String urlParameters = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Request><Name>GetTelemetryData</Name><Parameters/></Request>";
328172

329173
String xmlResponse = udpXmlResponse(urlParameters, MSG_TYPE_TELEMETRY);
330174

@@ -349,6 +193,7 @@ public synchronized boolean getTelemetryData() throws HaywardException, Interrup
349193
return true;
350194
}
351195

196+
352197
public synchronized boolean getAlarmList() throws HaywardException {
353198
for (Thing thing : getThing().getThings()) {
354199
Map<String, String> properties = thing.getProperties();
@@ -382,11 +227,8 @@ private synchronized void initPolling(int initalDelay) {
382227
updateStatus(ThingStatus.ONLINE);
383228
} catch (HaywardException e) {
384229
logger.debug("Hayward Connection thing: Exception during poll: {}", e.getMessage());
385-
} catch (InterruptedException e) {
386-
return;
387230
}
388231
}, initalDelay, config.telemetryPollTime, TimeUnit.SECONDS);
389-
return;
390232
}
391233

392234
private synchronized void initAlarmPolling(int initalDelay) {

0 commit comments

Comments
 (0)