]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tr064] fix wanBlockByIP channel and improvements to parameter handling (#9655)
authorJ-N-K <J-N-K@users.noreply.github.com>
Sun, 3 Jan 2021 01:52:15 +0000 (02:52 +0100)
committerGitHub <noreply@github.com>
Sun, 3 Jan 2021 01:52:15 +0000 (17:52 -0800)
- fix wanBlockByIP channel
- allow comments in parameter lists
- fix compiler warnings

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
bundles/org.openhab.binding.tr064/README.md
bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/config/Tr064RootConfiguration.java
bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfileFactory.java
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

index 2b201805653f759bec5cad451914df55bb7e3b0b..099de551b14608d3d40f0203ee1f24119ad8796f 100644 (file)
@@ -151,6 +151,10 @@ Advanced channels appear only if the corresponding parameters are set in the Thi
 | `wanTotalBytesSent`        | `Number:DataAmount`       |     x    | Total Bytes Sent                                               |
 
 
+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.
index 9b130cbfbe7e4105f638cafd9c2aa161fbd1a212..6d287419736586a13ee2f0f32b0ab884ae021813 100644 (file)
@@ -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<String> tamIndices = Collections.emptyList();
-    public List<String> callDeflectionIndices = Collections.emptyList();
-    public List<String> missedCallDays = Collections.emptyList();
-    public List<String> rejectedCallDays = Collections.emptyList();
-    public List<String> inboundCallDays = Collections.emptyList();
-    public List<String> outboundCallDays = Collections.emptyList();
-    public List<String> callListDays = Collections.emptyList();
-    public int phonebookInterval = 0;
+    public List<String> tamIndices = List.of();
+    public List<String> callDeflectionIndices = List.of();
+    public List<String> missedCallDays = List.of();
+    public List<String> rejectedCallDays = List.of();
+    public List<String> inboundCallDays = List.of();
+    public List<String> outboundCallDays = List.of();
+    public List<String> callListDays = List.of();
+    public List<String> wanBlockIPs = List.of();
+    public int phonebookInterval = 600;
 
     public boolean isValid() {
         return !host.isEmpty() && !user.isEmpty() && !password.isEmpty();
index cf0e3646b0c0ef42c2558501025266076cc4556b..f10359f76ab1daecf75174d5f2549db7221895c4 100644 (file)
@@ -15,12 +15,7 @@ package org.openhab.binding.tr064.internal.phonebook;
 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 @@ public class PhonebookProfileFactory implements ProfileFactory, ProfileTypeProvi
         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)));
     }
 
     /**
index d6eaf0e60309136b97138a99e8436d81768c3477..9a7d645be168b31365e88e4f72d1198b1219f439 100644 (file)
@@ -54,7 +54,6 @@ import com.google.gson.GsonBuilder;
  */
 @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;
 
index 13d010f0bb9c168075cf8a19e06fb38bf8b11585..d5884b91a08cd51ca628dc27ca6e716858e759d6 100644 (file)
@@ -217,7 +217,9 @@ public class Util {
                         } 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