diff --git a/bundles/org.openhab.binding.tr064/README.md b/bundles/org.openhab.binding.tr064/README.md index e9b97d90fce46..16ff47fc72270 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 | +| `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. 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..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 @@ -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": @@ -168,6 +171,35 @@ public Optional 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 * 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 ba7ff1b7e9708..afccf5454851c 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,66 @@ pattern="([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}(\s*#.*)*"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 @@ +