]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tr064] Add Wifi Signal Strength & Wifi Speed channels to LAN Subdevice (#10959)
authorTobi <tobiloeb@gmail.com>
Sat, 31 Jul 2021 11:01:20 +0000 (13:01 +0200)
committerGitHub <noreply@github.com>
Sat, 31 Jul 2021 11:01:20 +0000 (13:01 +0200)
* Add channels to tr064

Signed-off-by: Tobias Löbermann <tobiloeb@gmail.com>
* Set typeId for macSignalStrength channels

Signed-off-by: Tobias Loebermann <tobiloeb@gmail.com>
* adjust README with correct channel names.

Signed-off-by: Tobias Loebermann <tobiloeb@gmail.com>
* Add JavaDoc and separate post processors.

Signed-off-by: Tobias Loebermann <tobiloeb@gmail.com>
* Use UNDEF as default for signal-strength

Signed-off-by: Tobias Loebermann <tobiloeb@gmail.com>
* Update README.md documentation

Signed-off-by: Tobias Loebermann <tobiloeb@gmail.com>
bundles/org.openhab.binding.tr064/README.md
bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java
bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/util/Util.java
bundles/org.openhab.binding.tr064/src/main/resources/channels.xml
bundles/org.openhab.binding.tr064/src/main/resources/xsd/channeltypes.xsd

index e9b97d90fce462cbfa49213a1e18ff12f049e542..16ff47fc7227010686fdde13b36fc8d2ea45965a 100644 (file)
@@ -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                            |
+| `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.
index 9a7d645be168b31365e88e4f72d1198b1219f439..e175b22273d0583a9f2565dcf2644b932ed069be 100644 (file)
@@ -82,6 +82,7 @@ public class SOAPValueConverter {
                 return Optional.empty();
             }
             switch (dataType) {
+                case "ui1":
                 case "ui2":
                     return Optional.of(String.valueOf(value.shortValue()));
                 case "i4":
@@ -92,6 +93,7 @@ public class SOAPValueConverter {
         } 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 class SOAPValueConverter {
                     return rawValue.equals("0") ? OnOffType.OFF : OnOffType.ON;
                 case "string":
                     return new StringType(rawValue);
+                case "ui1":
                 case "ui2":
                 case "i4":
                 case "ui4":
@@ -168,6 +171,35 @@ public class SOAPValueConverter {
         }).or(Optional::empty);
     }
 
+    /**
+     * 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
+     * @return the mapped system.signal-strength in range 0-4
+     */
+    @SuppressWarnings("unused")
+    private State processMacSignalStrength(State state, Tr064ChannelConfig channelConfig) {
+        State mappedSignalStrength = UnDefType.UNDEF;
+        DecimalType currentStateValue = state.as(DecimalType.class);
+
+        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;
+    }
+
     /**
      * post processor for answering machine new messages channel
      *
index 4655e5fedc2abcf42be38d9c23aca0a8e2fdd2a3..b92acd997331309d68828e7199b75c0a42a868d4 100644 (file)
@@ -19,6 +19,7 @@ import java.io.InputStream;
 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 class Util {
                 .forEach(channelTypeDescription -> {
                     String channelId = channelTypeDescription.getName();
                     String serviceId = channelTypeDescription.getService().getServiceId();
+                    String typeId = channelTypeDescription.getTypeId();
+                    Map<String, String> channelProperties = new HashMap<String, String>();
+
+                    if (typeId != null) {
+                        channelProperties.put("typeId", typeId);
+                    }
+
                     Set<String> parameters = new HashSet<>();
                     try {
                         SCPDServiceType deviceService = scpdUtil.getDevice(deviceId)
@@ -232,7 +240,7 @@ public class Util {
                             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 class Util {
                                         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);
index ba7ff1b7e9708862e3da4eada887b8da0bb3792d..afccf5454851cb6782f0059bbc03a67199933c8c 100644 (file)
                                pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/>
                </getAction>
        </channel>
+       <channel name="macIP" label="MAC IP" description="IP of the device with the given MAC">
+               <item type="String"/>
+               <service deviceType="urn:dslforum-org:device:LANDevice:1" serviceId="urn:LanDeviceHosts-com:serviceId:Hosts1"/>
+               <getAction name="GetSpecificHostEntry" argument="NewIPAddress">
+                       <parameter name="NewMACAddress" thingParameter="macOnline"
+                               pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/>
+               </getAction>
+       </channel>
+
+       <!-- WLAN Config 1 - 2.4 Ghz -->
+       <channel name="macSignalStrength1" label="MAC Wifi Signal Strength 2.4Ghz"
+               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">
+               <item type="Number"/>
+               <service deviceType="urn:dslforum-org:device:LANDevice:1"
+                       serviceId="urn:WLANConfiguration-com:serviceId:WLANConfiguration1"/>
+               <getAction name="GetSpecificAssociatedDeviceInfo" argument="NewX_AVM-DE_SignalStrength"
+                       postProcessor="processMacSignalStrength">
+                       <parameter name="NewAssociatedDeviceMACAddress" thingParameter="macOnline"
+                               pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/>
+               </getAction>
+       </channel>
+       <channel name="macSpeed1" label="MAC Wifi Speed 2.4Ghz"
+               description="Wifi Speed of the device with
+               the given MAC. This is set in case the Device is connected to 2.4Ghz">
+               <item type="Number:DataTransferRate" unit="Mbit/s" statePattern="%d Mbit/s"/>
+               <service deviceType="urn:dslforum-org:device:LANDevice:1"
+                       serviceId="urn:WLANConfiguration-com:serviceId:WLANConfiguration1"/>
+               <getAction name="GetSpecificAssociatedDeviceInfo" argument="NewX_AVM-DE_Speed">
+                       <parameter name="NewAssociatedDeviceMACAddress" thingParameter="macOnline"
+                               pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/>
+               </getAction>
+       </channel>
+
+       <!-- WLAN Config 2 - 5 Ghz -->
+       <channel name="macSignalStrength2" label="MAC Wifi Signal Strength 5Ghz"
+               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">
+               <item type="Number"/>
+               <service deviceType="urn:dslforum-org:device:LANDevice:1"
+                       serviceId="urn:WLANConfiguration-com:serviceId:WLANConfiguration2"/>
+               <getAction name="GetSpecificAssociatedDeviceInfo" argument="NewX_AVM-DE_SignalStrength"
+                       postProcessor="processMacSignalStrength">
+                       <parameter name="NewAssociatedDeviceMACAddress" thingParameter="macOnline"
+                               pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/>
+               </getAction>
+       </channel>
+       <channel name="macSpeed2" label="MAC Wifi Speed 5Ghz"
+               description="Wifi Speed of the device with
+               the given MAC. This is set in case the Device is connected to 5Ghz">
+               <item type="Number:DataTransferRate" unit="Mbit/s" statePattern="%d Mbit/s"/>
+               <service deviceType="urn:dslforum-org:device:LANDevice:1"
+                       serviceId="urn:WLANConfiguration-com:serviceId:WLANConfiguration2"/>
+               <getAction name="GetSpecificAssociatedDeviceInfo" argument="NewX_AVM-DE_Speed">
+                       <parameter name="NewAssociatedDeviceMACAddress" thingParameter="macOnline"
+                               pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/>
+               </getAction>
+       </channel>
 
        <!-- WAN Device -->
        <channel name="wanAccessType" label="Access Type">
index 87a7691957cd83a0d7692801eda348f551733ccd..cbc7c26c0b24e7506d0a42542460e6fad9a11b8e 100644 (file)
@@ -46,6 +46,7 @@
         <xs:attribute type="xs:string" name="name" use="required"/>
         <xs:attribute type="xs:string" name="label"/>
         <xs:attribute type="xs:string" name="description"/>
+        <xs:attribute type="xs:string" name="typeId"/>
         <xs:attribute type="xs:boolean" name="advanced" default="false"/>
     </xs:complexType>
     <xs:complexType name="channelTypeDescriptions">