From 5ac5106c0d5fbf0d389d7a5a2af8fde603fb8f6d Mon Sep 17 00:00:00 2001 From: voruti <45130096+voruti@users.noreply.github.com> Date: Sun, 8 Aug 2021 18:59:09 +0200 Subject: [PATCH 1/3] Prepare test for profile feature --- src/test/resources/openhab2_multipleChannelsOneItem.items | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/openhab2_multipleChannelsOneItem.items b/src/test/resources/openhab2_multipleChannelsOneItem.items index b2418a9..0ada3f9 100644 --- a/src/test/resources/openhab2_multipleChannelsOneItem.items +++ b/src/test/resources/openhab2_multipleChannelsOneItem.items @@ -1 +1 @@ -Switch MultiItem {channel="mqtt:topic:52b61fd6:light", channel="mqtt:topic:d589b50d:power", channel="mqtt:topic:3621578b:switch", channel="mqtt:topic:1c4c5e84:light"} +Switch MultiItem {channel="mqtt:topic:52b61fd6:light", channel="mqtt:topic:d589b50d:power"[profile="system:follow"], channel="mqtt:topic:3621578b:switch"[sourceFormat="%.1f °C", profile="transform:REGEX", function=".*\u003d(\\\\d*.\\\\d*).*"], channel="mqtt:topic:1c4c5e84:light"} From 2f7b1a663072024acfaa95eab1c1e88196972a3f Mon Sep 17 00:00:00 2001 From: voruti <45130096+voruti@users.noreply.github.com> Date: Sun, 8 Aug 2021 21:12:01 +0200 Subject: [PATCH 2/3] Add channel link profiles Closes #5 --- .../model/json/JsonChannelLink.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/voruti/json2config/model/json/JsonChannelLink.java b/src/main/java/voruti/json2config/model/json/JsonChannelLink.java index 79c40ce..aa1e331 100644 --- a/src/main/java/voruti/json2config/model/json/JsonChannelLink.java +++ b/src/main/java/voruti/json2config/model/json/JsonChannelLink.java @@ -1,20 +1,24 @@ package voruti.json2config.model.json; +import com.google.gson.Gson; import lombok.Getter; import voruti.json2config.model.IConvertible; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; -@SuppressWarnings("unused") @Getter public class JsonChannelLink implements IConvertible { + private static final Gson GSON = new Gson(); private Value value; @Override public String toConfigLine(String lineBefore) { - String format = "channel=\"%s\"}"; + // first channel or append: + String format = "channel=\"%s\"%s}"; if (lineBefore.endsWith("}")) { lineBefore = lineBefore.substring(0, lineBefore.length() - 1); format = "%s, " + format; @@ -22,7 +26,20 @@ public String toConfigLine(String lineBefore) { format = "%s {" + format; } - return String.format(format, lineBefore, String.join(":", value.channelUID.segments)).strip(); + // profile: + String propertiesString = ""; + if (value.configuration.properties != null) { + String profile = value.configuration.properties.get("profile"); + if (profile != null && !profile.equals("system:default")) { + propertiesString = String.format("[%s]", + value.configuration.properties.entrySet().stream() + .map(propertiesEntry -> String.format("%s=%s", propertiesEntry.getKey(), GSON.toJson(propertiesEntry.getValue()))) + .collect(Collectors.joining(", ")) + ); + } + } + + return String.format(format, lineBefore, String.join(":", value.channelUID.segments), propertiesString).strip(); } @@ -38,15 +55,7 @@ private static class ChannelUID { } private static class Configuration { - private Properties properties; - - - private static class Properties { - private String offset; - private String sourceFormat; - private String profile; - private String function; - } + private Map properties; } } } From 1c1b4781e15e06f60bc6265f131b092d0e095b51 Mon Sep 17 00:00:00 2001 From: voruti <45130096+voruti@users.noreply.github.com> Date: Sun, 8 Aug 2021 21:23:19 +0200 Subject: [PATCH 3/3] Remove warning from readme --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 49e0d5a..be06b83 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,6 @@ directory. Alternatively you can adjust the program arguments to specify the fil - The `-d `/`--dir `/`--directory ` parameters allow you to specify the directory in which to search for *.items files. -:exclamation:Channel Link **Profiles** (value → configuration → properties → profile) currently will be lost in this -process:exclamation: (They can - of course - manually be added afterwards) - #### Other program features When enabling both features, the converting feature will run first, so the appending feature can then use the generated