From 08f1e5f703c1d6e357914badd94eb336207dfbcf Mon Sep 17 00:00:00 2001 From: "Jan N. Klug" Date: Sat, 2 Jan 2021 17:34:15 +0100 Subject: [PATCH] improvements - fix wanBlockByIP channel - allow comments in parameter lists - fix compiler warnings Signed-off-by: Jan N. Klug --- bundles/org.openhab.binding.tr064/README.md | 4 ++++ .../config/Tr064RootConfiguration.java | 18 +++++++-------- .../phonebook/PhonebookProfileFactory.java | 22 +++---------------- .../internal/soap/SOAPValueConverter.java | 1 - .../binding/tr064/internal/util/Util.java | 4 +++- 5 files changed, 19 insertions(+), 30 deletions(-) diff --git a/bundles/org.openhab.binding.tr064/README.md b/bundles/org.openhab.binding.tr064/README.md index 79e1c6103b435..1cdf2df6c17d0 100644 --- a/bundles/org.openhab.binding.tr064/README.md +++ b/bundles/org.openhab.binding.tr064/README.md @@ -115,6 +115,10 @@ This is an optional parameter and multiple values are allowed. | `wifi5GHzEnable` | `Switch` | | Enable/Disable the 5.0 GHz WiFi device. | | `wifiGuestEnable` | `Switch` | | Enable/Disable the guest WiFi. | +Parameters that accept lists (e.g. `macOnline`, `wanBlockIPs`) can contain comments. +Comments are separated from the value with a '#' (e.g. `192.168.0.77 # Daughter's iPhone`). +The full string is used for the channel label. + ### Channel `callList` Call lists are provided for one or more days (as configured) as JSON. diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/config/Tr064RootConfiguration.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/config/Tr064RootConfiguration.java index 5800a54cc1fd1..6a1f6cacdf37f 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/config/Tr064RootConfiguration.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/config/Tr064RootConfiguration.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.tr064.internal.config; -import java.util.Collections; import java.util.List; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -29,14 +28,15 @@ public class Tr064RootConfiguration extends Tr064BaseThingConfiguration { public String password = ""; /* following parameters only available in fritzbox thing */ - public List tamIndices = Collections.emptyList(); - public List callDeflectionIndices = Collections.emptyList(); - public List missedCallDays = Collections.emptyList(); - public List rejectedCallDays = Collections.emptyList(); - public List inboundCallDays = Collections.emptyList(); - public List outboundCallDays = Collections.emptyList(); - public List callListDays = Collections.emptyList(); - public int phonebookInterval = 0; + public List tamIndices = List.of(); + public List callDeflectionIndices = List.of(); + public List missedCallDays = List.of(); + public List rejectedCallDays = List.of(); + public List inboundCallDays = List.of(); + public List outboundCallDays = List.of(); + public List callListDays = List.of(); + public List wanBlockIPs = List.of(); + public int phonebookInterval = 600; public boolean isValid() { return !host.isEmpty() && !user.isEmpty() && !password.isEmpty(); diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfileFactory.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfileFactory.java index f70b51d95f92b..b2957433ef32c 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfileFactory.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfileFactory.java @@ -15,12 +15,7 @@ import static java.util.Comparator.comparing; import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -92,19 +87,8 @@ private ProfileType createLocalizedProfileType(ProfileType profileType, @Nullabl final LocalizedKey localizedKey = new LocalizedKey(profileType.getUID(), locale != null ? locale.toLanguageTag() : null); - final ProfileType cachedlocalizedProfileType = localizedProfileTypeCache.get(localizedKey); - if (cachedlocalizedProfileType != null) { - return cachedlocalizedProfileType; - } - - final ProfileType localizedProfileType = profileTypeI18nLocalizationService.createLocalizedProfileType(bundle, - profileType, locale); - if (localizedProfileType != null) { - localizedProfileTypeCache.put(localizedKey, localizedProfileType); - return localizedProfileType; - } else { - return profileType; - } + return Objects.requireNonNull(localizedProfileTypeCache.computeIfAbsent(localizedKey, + key -> profileTypeI18nLocalizationService.createLocalizedProfileType(bundle, profileType, locale))); } /** 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 e3436141acd9d..00bd6706c5d8c 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 @@ -54,7 +54,6 @@ */ @NonNullByDefault public class SOAPValueConverter { - private static final int REQUEST_TIMEOUT = 5000; // in ms private final Logger logger = LoggerFactory.getLogger(SOAPValueConverter.class); private final HttpClient httpClient; 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 dea7e2eb676d6..40c6ed69e4d44 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 @@ -217,7 +217,9 @@ public static void checkAvailableChannels(Thing thing, ThingBuilder thingBuilder } else { // create a channel for each parameter parameters.forEach(parameter -> { - String normalizedParameter = UIDUtils.encode(parameter); + // remove comment: split parameter at '#', discard everything after that and remove + // trailing spaces + String normalizedParameter = UIDUtils.encode(parameter.split("#")[0].trim()); ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId + "_" + normalizedParameter); ChannelBuilder channelBuilder = ChannelBuilder