Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,97 @@

@NonNullByDefault
public class HaywardAccount {
public String token = "";
public String mspSystemID = "";
public String userID = "";
public String backyardName = "";
public String address = "";
public String firstName = "";
public String lastName = "";
public String roleType = "";
public String units = "";
public String vspSpeedFormat = "";
private String token = "";
private String mspSystemID = "";
private String userID = "";
private String backyardName = "";
private String address = "";
private String firstName = "";
private String lastName = "";
private String roleType = "";
private String units = "";
private String vspSpeedFormat = "";

public HaywardAccount() {
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

public String getMspSystemID() {
return mspSystemID;
}

public void setMspSystemID(String mspSystemID) {
this.mspSystemID = mspSystemID;
}

public String getUserID() {
return userID;
}

public void setUserID(String userID) {
this.userID = userID;
}

public String getBackyardName() {
return backyardName;
}

public void setBackyardName(String backyardName) {
this.backyardName = backyardName;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getRoleType() {
return roleType;
}

public void setRoleType(String roleType) {
this.roleType = roleType;
}

public String getUnits() {
return units;
}

public void setUnits(String units) {
this.units = units;
}

public String getVspSpeedFormat() {
return vspSpeedFormat;
}

public void setVspSpeedFormat(String vspSpeedFormat) {
this.vspSpeedFormat = vspSpeedFormat;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public State toState(String type, String channelID, String value) throws NumberF
if (bridge != null) {
HaywardBridgeHandler bridgehandler = (HaywardBridgeHandler) bridge.getHandler();
if (bridgehandler != null) {
if ("Standard".equals(bridgehandler.account.units)) {
if ("Standard".equals(bridgehandler.getAccount().getUnits())) {
return new QuantityType<>(Integer.parseInt(value), ImperialUnits.FAHRENHEIT);
} else {
return new QuantityType<>(Integer.parseInt(value), SIUnits.CELSIUS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,52 @@

@NonNullByDefault
public class HaywardConfig {
public String endpointUrl = "";
public String username = "";
public String password = "";
public int alarmPollTime = 60;
public int telemetryPollTime = 10;
private String endpointUrl = "";
private String username = "";
private String password = "";
private int alarmPollTime = 60;
private int telemetryPollTime = 10;

public HaywardConfig() {
}

public String getEndpointUrl() {
return endpointUrl;
}

public void setEndpointUrl(String endpointUrl) {
this.endpointUrl = endpointUrl;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public int getAlarmPollTime() {
return alarmPollTime;
}

public void setAlarmPollTime(int alarmPollTime) {
this.alarmPollTime = alarmPollTime;
}

public int getTelemetryPollTime() {
return telemetryPollTime;
}

public void setTelemetryPollTime(int telemetryPollTime) {
this.telemetryPollTime = telemetryPollTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public synchronized void mspConfigDiscovery(String xmlResponse) {

for (int i = 0; i < names.size(); i++) {
backyardProperties.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BACKYARD);
backyardProperties.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, thingHandler.account.mspSystemID);
backyardProperties.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID,
thingHandler.getAccount().getMspSystemID());

onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BACKYARD, names.get(i), backyardProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public boolean getAlarmList(String systemID) throws HaywardException {
String urlParameters = """
<?xml version="1.0" encoding="utf-8"?><Request><Name>GetAlarmList</Name><Parameters>\
<Parameter name="Token" dataType="String">\
""" + bridgehandler.account.token + "</Parameter>"
+ "<Parameter name=\"MspSystemID\" dataType=\"int\">" + bridgehandler.account.mspSystemID
""" + bridgehandler.getAccount().getToken() + "</Parameter>"
+ "<Parameter name=\"MspSystemID\" dataType=\"int\">" + bridgehandler.getAccount().getMspSystemID()
+ "</Parameter>"
+ "<Parameter name=\"CultureInfoName\" dataType=\"String\">en-us</Parameter></Parameters></Request>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,16 @@ public class HaywardBridgeHandler extends BaseBridgeHandler {
private @Nullable ScheduledFuture<?> pollTelemetryFuture;
private @Nullable ScheduledFuture<?> pollAlarmsFuture;
private int commFailureCount;
public HaywardConfig config = getConfig().as(HaywardConfig.class);
public HaywardAccount account = getConfig().as(HaywardAccount.class);
private HaywardConfig config = getConfig().as(HaywardConfig.class);
private final HaywardAccount account = getConfig().as(HaywardAccount.class);

public HaywardConfig getBridgeConfig() {
return config;
}

public HaywardAccount getAccount() {
return account;
}

@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
Expand Down Expand Up @@ -164,13 +172,13 @@ public void scheduledInitialize() {
updateStatus(ThingStatus.ONLINE);
}

logger.debug("Succesfully opened connection to Hayward's server: {} Username:{}", config.endpointUrl,
config.username);
logger.debug("Succesfully opened connection to Hayward's server: {} Username:{}",
config.getEndpointUrl(), config.getUsername());

initPolling(0);
logger.trace("Hayward Telemetry polling scheduled");

if (config.alarmPollTime > 0) {
if (config.getAlarmPollTime() > 0) {
initAlarmPolling(1);
}
} catch (HaywardException e) {
Expand All @@ -195,8 +203,8 @@ public synchronized boolean login() throws HaywardException, InterruptedExceptio
<?xml version="1.0" encoding="utf-8"?><Request>\
<Name>Login</Name><Parameters>\
<Parameter name="UserName" dataType="String">\
""" + config.username + "</Parameter>" + "<Parameter name=\"Password\" dataType=\"String\">"
+ config.password + "</Parameter>" + "</Parameters></Request>";
""" + config.getUsername() + "</Parameter>" + "<Parameter name=\"Password\" dataType=\"String\">"
+ config.getPassword() + "</Parameter>" + "</Parameters></Request>";

xmlResponse = httpXmlResponse(urlParameters);

Expand All @@ -212,8 +220,8 @@ public synchronized boolean login() throws HaywardException, InterruptedExceptio
return false;
}

account.token = evaluateXPath("/Response/Parameters//Parameter[@name='Token']/text()", xmlResponse).get(0);
account.userID = evaluateXPath("/Response/Parameters//Parameter[@name='UserID']/text()", xmlResponse).get(0);
account.setToken(evaluateXPath("/Response/Parameters//Parameter[@name='Token']/text()", xmlResponse).get(0));
account.setUserID(evaluateXPath("/Response/Parameters//Parameter[@name='UserID']/text()", xmlResponse).get(0));
return true;
}

Expand All @@ -224,8 +232,8 @@ public synchronized boolean getApiDef() throws HaywardException, InterruptedExce
String urlParameters = """
<?xml version="1.0" encoding="utf-8"?><Request><Name>GetAPIDef</Name><Parameters>\
<Parameter name="Token" dataType="String">\
""" + account.token + "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
+ account.mspSystemID + "</Parameter>;"
""" + account.getToken() + "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
+ account.getMspSystemID() + "</Parameter>;"
+ "<Parameter name=\"Version\" dataType=\"string\">0.4</Parameter >\r\n"
+ "<Parameter name=\"Language\" dataType=\"string\">en</Parameter >\r\n" + "</Parameters></Request>";

Expand All @@ -246,7 +254,7 @@ public synchronized boolean getSiteList() throws HaywardException, InterruptedEx
String urlParameters = """
<?xml version="1.0" encoding="utf-8"?><Request><Name>GetSiteList</Name><Parameters>\
<Parameter name="Token" dataType="String">\
""" + account.token + "</Parameter><Parameter name=\"UserID\" dataType=\"String\">" + account.userID
""" + account.getToken() + "</Parameter><Parameter name=\"UserID\" dataType=\"String\">" + account.getUserID()
+ "</Parameter></Parameters></Request>";

xmlResponse = httpXmlResponse(urlParameters);
Expand All @@ -263,12 +271,12 @@ public synchronized boolean getSiteList() throws HaywardException, InterruptedEx
return false;
}

account.mspSystemID = evaluateXPath("/Response/Parameters/Parameter/Item//Property[@name='MspSystemID']/text()",
xmlResponse).get(0);
account.backyardName = evaluateXPath(
"/Response/Parameters/Parameter/Item//Property[@name='BackyardName']/text()", xmlResponse).get(0);
account.address = evaluateXPath("/Response/Parameters/Parameter/Item//Property[@name='Address']/text()",
xmlResponse).get(0);
account.setMspSystemID(evaluateXPath(
"/Response/Parameters/Parameter/Item//Property[@name='MspSystemID']/text()", xmlResponse).get(0));
account.setBackyardName(evaluateXPath(
"/Response/Parameters/Parameter/Item//Property[@name='BackyardName']/text()", xmlResponse).get(0));
account.setAddress(evaluateXPath(
"/Response/Parameters/Parameter/Item//Property[@name='Address']/text()", xmlResponse).get(0));
return true;
}

Expand All @@ -277,8 +285,8 @@ public synchronized String getMspConfig() throws HaywardException, InterruptedEx
String urlParameters = """
<?xml version="1.0" encoding="utf-8"?><Request><Name>GetMspConfigFile</Name><Parameters>\
<Parameter name="Token" dataType="String">\
""" + account.token + "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
+ account.mspSystemID + "</Parameter><Parameter name=\"Version\" dataType=\"string\">0</Parameter>\r\n"
""" + account.getToken() + "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
+ account.getMspSystemID() + "</Parameter><Parameter name=\"Version\" dataType=\"string\">0</Parameter>\r\n"
+ "</Parameters></Request>";

String xmlResponse = httpXmlResponse(urlParameters);
Expand Down Expand Up @@ -307,11 +315,11 @@ public synchronized boolean mspConfigUnits() throws HaywardException, Interrupte

// Get Units (Standard, Metric)
property1 = evaluateXPath("//System/Units/text()", xmlResponse);
account.units = property1.get(0);
account.setUnits(property1.get(0));

// Get Variable Speed Pump Units (percent, RPM)
property2 = evaluateXPath("//System/Msp-Vsp-Speed-Format/text()", xmlResponse);
account.vspSpeedFormat = property2.get(0);
account.setVspSpeedFormat(property2.get(0));

return true;
}
Expand All @@ -321,8 +329,8 @@ public synchronized boolean getTelemetryData() throws HaywardException, Interrup
String urlParameters = """
<?xml version="1.0" encoding="utf-8"?><Request><Name>GetTelemetryData</Name><Parameters>\
<Parameter name="Token" dataType="String">\
""" + account.token + "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
+ account.mspSystemID + "</Parameter></Parameters></Request>";
""" + account.getToken() + "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
+ account.getMspSystemID() + "</Parameter></Parameters></Request>";

String xmlResponse = httpXmlResponse(urlParameters);

Expand Down Expand Up @@ -383,7 +391,7 @@ private synchronized void initPolling(int initalDelay) {
} catch (InterruptedException e) {
return;
}
}, initalDelay, config.telemetryPollTime, TimeUnit.SECONDS);
}, initalDelay, config.getTelemetryPollTime(), TimeUnit.SECONDS);
return;
}

Expand All @@ -394,7 +402,7 @@ private synchronized void initAlarmPolling(int initalDelay) {
} catch (HaywardException e) {
logger.debug("Hayward Connection thing: Exception during poll: {}", e.getMessage());
}
}, initalDelay, config.alarmPollTime, TimeUnit.SECONDS);
}, initalDelay, config.getAlarmPollTime(), TimeUnit.SECONDS);
}

private void clearPolling(@Nullable ScheduledFuture<?> pollJob) {
Expand Down Expand Up @@ -452,7 +460,7 @@ public synchronized String httpXmlResponse(String urlParameters) throws HaywardE

for (int retry = 0; retry <= 2; retry++) {
try {
ContentResponse httpResponse = sendRequestBuilder(config.endpointUrl, HttpMethod.POST)
ContentResponse httpResponse = sendRequestBuilder(config.getEndpointUrl(), HttpMethod.POST)
.content(new StringContentProvider(urlParameters), "text/xml; charset=utf-8")
.header(HttpHeader.CONTENT_LENGTH, urlParameterslength).send();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}

String cmdURL = HaywardBindingConstants.COMMAND_PARAMETERS + "<Name>SetCHLORParams</Name><Parameters>"
+ "<Parameter name=\"Token\" dataType=\"String\">" + bridgehandler.account.token
+ "<Parameter name=\"Token\" dataType=\"String\">" + bridgehandler.getAccount().getToken()
+ "</Parameter>" + "<Parameter name=\"MspSystemID\" dataType=\"int\">"
+ bridgehandler.account.mspSystemID + "</Parameter>"
+ bridgehandler.getAccount().getMspSystemID() + "</Parameter>"
+ "<Parameter name=\"PoolID\" dataType=\"int\">" + poolID + "</Parameter>"
+ "<Parameter name=\"ChlorID\" dataType=\"int\" alias=\"EquipmentID\">" + systemID
+ "</Parameter>" + "<Parameter name=\"CfgState\" dataType=\"byte\" alias=\"Data1\">"
Expand All @@ -171,8 +171,8 @@ public void handleCommand(ChannelUID channelUID, Command command) {
return;
}
} catch (HaywardException e) {
logger.debug("Unable to send command to Hayward's server {}:{}:{}", bridgehandler.config.endpointUrl,
bridgehandler.config.username, e.getMessage());
logger.debug("Unable to send command to Hayward's server {}:{}:{}", bridgehandler.getBridgeConfig().getEndpointUrl(),
bridgehandler.getBridgeConfig().getUsername(), e.getMessage());
} catch (InterruptedException e) {
return;
}
Expand Down
Loading