From 48280c9239e9c2b4305787ec80118bae5cf0fe2b Mon Sep 17 00:00:00 2001 From: janklug Date: Tue, 17 Nov 2020 10:02:57 +0100 Subject: [PATCH 1/2] Updated for FRITZ-Dect 500 devices --- build.gradle | 4 +- .../fritzbox/mapping/Deserializer.java | 1 + .../model/homeautomation/ColorControl.java | 60 +++++++++++++++++++ .../fritzbox/model/homeautomation/Device.java | 18 ++++++ .../model/homeautomation/EtsiUnitInfo.java | 46 ++++++++++++++ .../model/homeautomation/LevelControl.java | 39 ++++++++++++ .../homeautomation/SimpleOnOffState.java | 2 +- .../fritzbox/mapping/DeserializerTest.java | 25 +++++++- ...eviceListConnectedFritzDect200Payload.xml} | 0 ...deviceListConnectedFritzDect301Payload.xml | 32 ++++++++++ ...deviceListConnectedFritzDect500Payload.xml | 24 ++++++++ ...iceListNotConnectedFritzDect500Payload.xml | 24 ++++++++ 12 files changed, 270 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/ColorControl.java create mode 100644 src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/EtsiUnitInfo.java create mode 100644 src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/LevelControl.java rename src/test/resources/{deviceListPayload.xml => deviceListConnectedFritzDect200Payload.xml} (100%) create mode 100644 src/test/resources/deviceListConnectedFritzDect301Payload.xml create mode 100644 src/test/resources/deviceListConnectedFritzDect500Payload.xml create mode 100644 src/test/resources/deviceListNotConnectedFritzDect500Payload.xml diff --git a/build.gradle b/build.gradle index cf6527a..6a79c6a 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ repositories { } group 'com.github.kaklakariada' -version = '1.1.0' +version = '1.2.0-SNAPSHOT' sourceCompatibility = 1.8 tasks.withType(JavaCompile) { @@ -39,7 +39,7 @@ dependencies { license { header = file('gradle/license-header.txt') - exclude('**/deviceListPayload.xml') + exclude('**/deviceList*Payload.xml') } task sourceJar(type: Jar) { diff --git a/src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java b/src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java index f035eca..34ae210 100644 --- a/src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java +++ b/src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java @@ -39,6 +39,7 @@ public Deserializer() { } public T parse(String data, Class resultType) { + //LOG.info("parsing data:"+data); if (resultType == String.class) { return resultType.cast(data); } diff --git a/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/ColorControl.java b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/ColorControl.java new file mode 100644 index 0000000..d9bbe3d --- /dev/null +++ b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/ColorControl.java @@ -0,0 +1,60 @@ +/** + * A Java API for managing FritzBox HomeAutomation + * Copyright (C) 2017 Christoph Pirkl + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.github.kaklakariada.fritzbox.model.homeautomation; + +import org.simpleframework.xml.Attribute; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; + +@Root(name = "colorcontrol") +public class ColorControl { + @Element(name = "hue", required = false) + private String hue; + + @Element(name = "saturation", required = false) + private String saturation; + + @Element(name = "temperature", required = false) + private String temperature; + + @Attribute(name = "supported_modes") + private String supportedModes; + + @Attribute(name = "current_mode", required = false) + private String current_mode; + + public String getHue() { + return hue; + } + + public String getSaturation() { + return saturation; + } + + public String getTemperature() { + return temperature; + } + + public String getSupportedModes() { + return supportedModes; + } + + public String getCurrent_mode() { + return current_mode; + } +} diff --git a/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/Device.java b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/Device.java index 7eb4e24..c1ccb71 100644 --- a/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/Device.java +++ b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/Device.java @@ -61,6 +61,12 @@ public class Device { private Temperature temperature; @Element(name = "hkr", required = false) private Hkr hkr; + @Element(name = "levelcontrol", required = false) + private LevelControl levelControl; + @Element(name = "colorcontrol", required = false) + private ColorControl colorControl; + @Element(name = "etsiunitinfo", required = false) + private EtsiUnitInfo etsiUnitInfo; public String getIdentifier() { return identifier; @@ -126,6 +132,18 @@ public SimpleOnOffState getSimpleOnOff() { return simpleOnOff; } + public LevelControl getLevelControl() { + return levelControl; + } + + public ColorControl getColorControl() { + return colorControl; + } + + public EtsiUnitInfo getEtsiUnitInfo() { + return etsiUnitInfo; + } + @Override public String toString() { return "Device [identifier=" + identifier + ", id=" + id + ", functionBitmask=" + functionBitmask diff --git a/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/EtsiUnitInfo.java b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/EtsiUnitInfo.java new file mode 100644 index 0000000..2850e05 --- /dev/null +++ b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/EtsiUnitInfo.java @@ -0,0 +1,46 @@ +/** + * A Java API for managing FritzBox HomeAutomation + * Copyright (C) 2017 Christoph Pirkl + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.github.kaklakariada.fritzbox.model.homeautomation; + +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; + +@Root(name = "etsiunitinfo") +public class EtsiUnitInfo { + + @Element(name = "etsideviceid") + private int etsideviceid; + + @Element(name = "unittype") + private int unittype; + + @Element(name = "interfaces") + private String interfaces; + + public int getEtsideviceid() { + return etsideviceid; + } + + public int getUnittype() { + return unittype; + } + + public String getInterfaces() { + return interfaces; + } +} diff --git a/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/LevelControl.java b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/LevelControl.java new file mode 100644 index 0000000..710a8b7 --- /dev/null +++ b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/LevelControl.java @@ -0,0 +1,39 @@ +/** + * A Java API for managing FritzBox HomeAutomation + * Copyright (C) 2017 Christoph Pirkl + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.github.kaklakariada.fritzbox.model.homeautomation; + +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; + +@Root(name = "levelcontrol") +public class LevelControl { + + @Element(name = "level", required = false) + private int level; + + @Element(name = "levelpercentage", required = false) + private int levelpercentage; + + public int getLevel() { + return level; + } + + public int getLevelpercentage() { + return levelpercentage; + } +} diff --git a/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/SimpleOnOffState.java b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/SimpleOnOffState.java index be7e7ce..d1c8fbd 100644 --- a/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/SimpleOnOffState.java +++ b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/SimpleOnOffState.java @@ -23,7 +23,7 @@ @Root(name = "simpleonoff") public class SimpleOnOffState { - @Element(name = "state") + @Element(name = "state", required = false) private int state; public int getState() { diff --git a/src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java b/src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java index be7b3e5..db01728 100644 --- a/src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java +++ b/src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java @@ -30,8 +30,29 @@ public class DeserializerTest { @Test - public void parseDeviceList() throws IOException { - final String fileContent = Files.readAllLines(Paths.get("src/test/resources/deviceListPayload.xml")).stream() + public void parseDeviceListFritzDect200() throws IOException { + final String fileContent = Files.readAllLines(Paths.get("src/test/resources/deviceListConnectedFritzDect200Payload.xml")).stream() + .collect(joining("\n")); + new Deserializer().parse(fileContent, DeviceList.class); + } + + @Test + public void parseDeviceListFritzDect301() throws IOException { + final String fileContent = Files.readAllLines(Paths.get("src/test/resources/deviceListConnectedFritzDect200Payload.xml")).stream() + .collect(joining("\n")); + new Deserializer().parse(fileContent, DeviceList.class); + } + + @Test + public void parseDeviceListNotConnectedFritzDect500() throws IOException { + final String fileContent = Files.readAllLines(Paths.get("src/test/resources/deviceListNotConnectedFritzDect500Payload.xml")).stream() + .collect(joining("\n")); + new Deserializer().parse(fileContent, DeviceList.class); + } + + @Test + public void parseDeviceListConnectedFritzDect500() throws IOException { + final String fileContent = Files.readAllLines(Paths.get("src/test/resources/deviceListConnectedFritzDect500Payload.xml")).stream() .collect(joining("\n")); new Deserializer().parse(fileContent, DeviceList.class); } diff --git a/src/test/resources/deviceListPayload.xml b/src/test/resources/deviceListConnectedFritzDect200Payload.xml similarity index 100% rename from src/test/resources/deviceListPayload.xml rename to src/test/resources/deviceListConnectedFritzDect200Payload.xml diff --git a/src/test/resources/deviceListConnectedFritzDect301Payload.xml b/src/test/resources/deviceListConnectedFritzDect301Payload.xml new file mode 100644 index 0000000..7fd19e7 --- /dev/null +++ b/src/test/resources/deviceListConnectedFritzDect301Payload.xml @@ -0,0 +1,32 @@ + + 1 + 0 + FRITZ!DECT 301 + 100 + 0 + + 235 + 0 + + + 47 + 46 + 28 + 46 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 100 + + 1605643200 + 28 + + 0 + 0 + + \ No newline at end of file diff --git a/src/test/resources/deviceListConnectedFritzDect500Payload.xml b/src/test/resources/deviceListConnectedFritzDect500Payload.xml new file mode 100644 index 0000000..c7c82e8 --- /dev/null +++ b/src/test/resources/deviceListConnectedFritzDect500Payload.xml @@ -0,0 +1,24 @@ + + + 0 + 0 + FRITZ!DECT 500 power + + 1 + + + 153 + 60 + + + 225 + 204 + 6500 + + + 406 + 278 + 512,514,513 + + + \ No newline at end of file diff --git a/src/test/resources/deviceListNotConnectedFritzDect500Payload.xml b/src/test/resources/deviceListNotConnectedFritzDect500Payload.xml new file mode 100644 index 0000000..273f546 --- /dev/null +++ b/src/test/resources/deviceListNotConnectedFritzDect500Payload.xml @@ -0,0 +1,24 @@ + + + 0 + 0 + FRITZ!DECT 500 without power + + + + + + + + + + + + + + 406 + 278 + 512,514,513 + + + \ No newline at end of file From a8b2ad192497c3ac73ffe2ce71a07780226b2947 Mon Sep 17 00:00:00 2001 From: janklug Date: Wed, 2 Dec 2020 18:17:58 +0100 Subject: [PATCH 2/2] Implemented MR comments --- .../com/github/kaklakariada/fritzbox/mapping/Deserializer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java b/src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java index 34ae210..f035eca 100644 --- a/src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java +++ b/src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java @@ -39,7 +39,6 @@ public Deserializer() { } public T parse(String data, Class resultType) { - //LOG.info("parsing data:"+data); if (resultType == String.class) { return resultType.cast(data); }