Skip to content
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

feat(status): support OneWireDetails for MultiExtensionAir #210

Merged
merged 1 commit into from
Feb 15, 2024
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
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 @@
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 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; "
Loading