From 1ce6e8775f960b5a0cde3df3667adffb2fbcdc81 Mon Sep 17 00:00:00 2001 From: pali Date: Fri, 7 Jul 2023 10:32:37 +0300 Subject: [PATCH] [ihc] Fix special character issue on item descriptions (#15183) * [ihc] fix special character issue on item descriptions * [ihc] Changed thing status to UNKNOWN when initializing Signed-off-by: Pauli Anttila --- .../binding/ihc/internal/ChannelUtils.java | 21 +++++++------------ .../ihc/internal/handler/IhcHandler.java | 5 +++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/ChannelUtils.java b/bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/ChannelUtils.java index 08a081604de35..6166176728e6d 100644 --- a/bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/ChannelUtils.java +++ b/bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/ChannelUtils.java @@ -14,10 +14,13 @@ 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 @@ private static void addChannelsFromProjectFile(Thing thing, NodeList nodes, Stri } 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 thingChannels) { diff --git a/bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/handler/IhcHandler.java b/bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/handler/IhcHandler.java index 6fb5b936afbcb..db1ebe05ab68a 100644 --- a/bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/handler/IhcHandler.java +++ b/bundles/org.openhab.binding.ihc/src/main/java/org/openhab/binding/ihc/internal/handler/IhcHandler.java @@ -181,6 +181,9 @@ public void initialize() { 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 @@ private void connect() throws IhcExecption { 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();