[tr064] Add Wifi Signal Strength & Wifi Speed channels to LAN Subdevice (#10959)

* 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>
This commit is contained in:
Tobi 2021-07-31 13:01:20 +02:00 committed by GitHub
parent 4b57ea28c8
commit a1ec5eb241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 108 additions and 2 deletions

View 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. | | `wifi5GHzEnable` | `Switch` | | Enable/Disable the 5.0 GHz WiFi device. |
| `wifiGuestEnable` | `Switch` | | Enable/Disable the guest WiFi. | | `wifiGuestEnable` | `Switch` | | Enable/Disable the guest WiFi. |
| `macOnline` | `Switch` | x | Online status of the device with the given MAC | | `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. Older FritzBox devices may not support 5 GHz WiFi.
In this case you have to use the `wifi5GHzEnable` channel for switching the guest WiFi. In this case you have to use the `wifi5GHzEnable` channel for switching the guest WiFi.

View File

@ -82,6 +82,7 @@ public class SOAPValueConverter {
return Optional.empty(); return Optional.empty();
} }
switch (dataType) { switch (dataType) {
case "ui1":
case "ui2": case "ui2":
return Optional.of(String.valueOf(value.shortValue())); return Optional.of(String.valueOf(value.shortValue()));
case "i4": case "i4":
@ -92,6 +93,7 @@ public class SOAPValueConverter {
} else if (command instanceof DecimalType) { } else if (command instanceof DecimalType) {
BigDecimal value = ((DecimalType) command).toBigDecimal(); BigDecimal value = ((DecimalType) command).toBigDecimal();
switch (dataType) { switch (dataType) {
case "ui1":
case "ui2": case "ui2":
return Optional.of(String.valueOf(value.shortValue())); return Optional.of(String.valueOf(value.shortValue()));
case "i4": case "i4":
@ -132,6 +134,7 @@ public class SOAPValueConverter {
return rawValue.equals("0") ? OnOffType.OFF : OnOffType.ON; return rawValue.equals("0") ? OnOffType.OFF : OnOffType.ON;
case "string": case "string":
return new StringType(rawValue); return new StringType(rawValue);
case "ui1":
case "ui2": case "ui2":
case "i4": case "i4":
case "ui4": case "ui4":
@ -168,6 +171,35 @@ public class SOAPValueConverter {
}).or(Optional::empty); }).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 * post processor for answering machine new messages channel
* *

View File

@ -19,6 +19,7 @@ import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.time.Duration; import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -178,6 +179,13 @@ public class Util {
.forEach(channelTypeDescription -> { .forEach(channelTypeDescription -> {
String channelId = channelTypeDescription.getName(); String channelId = channelTypeDescription.getName();
String serviceId = channelTypeDescription.getService().getServiceId(); 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<>(); Set<String> parameters = new HashSet<>();
try { try {
SCPDServiceType deviceService = scpdUtil.getDevice(deviceId) SCPDServiceType deviceService = scpdUtil.getDevice(deviceId)
@ -232,7 +240,7 @@ public class Util {
ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId); ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId);
ChannelBuilder channelBuilder = ChannelBuilder ChannelBuilder channelBuilder = ChannelBuilder
.create(channelUID, channelTypeDescription.getItem().getType()) .create(channelUID, channelTypeDescription.getItem().getType())
.withType(channelTypeUID); .withType(channelTypeUID).withProperties(channelProperties);
thingBuilder.withChannel(channelBuilder.build()); thingBuilder.withChannel(channelBuilder.build());
channels.put(channelUID, channelConfig); channels.put(channelUID, channelConfig);
} else { } else {
@ -246,7 +254,7 @@ public class Util {
channelId + "_" + normalizedParameter); channelId + "_" + normalizedParameter);
ChannelBuilder channelBuilder = ChannelBuilder ChannelBuilder channelBuilder = ChannelBuilder
.create(channelUID, channelTypeDescription.getItem().getType()) .create(channelUID, channelTypeDescription.getItem().getType())
.withType(channelTypeUID) .withType(channelTypeUID).withProperties(channelProperties)
.withLabel(channelTypeDescription.getLabel() + " " + parameter); .withLabel(channelTypeDescription.getLabel() + " " + parameter);
thingBuilder.withChannel(channelBuilder.build()); thingBuilder.withChannel(channelBuilder.build());
Tr064ChannelConfig channelConfig1 = new Tr064ChannelConfig(channelConfig); Tr064ChannelConfig channelConfig1 = new Tr064ChannelConfig(channelConfig);

View File

@ -146,6 +146,66 @@
pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/> pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/>
</getAction> </getAction>
</channel> </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 --> <!-- WAN Device -->
<channel name="wanAccessType" label="Access Type"> <channel name="wanAccessType" label="Access Type">

View File

@ -46,6 +46,7 @@
<xs:attribute type="xs:string" name="name" use="required"/> <xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:string" name="label"/> <xs:attribute type="xs:string" name="label"/>
<xs:attribute type="xs:string" name="description"/> <xs:attribute type="xs:string" name="description"/>
<xs:attribute type="xs:string" name="typeId"/>
<xs:attribute type="xs:boolean" name="advanced" default="false"/> <xs:attribute type="xs:boolean" name="advanced" default="false"/>
</xs:complexType> </xs:complexType>
<xs:complexType name="channelTypeDescriptions"> <xs:complexType name="channelTypeDescriptions">