-
Notifications
You must be signed in to change notification settings - Fork 0
feat: centralize hayward command building #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package org.openhab.binding.haywardomnilogic.internal.net; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
|
||
| /** | ||
| * Helper for building XML command strings sent to the Hayward cloud. | ||
| */ | ||
| @NonNullByDefault | ||
| public class CommandBuilder { | ||
|
|
||
| private static final String SET_HEATER_ENABLE = """ | ||
| <Name>SetHeaterEnable</Name> | ||
| <Parameters> | ||
| <Parameter name=\"Token\" dataType=\"String\">%s</Parameter> | ||
| <Parameter name=\"MspSystemID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"PoolID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"HeaterID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"Enabled\" dataType=\"bool\">%s</Parameter> | ||
| </Parameters> | ||
| """; | ||
|
|
||
| private static final String SET_UI_HEATER_CMD = """ | ||
| <Name>SetUIHeaterCmd</Name> | ||
| <Parameters> | ||
| <Parameter name=\"Token\" dataType=\"String\">%s</Parameter> | ||
| <Parameter name=\"MspSystemID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"PoolID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"HeaterID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"Temp\" dataType=\"int\">%s</Parameter> | ||
| </Parameters> | ||
| """; | ||
|
|
||
| private CommandBuilder() { | ||
| // utility class | ||
| } | ||
|
|
||
| public static String buildSetHeaterEnable(String prefix, String token, int mspSystemID, String poolID, | ||
| String heaterID, String enabled) { | ||
| return prefix | ||
| + String.format(SET_HEATER_ENABLE, token, mspSystemID, poolID, heaterID, enabled) | ||
| + closingTag(prefix); | ||
| } | ||
|
|
||
| public static String buildSetUIHeaterCmd(String prefix, String token, int mspSystemID, String poolID, | ||
| String heaterID, String temp) { | ||
| return prefix + String.format(SET_UI_HEATER_CMD, token, mspSystemID, poolID, heaterID, temp) | ||
| + closingTag(prefix); | ||
| } | ||
|
|
||
| private static String closingTag(String prefix) { | ||
| if (prefix.contains("<Request>")) { | ||
| return "</Request>"; | ||
| } else if (prefix.contains("<GetTelemetry>")) { | ||
| return "</GetTelemetry>"; | ||
| } else { | ||
| return ""; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.net; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
|
||
| /** | ||
| * Helper for building XML command strings sent to the Hayward controller. | ||
| */ | ||
| @NonNullByDefault | ||
| public class CommandBuilder { | ||
|
|
||
| private static final String SET_HEATER_ENABLE = """ | ||
| <Name>SetHeaterEnable</Name> | ||
| <Parameters> | ||
| <Parameter name=\"Token\" dataType=\"String\">%s</Parameter> | ||
| <Parameter name=\"MspSystemID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"PoolID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"HeaterID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"Enabled\" dataType=\"bool\">%s</Parameter> | ||
| </Parameters> | ||
| """; | ||
|
|
||
| private static final String SET_UI_HEATER_CMD = """ | ||
| <Name>SetUIHeaterCmd</Name> | ||
| <Parameters> | ||
| <Parameter name=\"Token\" dataType=\"String\">%s</Parameter> | ||
| <Parameter name=\"MspSystemID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"PoolID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"HeaterID\" dataType=\"int\">%s</Parameter> | ||
| <Parameter name=\"Temp\" dataType=\"int\">%s</Parameter> | ||
| </Parameters> | ||
| """; | ||
|
|
||
| private CommandBuilder() { | ||
| // utility class | ||
| } | ||
|
|
||
| public static String buildSetHeaterEnable(String prefix, String token, int mspSystemID, String poolID, | ||
| String heaterID, String enabled) { | ||
| return prefix | ||
| + String.format(SET_HEATER_ENABLE, token, mspSystemID, poolID, heaterID, enabled) | ||
| + closingTag(prefix); | ||
| } | ||
|
|
||
| public static String buildSetUIHeaterCmd(String prefix, String token, int mspSystemID, String poolID, | ||
| String heaterID, String temp) { | ||
| return prefix + String.format(SET_UI_HEATER_CMD, token, mspSystemID, poolID, heaterID, temp) | ||
|
Comment on lines
+37
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P0] Use String for mspSystemID in local command builder The local variant of Useful? React with 👍 / 👎. |
||
| + closingTag(prefix); | ||
| } | ||
|
|
||
| private static String closingTag(String prefix) { | ||
| if (prefix.contains("<Request>")) { | ||
| return "</Request>"; | ||
| } else if (prefix.contains("<GetTelemetry>")) { | ||
| return "</GetTelemetry>"; | ||
| } else { | ||
| return ""; | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P0] Align mspSystemID parameter type with callers
The new
CommandBuilderexpectsint mspSystemIDin bothbuildSetHeaterEnableandbuildSetUIHeaterCmd, butHaywardAccount.mspSystemIDis defined as aStringand the handlers pass that string directly. This mismatch means the binding no longer compiles because there is no implicit conversion fromStringtoint. Either accept aStringhere or parse it at the call site before invoking the builder.Useful? React with 👍 / 👎.