use of io.openems.common.types.ThingStateInfo in project openems by OpenEMS.
the class FaultsAndWarningsTranspiler method getJson.
private static JsonObject getJson() throws ReflectionException, OpenemsException {
JsonObject j = new JsonObject();
for (Class<ThingStateEnum> clazz : getEnums()) {
ThingStateInfo annotation = clazz.getAnnotation(ThingStateInfo.class);
if (annotation == null) {
System.err.println("@ThingStateInfo is missing for Enum [" + clazz.getName() + "]");
continue;
}
// Find existing Thing definition or create new one
for (Class<?> thingClazz : annotation.reference()) {
String thingClassName = thingClazz.getName();
JsonObject jThing = JsonUtils.getAsOptionalJsonObject(j, thingClassName).orElse(new JsonObject());
// Parse enum constants
ThingStateEnum[] enoms = clazz.getEnumConstants();
JsonObject jState = new JsonObject();
for (ThingStateEnum enom : enoms) {
String name = splitCamelCase(enom.toString());
jState.addProperty(String.valueOf(enom.getValue()), name);
}
// Is it Fault or Warning?
if (FaultEnum.class.isAssignableFrom(clazz)) {
jThing.add("faults", jState);
} else if (WarningEnum.class.isAssignableFrom(clazz)) {
jThing.add("warnings", jState);
} else {
throw new OpenemsException("Neither Fault nor Warning in Enum [" + clazz.getName() + "]");
}
j.add(thingClassName, jThing);
}
}
return j;
}
Aggregations