Skip to content

Commit

Permalink
feat(status): support OneWireDetails for MultiExtensionAir
Browse files Browse the repository at this point in the history
  • Loading branch information
jimirocks committed Feb 15, 2024
1 parent 33257ad commit 5890bcf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/main/java/cz/smarteon/loxone/message/LoxoneMessageCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ public static LoxoneMessageCommand<OneWireDetails> oneWireDetails(final @NotNull
OneWireDetails.class, MiniserverType.KNOWN);
}

/**
* Get 1-wire details of MultiExtensionAir by given extension serial number.
* @param extensionSerial serial number of MultiExtensionAir extension
* @return command requesting 1-wire details
*/
public static LoxoneMessageCommand<OneWireDetails> multiExtensionAirOneWireDetails(final @NotNull String extensionSerial) {
return jsonCommand("jdev/sys/wsdevice/" + requireNonNull(extensionSerial, "extensionSerial can't be null") + "/Statistics",

Check warning on line 256 in src/main/java/cz/smarteon/loxone/message/LoxoneMessageCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cz/smarteon/loxone/message/LoxoneMessageCommand.java#L256

Added line #L256 was not covered by tests
OneWireDetails.class, MiniserverType.KNOWN);
}

private static <V extends LoxoneValue> LoxoneMessageCommand<V> jsonCommand(
final String command, final Class<V> valueType, final MiniserverType[] supportedMiniservers) {
return new LoxoneMessageCommand<>(command, Type.JSON, valueType, true, true, supportedMiniservers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public int hashCode() {
public static class Deserializer extends JsonDeserializer<OneWireDetails> {

private static final Pattern ONE_WIRE_DETAIL_PATTERN = Pattern.compile(
"^1-Wire\\s+Serial\\s+([0-9A-F.]+):\\s+(\\d+)\\s+Packet Requests,"
"^(?:1-Wire\\s+)?Serial\\s+([0-9A-F.]+):\\s+(\\d+)\\s+Packet Requests,"
+ "\\s+(\\d+)\\s+CRC Errors,\\s+(\\d+)\\s+85 Degree Problems$");
@Override
public OneWireDetails deserialize(
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/cz/smarteon/loxone/system/status/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@ public String getName() {
public String getSerialNumber() {
return serialNumber;
}

/**
* Serial number transformed for use with 'wsdevice' commands.
* @return serial number for 'wsdevice' commands.
* @see cz.smarteon.loxone.message.LoxoneMessageCommand#oneWireDetails(String)
*/
@Nullable
public String getSerialForCommands() {
if (getSerialNumber() != null) {
return getSerialNumber().replaceAll(":", "");
} else {
return null;

Check warning on line 51 in src/main/java/cz/smarteon/loxone/system/status/Device.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/cz/smarteon/loxone/system/status/Device.java#L51

Added line #L51 was not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public List<OneWireDevice> getDevices() {
/**
* Serial number transformed to the form for getting one wire details.
* @return serial number for one wire details command.
* @see cz.smarteon.loxone.message.LoxoneMessageCommand#oneWireDetails(String)
* @see cz.smarteon.loxone.message.LoxoneMessageCommand#multiExtensionAirOneWireDetails(String)
*/
@NotNull
public String getSerialForOneWireDetails() {
if (getSerialNumber() != null) {
return getSerialNumber().replaceAll(":", "").substring(8).toLowerCase();
final String serial = getSerialForCommands();
if (serial != null) {
return serial;
} else {
throw new IllegalStateException("MultiExtensionAir must have set serial number");
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/system/status/MiniserverStatusTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class MiniserverStatusTest {

expectThat(airBaseExtensions[0].devices[2] as MultiExtensionAir) {
get { devices }.hasSize(3)
get { serialForOneWireDetails }.isEqualTo("fe894bc6")
get { serialForOneWireDetails }.isEqualTo("504F94FFFE894BC6")
}

val treeExtensions = ms.getExtensions(TreeExtension::class.java)
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/message/oneWireDetails.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"
1-Wire Serial 28.BB.CE.AD.07.00.00.2F: 2709 Packet Requests, 0 CRC Errors, 0 85 Degree Problems;
1-Wire Serial 28.62.A9.AC.0A.00.00.A2: 13 Packet Requests, 1230000 CRC Errors, 5 85 Degree Problems; "
Serial 28.62.A9.AC.0A.00.00.A2: 13 Packet Requests, 1230000 CRC Errors, 5 85 Degree Problems; "

0 comments on commit 5890bcf

Please sign in to comment.