]> git.basschouten.com Git - openhab-addons.git/commitdiff
[ihc] Fix special character issue on item descriptions (#15183)
authorpali <pauli.anttila@gmail.com>
Fri, 7 Jul 2023 07:32:37 +0000 (10:32 +0300)
committerGitHub <noreply@github.com>
Fri, 7 Jul 2023 07:32:37 +0000 (09:32 +0200)
* [ihc] fix special character issue on item descriptions
* [ihc] Changed thing status to UNKNOWN when initializing

Signed-off-by: Pauli Anttila <pauli.anttila@gmail.com>
bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/ChannelUtils.java
bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/handler/IhcHandler.java

index 08a081604de35f5a7d96dfb5b0406f5973bdc6ab..6166176728e6d4e0ffaed620d1841371cd9e03b5 100644 (file)
@@ -14,10 +14,13 @@ package org.openhab.binding.ihc.internal;
 
 import static org.openhab.binding.ihc.internal.IhcBindingConstants.*;
 
+import java.nio.charset.StandardCharsets;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.openhab.binding.ihc.internal.config.ChannelParams;
 import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
@@ -212,20 +215,10 @@ public class ChannelUtils {
     }
 
     private static String createDescription(String name1, String name2, String name3, String name4) {
-        String description = "";
-        if (name1 != null && !name1.isEmpty()) {
-            description = name1;
-        }
-        if (name2 != null && !name2.isEmpty()) {
-            description += String.format(" - %s", name2);
-        }
-        if (name3 != null && !name3.isEmpty()) {
-            description += String.format(" - %s", name3);
-        }
-        if (name4 != null && !name4.isEmpty()) {
-            description += String.format(" - %s", name4);
-        }
-        return description;
+        String description = Stream.of(name1, name2, name3, name4).filter(s -> s != null && !s.isEmpty())
+                .collect(Collectors.joining(" - "));
+
+        return new String(description.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
     }
 
     private static void addOrUpdateChannel(Channel newChannel, List<Channel> thingChannels) {
index 6fb5b936afbcb6f84300fe9b941ff5cebe2d6af1..db1ebe05ab68a5ed9acd8e78bad87c6335293e6d 100644 (file)
@@ -181,6 +181,9 @@ public class IhcHandler extends BaseThingHandler implements IhcEventListener {
         linkedResourceIds.addAll(getAllLinkedChannelsResourceIds());
         logger.debug("Linked resources {}: {}", linkedResourceIds.size(), linkedResourceIds);
 
+        updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE,
+                "Initializing communication to the IHC / ELKO controller");
+
         if (controlJob == null || controlJob.isCancelled()) {
             logger.debug("Start control task, interval={}sec", 1);
             controlJob = scheduler.scheduleWithFixedDelay(this::reconnectCheck, 0, 1, TimeUnit.SECONDS);
@@ -542,8 +545,6 @@ public class IhcHandler extends BaseThingHandler implements IhcEventListener {
                     conf.username);
             ihc = new IhcClient(conf.hostname, conf.username, conf.password, conf.timeout, conf.tlsVersion);
             ihc.openConnection();
-            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
-                    "Initializing communication to the IHC / ELKO controller");
             loadProject();
             createChannels();
             updateControllerProperties();