Skip to content

Commit

Permalink
Merge pull request #12 from voruti/issue-7-compatibility-with-openhab-3x
Browse files Browse the repository at this point in the history
Add v3 argument
  • Loading branch information
voruti committed Aug 11, 2021
2 parents 9e09814 + 309a183 commit a585d79
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ directory. Alternatively you can adjust the program arguments to specify the fil

When enabling both features, the converting feature will run first, so the appending feature can then use the generated
.items file to append the channel links.

With the `-3`/`--v3`/`--openhab3` parameters default values used since openHAB version 3.X are set. Additional
parameters that specify a custom file always have priority over these defaults.
19 changes: 17 additions & 2 deletions src/main/java/voruti/json2config/Starter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import voruti.json2config.service.ChannelAppender;
import voruti.json2config.service.Constants;
import voruti.json2config.service.Converter;
import voruti.json2config.service.Type;

Expand All @@ -22,14 +23,18 @@ public class Starter implements Runnable {
description = "enable the appending feature")
private boolean doChannelLinks;

@Option(names = {"-3", "--openhab3", "--v3", "--openhab-v3", "--openhabv3", "--openhab-3"},
description = "set default file names used since openHAB version 3.X")
private boolean defaultV3;


@Option(names = {"-i", "--in", "--json"},
defaultValue = "org.eclipse.smarthome.core.items.Item.json",
defaultValue = Constants.DEFAULT_V2_JSON_FILE,
description = "specify the input .json file")
private String jsonFile;

@Option(names = {"--channel-file", "--channel-link-file"},
defaultValue = "org.eclipse.smarthome.core.thing.link.ItemChannelLink.json",
defaultValue = Constants.DEFAULT_V2_CHANNEL_FILE,
description = "specify the .json file location containing the channel links")
private String channelFile;

Expand All @@ -54,6 +59,16 @@ public static void main(String[] args) {
*/
@Override
public void run() {
// openHAB 3.X defaults:
if (defaultV3) {
if (jsonFile.equals(Constants.DEFAULT_V2_JSON_FILE)) {
jsonFile = Constants.DEFAULT_V3_JSON_FILE;
}
if (channelFile.equals(Constants.DEFAULT_V2_CHANNEL_FILE)) {
channelFile = Constants.DEFAULT_V3_CHANNEL_FILE;
}
}

// start Converter:
if (!noConverter) {
Converter.start(jsonFile, outFile, Type.ITEM);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/voruti/json2config/service/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

public final class Constants {

// logging constants:
public static final String LOG_CANT_OPEN_FILE = "Can't open file {}";

// default voruti.json2config.Starter argument values:
public static final String DEFAULT_V2_JSON_FILE = "org.eclipse.smarthome.core.items.Item.json";
public static final String DEFAULT_V3_JSON_FILE = "org.openhab.core.items.Item.json";
public static final String DEFAULT_V2_CHANNEL_FILE = "org.eclipse.smarthome.core.thing.link.ItemChannelLink.json";
public static final String DEFAULT_V3_CHANNEL_FILE = "org.openhab.core.thing.link.ItemChannelLink.json";


private Constants() {
}
Expand Down

0 comments on commit a585d79

Please sign in to comment.