Skip to content

Commit

Permalink
[ihc] Fix special character issue on item descriptions (openhab#15183)
Browse files Browse the repository at this point in the history
* [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>
  • Loading branch information
paulianttila authored and markus7017 committed Jul 8, 2023
1 parent 49d57ad commit 302f227
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Channel> thingChannels) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 302f227

Please sign in to comment.