From a5df2633b5001e4e7811c386abddc3992fbbc37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=B6bermann?= Date: Wed, 7 Jul 2021 20:50:25 +0200 Subject: [PATCH 1/6] Add channels to tr064 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tobias Löbermann --- bundles/org.openhab.binding.tr064/README.md | 5 ++ .../internal/soap/SOAPValueConverter.java | 3 + .../src/main/resources/channels.xml | 56 +++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/bundles/org.openhab.binding.tr064/README.md b/bundles/org.openhab.binding.tr064/README.md index e9b97d90fce46..e60f652b7be08 100644 --- a/bundles/org.openhab.binding.tr064/README.md +++ b/bundles/org.openhab.binding.tr064/README.md @@ -119,6 +119,11 @@ The call-types are the same as provided by the FritzBox, i.e. `1` (inbound), `2` | `wifi5GHzEnable` | `Switch` | | Enable/Disable the 5.0 GHz WiFi device. | | `wifiGuestEnable` | `Switch` | | Enable/Disable the guest WiFi. | | `macOnline` | `Switch` | x | Online status of the device with the given MAC | +| `macIP` | `String` | x | IP of the device with the given MAC | +| `macSignalStrengthConfig1` | `Number:Dimensionless` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | +| `macSpeedConfig1` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | +| `macSignalStrengthConfig2` | `Number:Dimensionless` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 5Ghz | +| `macSpeedConfig2` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 5Ghz | Older FritzBox devices may not support 5 GHz WiFi. In this case you have to use the `wifi5GHzEnable` channel for switching the guest WiFi. diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java index 9a7d645be168b..71398527740f4 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java @@ -82,6 +82,7 @@ public Optional getSOAPValueFromCommand(Command command, String dataType return Optional.empty(); } switch (dataType) { + case "ui1": case "ui2": return Optional.of(String.valueOf(value.shortValue())); case "i4": @@ -92,6 +93,7 @@ public Optional getSOAPValueFromCommand(Command command, String dataType } else if (command instanceof DecimalType) { BigDecimal value = ((DecimalType) command).toBigDecimal(); switch (dataType) { + case "ui1": case "ui2": return Optional.of(String.valueOf(value.shortValue())); case "i4": @@ -132,6 +134,7 @@ public Optional getStateFromSOAPValue(SOAPMessage soapMessage, String ele return rawValue.equals("0") ? OnOffType.OFF : OnOffType.ON; case "string": return new StringType(rawValue); + case "ui1": case "ui2": case "i4": case "ui4": diff --git a/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml b/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml index ba7ff1b7e9708..7a276e6143457 100644 --- a/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml +++ b/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml @@ -146,6 +146,62 @@ pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 75b45bf84e2984df5f85962750d63fba6046c9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=B6bermann?= Date: Wed, 28 Jul 2021 20:41:44 +0200 Subject: [PATCH 2/6] Set typeId for macSignalStrength channels Signed-off-by: Tobias Loebermann --- .../internal/soap/SOAPValueConverter.java | 20 ++++++++++++++++ .../binding/tr064/internal/util/Util.java | 12 ++++++++-- .../src/main/resources/channels.xml | 24 +++++++++++-------- .../src/main/resources/xsd/channeltypes.xsd | 1 + 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java index 71398527740f4..c4cd7f54c458a 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java @@ -171,6 +171,26 @@ public Optional getStateFromSOAPValue(SOAPMessage soapMessage, String ele }).or(Optional::empty); } + /** + * post processor to map mac device signal strength to system.signal-strength 0-4 + */ + private State processMacSignalStrength(State state, Tr064ChannelConfig channelConfig) { + DecimalType mappedSignalStrength = new DecimalType(0); + DecimalType currentStateValue = state.as(DecimalType.class); + + if (currentStateValue.intValue() > 80) { + mappedSignalStrength = new DecimalType(4); + } else if (currentStateValue.intValue() > 60) { + mappedSignalStrength = new DecimalType(3); + } else if (currentStateValue.intValue() > 40) { + mappedSignalStrength = new DecimalType(2); + } else if (currentStateValue.intValue() > 20) { + mappedSignalStrength = new DecimalType(1); + } + + return mappedSignalStrength; + } + /** * post processor for answering machine new messages channel * diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/util/Util.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/util/Util.java index 4655e5fedc2ab..b92acd9973313 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/util/Util.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/util/Util.java @@ -19,6 +19,7 @@ import java.lang.reflect.Field; import java.time.Duration; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -178,6 +179,13 @@ public static void checkAvailableChannels(Thing thing, ThingBuilder thingBuilder .forEach(channelTypeDescription -> { String channelId = channelTypeDescription.getName(); String serviceId = channelTypeDescription.getService().getServiceId(); + String typeId = channelTypeDescription.getTypeId(); + Map channelProperties = new HashMap(); + + if (typeId != null) { + channelProperties.put("typeId", typeId); + } + Set parameters = new HashSet<>(); try { SCPDServiceType deviceService = scpdUtil.getDevice(deviceId) @@ -232,7 +240,7 @@ public static void checkAvailableChannels(Thing thing, ThingBuilder thingBuilder ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId); ChannelBuilder channelBuilder = ChannelBuilder .create(channelUID, channelTypeDescription.getItem().getType()) - .withType(channelTypeUID); + .withType(channelTypeUID).withProperties(channelProperties); thingBuilder.withChannel(channelBuilder.build()); channels.put(channelUID, channelConfig); } else { @@ -246,7 +254,7 @@ public static void checkAvailableChannels(Thing thing, ThingBuilder thingBuilder channelId + "_" + normalizedParameter); ChannelBuilder channelBuilder = ChannelBuilder .create(channelUID, channelTypeDescription.getItem().getType()) - .withType(channelTypeUID) + .withType(channelTypeUID).withProperties(channelProperties) .withLabel(channelTypeDescription.getLabel() + " " + parameter); thingBuilder.withChannel(channelBuilder.build()); Tr064ChannelConfig channelConfig1 = new Tr064ChannelConfig(channelConfig); diff --git a/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml b/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml index 7a276e6143457..11e5d17c019ef 100644 --- a/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml +++ b/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml @@ -156,18 +156,20 @@ - - + the given MAC. This is set in case the Device is connected to 2.4Ghz" + typeId="system.signal-strength"> + - + - @@ -180,18 +182,20 @@ - - + the given MAC. This is set in case the Device is connected to 5Ghz" + typeId="system.signal-strength"> + - + - diff --git a/bundles/org.openhab.binding.tr064/src/main/resources/xsd/channeltypes.xsd b/bundles/org.openhab.binding.tr064/src/main/resources/xsd/channeltypes.xsd index 87a7691957cd8..cbc7c26c0b24e 100644 --- a/bundles/org.openhab.binding.tr064/src/main/resources/xsd/channeltypes.xsd +++ b/bundles/org.openhab.binding.tr064/src/main/resources/xsd/channeltypes.xsd @@ -46,6 +46,7 @@ + From 0e30a31e485c1d5d61c74b946754d6e361b8be9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=B6bermann?= Date: Wed, 28 Jul 2021 20:43:52 +0200 Subject: [PATCH 3/6] adjust README with correct channel names. Signed-off-by: Tobias Loebermann --- bundles/org.openhab.binding.tr064/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.tr064/README.md b/bundles/org.openhab.binding.tr064/README.md index e60f652b7be08..b646999d3e6c8 100644 --- a/bundles/org.openhab.binding.tr064/README.md +++ b/bundles/org.openhab.binding.tr064/README.md @@ -120,10 +120,10 @@ The call-types are the same as provided by the FritzBox, i.e. `1` (inbound), `2` | `wifiGuestEnable` | `Switch` | | Enable/Disable the guest WiFi. | | `macOnline` | `Switch` | x | Online status of the device with the given MAC | | `macIP` | `String` | x | IP of the device with the given MAC | -| `macSignalStrengthConfig1` | `Number:Dimensionless` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | -| `macSpeedConfig1` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | -| `macSignalStrengthConfig2` | `Number:Dimensionless` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 5Ghz | -| `macSpeedConfig2` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 5Ghz | +| `macSignalStrength1` | `Number:Dimensionless` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | +| `macSpeed1` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | +| `macSignalStrength2` | `Number:Dimensionless` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 5Ghz | +| `macSpeed2` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 5Ghz | Older FritzBox devices may not support 5 GHz WiFi. In this case you have to use the `wifi5GHzEnable` channel for switching the guest WiFi. From c1105c6981ddaa900d5652650ac671004f0259ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=B6bermann?= Date: Wed, 28 Jul 2021 22:20:21 +0200 Subject: [PATCH 4/6] Add JavaDoc and separate post processors. Signed-off-by: Tobias Loebermann --- .../internal/soap/SOAPValueConverter.java | 31 +++++++++++++++++-- .../src/main/resources/channels.xml | 4 +-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java index c4cd7f54c458a..4ce6610ca9ead 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java @@ -172,9 +172,36 @@ public Optional getStateFromSOAPValue(SOAPMessage soapMessage, String ele } /** - * post processor to map mac device signal strength to system.signal-strength 0-4 + * post processor to map mac device 2.4Ghz signal strength to system.signal-strength 0-4 + * + * @param state with signalStrength + * @param channelConfig channel config of the mac signal strength 2.4Ghz + * @return the mapped system.signal-strength in range 0-4 + */ + @SuppressWarnings("unused") + private State processMacSignalStrength1(State state, Tr064ChannelConfig channelConfig) { + return this.processMacSignalStrength(state); + } + + /** + * post processor to map mac device 5Ghz signal strength to system.signal-strength 0-4 + * + * @param state with signal strength + * @param channelConfig channel config of the mac signal strength 5Ghz + * @return the mapped system.signal-strength in range 0-4 + */ + @SuppressWarnings("unused") + private State processMacSignalStrength2(State state, Tr064ChannelConfig channelConfig) { + return this.processMacSignalStrength(state); + } + + /** + * internal helper to map the mac signal strength. + * + * @param state with signalStrength + * @return the mapped system.signal-strength */ - private State processMacSignalStrength(State state, Tr064ChannelConfig channelConfig) { + private State processMacSignalStrength(State state) { DecimalType mappedSignalStrength = new DecimalType(0); DecimalType currentStateValue = state.as(DecimalType.class); diff --git a/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml b/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml index 11e5d17c019ef..44be81867a51c 100644 --- a/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml +++ b/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml @@ -164,7 +164,7 @@ + postProcessor="processMacSignalStrength1"> @@ -190,7 +190,7 @@ + postProcessor="processMacSignalStrength2"> From f1bbe634d3d40e3e7a977e03b5f8fa018ce8326d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=B6bermann?= Date: Fri, 30 Jul 2021 20:15:07 +0200 Subject: [PATCH 5/6] Use UNDEF as default for signal-strength Signed-off-by: Tobias Loebermann --- .../internal/soap/SOAPValueConverter.java | 50 ++++++------------- .../src/main/resources/channels.xml | 8 +-- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java index 4ce6610ca9ead..e175b22273d05 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java @@ -172,47 +172,29 @@ public Optional getStateFromSOAPValue(SOAPMessage soapMessage, String ele } /** - * post processor to map mac device 2.4Ghz signal strength to system.signal-strength 0-4 + * post processor to map mac device signal strength to system.signal-strength 0-4 * * @param state with signalStrength - * @param channelConfig channel config of the mac signal strength 2.4Ghz + * @param channelConfig channel config of the mac signal strength * @return the mapped system.signal-strength in range 0-4 */ @SuppressWarnings("unused") - private State processMacSignalStrength1(State state, Tr064ChannelConfig channelConfig) { - return this.processMacSignalStrength(state); - } - - /** - * post processor to map mac device 5Ghz signal strength to system.signal-strength 0-4 - * - * @param state with signal strength - * @param channelConfig channel config of the mac signal strength 5Ghz - * @return the mapped system.signal-strength in range 0-4 - */ - @SuppressWarnings("unused") - private State processMacSignalStrength2(State state, Tr064ChannelConfig channelConfig) { - return this.processMacSignalStrength(state); - } - - /** - * internal helper to map the mac signal strength. - * - * @param state with signalStrength - * @return the mapped system.signal-strength - */ - private State processMacSignalStrength(State state) { - DecimalType mappedSignalStrength = new DecimalType(0); + private State processMacSignalStrength(State state, Tr064ChannelConfig channelConfig) { + State mappedSignalStrength = UnDefType.UNDEF; DecimalType currentStateValue = state.as(DecimalType.class); - if (currentStateValue.intValue() > 80) { - mappedSignalStrength = new DecimalType(4); - } else if (currentStateValue.intValue() > 60) { - mappedSignalStrength = new DecimalType(3); - } else if (currentStateValue.intValue() > 40) { - mappedSignalStrength = new DecimalType(2); - } else if (currentStateValue.intValue() > 20) { - mappedSignalStrength = new DecimalType(1); + if (currentStateValue != null) { + if (currentStateValue.intValue() > 80) { + mappedSignalStrength = new DecimalType(4); + } else if (currentStateValue.intValue() > 60) { + mappedSignalStrength = new DecimalType(3); + } else if (currentStateValue.intValue() > 40) { + mappedSignalStrength = new DecimalType(2); + } else if (currentStateValue.intValue() > 20) { + mappedSignalStrength = new DecimalType(1); + } else { + mappedSignalStrength = new DecimalType(0); + } } return mappedSignalStrength; diff --git a/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml b/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml index 44be81867a51c..afccf5454851c 100644 --- a/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml +++ b/bundles/org.openhab.binding.tr064/src/main/resources/channels.xml @@ -160,11 +160,11 @@ description="Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz" typeId="system.signal-strength"> - + + postProcessor="processMacSignalStrength"> @@ -186,11 +186,11 @@ description="Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 5Ghz" typeId="system.signal-strength"> - + + postProcessor="processMacSignalStrength"> From eedc0687fbea4fd03caf5253def583127f98d64d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=B6bermann?= Date: Sat, 31 Jul 2021 12:48:56 +0200 Subject: [PATCH 6/6] Update README.md documentation Signed-off-by: Tobias Loebermann --- bundles/org.openhab.binding.tr064/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.tr064/README.md b/bundles/org.openhab.binding.tr064/README.md index b646999d3e6c8..16ff47fc72270 100644 --- a/bundles/org.openhab.binding.tr064/README.md +++ b/bundles/org.openhab.binding.tr064/README.md @@ -120,10 +120,10 @@ The call-types are the same as provided by the FritzBox, i.e. `1` (inbound), `2` | `wifiGuestEnable` | `Switch` | | Enable/Disable the guest WiFi. | | `macOnline` | `Switch` | x | Online status of the device with the given MAC | | `macIP` | `String` | x | IP of the device with the given MAC | -| `macSignalStrength1` | `Number:Dimensionless` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | -| `macSpeed1` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | -| `macSignalStrength2` | `Number:Dimensionless` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 5Ghz | -| `macSpeed2` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 5Ghz | +| `macSignalStrength1` | `Number` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | +| `macSpeed1` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 2.4Ghz | +| `macSignalStrength2` | `Number` | x | Wifi Signal Strength of the device with the given MAC. This is set in case the Device is connected to 5Ghz | +| `macSpeed2` | `Number:DataTransferRate` | x | Wifi Speed of the device with the given MAC. This is set in case the Device is connected to 5Ghz | Older FritzBox devices may not support 5 GHz WiFi. In this case you have to use the `wifi5GHzEnable` channel for switching the guest WiFi.