Skip to content

Commit

Permalink
Merge pull request #8 from kippAndMost/feature/skip-standard-properties
Browse files Browse the repository at this point in the history
Skip standard properties from org.eclipse.smarthome.core.thing.Thing
  • Loading branch information
fabian-schlegel authored Dec 20, 2021
2 parents f6d4624 + c6dfe38 commit 2e39d57
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@
@Mojo(name = "generate-esh-constants", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
public class GenerateConstantsMojo extends AbstractMojo {

/**
* property names which are already defined in org.eclipse.smarthome.core.thing.Thing
*/
private static final Set<String> STANDARD_PROPERTIES = Set.of(
/* the key for the vendor property */
"vendor",
/* the key for the model ID property */
"modelId",
/* the key for the serial number property */
"serialNumber",
/* the key for the hardware version property */
"hardwareVersion",
/* the key for the firmware version property */
"firmwareVersion",
/* the key for the MAC address property */
"macAddress"
);

@Parameter(property = "esh-constants.inputDirectory",
defaultValue = "${project.basedir}/src/main/resources/ESH-INF")
private String inputDirectory;
Expand All @@ -66,7 +84,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
final Map<String, String> constants = new LinkedHashMap<>();

Set<String> bindingIDs = scanDocuments(inputFiles, "//thing-descriptions/@bindingId");
Set<String> properties = scanDocuments(inputFiles, "//property/@name");
Set<String> properties = exclude(STANDARD_PROPERTIES, scanDocuments(inputFiles, "//property/@name"));
Set<String> thingTypeIDs = scanDocuments(inputFiles, "//thing-type/@id");
Set<String> bridgeTypeIDs = scanDocuments(inputFiles, "//bridge-type/@id");
Set<String> channelIDs = scanDocuments(inputFiles, "//channel/@id");
Expand Down Expand Up @@ -267,4 +285,15 @@ private void writeFile(Path path, String content) throws MojoExecutionException
throw new MojoExecutionException("Unable to write file: " + path, e);
}
}

/**
* @param exclude the set of values to exclude
* @param candidates the origin value set
* @return a copy of candidates with all values from exclude removed
*/
private static Set<String> exclude(Set<String> exclude, Set<String> candidates) {
return candidates.stream()
.filter(candidate -> !exclude.contains(candidate))
.collect(Collectors.toSet());
}
}
11 changes: 11 additions & 0 deletions src/test/resources/ESH-INF/thing/thing-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
<unitLabel>minutes</unitLabel>
</parameter>
</config-description>

<!-- standard properties from org.eclipse.smarthome.core.thing.Thing, should be skipped -->
<properties>
<property name="vendor">N/A</property>
<property name="modelId">N/A</property>
<property name="serialNumber">N/A</property>
<property name="hardwareVersion">N/A</property>
<property name="firmwareVersion">N/A</property>
<property name="macAddress">N/A</property>
</properties>

</thing-type>

<!-- thing definition for encrypted, but still standard meter -->
Expand Down
2 changes: 0 additions & 2 deletions src/test/resources/expected.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ private Constants() {
public static final String BINDING_ID = "wmbus";

// Constants
public static final String PROPERTY_VENDOR = "vendor";
public static final String PROPERTY_MODELID = "modelId";
public static final String PROPERTY_SERIAL = "serial";
public static final String THING_TYPE_ID_ITRON_SMOKE_DETECTOR = "itron_smoke_detector";
public static final String THING_TYPE_ID_TECHEM_HKV45 = "techem_hkv45";
Expand Down

0 comments on commit 2e39d57

Please sign in to comment.