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

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

Merged
merged 7 commits into from
Jul 31, 2021
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
5 changes: 5 additions & 0 deletions bundles/org.openhab.binding.tr064/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public Optional<String> getSOAPValueFromCommand(Command command, String dataType
return Optional.empty();
}
switch (dataType) {
case "ui1":
case "ui2":
return Optional.of(String.valueOf(value.shortValue()));
case "i4":
Expand All @@ -92,6 +93,7 @@ public Optional<String> 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":
Expand Down Expand Up @@ -132,6 +134,7 @@ public Optional<State> 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":
Expand Down Expand Up @@ -168,6 +171,35 @@ public Optional<State> getStateFromSOAPValue(SOAPMessage soapMessage, String ele
}).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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,66 @@
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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down