WiredTriggerRepeater now saves as json

This commit is contained in:
Remco 2021-01-04 10:25:46 -05:00
parent 4fcf750763
commit 9b62b43907

View File

@ -41,13 +41,22 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
@Override
public String getWiredData() {
return this.repeatTime + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.repeatTime
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
if (set.getString("wired_data").length() >= 1) {
this.repeatTime = (Integer.valueOf(set.getString("wired_data")));
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.repeatTime = data.repeatTime;
} else {
if (wiredData.length() >= 1) {
this.repeatTime = (Integer.valueOf(wiredData));
}
}
if (this.repeatTime < 500) {
@ -136,4 +145,12 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
}
}
}
static class JsonData {
int repeatTime;
public JsonData(int repeatTime) {
this.repeatTime = repeatTime;
}
}
}