Skip to content

Commit

Permalink
Fixed bug in local actions that caused environment to contain old pac…
Browse files Browse the repository at this point in the history
…ket collection
  • Loading branch information
retrodaredevil committed Nov 25, 2022
1 parent 1b4eb7e commit e84a79f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import me.retrodaredevil.solarthing.influxdb.retention.ConstantRetentionPolicyGetter;
import me.retrodaredevil.solarthing.influxdb.retention.FrequentRetentionPolicyGetter;
import me.retrodaredevil.solarthing.mqtt.MqttPacketSaver;
import me.retrodaredevil.solarthing.packets.collection.PacketCollection;
import me.retrodaredevil.solarthing.packets.handling.*;
import me.retrodaredevil.solarthing.packets.handling.implementations.FileWritePacketHandler;
import me.retrodaredevil.solarthing.packets.handling.implementations.JacksonStringPacketHandler;
Expand Down Expand Up @@ -231,15 +232,20 @@ private static <T extends ActionsOption & PacketHandlingOption> PacketHandler cr

ActionMultiplexer multiplexer = new Actions.ActionMultiplexerBuilder().build();

PacketCollection[] packetCollectionReference = new PacketCollection[] { null };
LatestPacketGroupEnvironment latestPacketGroupEnvironment = new LatestPacketGroupEnvironment(() -> requireNonNull(packetCollectionReference[0], "Using latestPacketGroupEnvironment before initializing packet collection!"));

return packetCollection -> {
packetCollectionReference[0] = packetCollection;

EnvironmentUpdater environmentUpdater = environmentUpdaterSupplier.get();
ExecutionReason executionReason = new PacketCollectionExecutionReason(packetCollection.getDateMillis(), packetCollection.getDbId());
InjectEnvironment.Builder injectEnvironmentBuilder = new InjectEnvironment.Builder()
.add(new ExecutionReasonEnvironment(executionReason))
.add(new NanoTimeProviderEnvironment(NanoTimeProvider.SYSTEM_NANO_TIME))
.add(new SourceIdEnvironment(options.getSourceId()))
.add(new TimeZoneEnvironment(options.getZoneId()))
.add(new LatestPacketGroupEnvironment(() -> packetCollection))
.add(latestPacketGroupEnvironment)
;
environmentUpdater.updateInjectEnvironment(executionReason, injectEnvironmentBuilder);
InjectEnvironment injectEnvironment = injectEnvironmentBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"type": "race",
"racers": [
[ { "type": "call", "name": "is_aux_off_or_generator_on" }, { "type": "pass" }],
[ { "type": "wait", "duration": "PT30S" }, { "type": "call", "name": "send_alert"}]
[ { "type": "wait", "duration": "PT45S" }, { "type": "call", "name": "send_alert"}]
]
}
},
Expand Down
3 changes: 2 additions & 1 deletion config_templates/actions/low_battery_alert.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"action": {
"type": "call",
"name": "run_check"
}
},
"ontimeout": { "type": "log", "message": "low_battery_alert locked (timer is counting down)", "debug": true }
},
"run_check": {
"type": "race",
Expand Down
1 change: 1 addition & 0 deletions other/docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ and also react to messages that have been fully processed (request successfully
may not be supported with the configuration or type of program being ran.
* Status page on SolarThing web to show which components of SolarThing are or are not working
* Ability to upload to a backup CouchDB database, but with a unique document ID as to not cause conflicts when the databases sync again
* Add page to SolarThing web to create actions


### Completed
Expand Down

0 comments on commit e84a79f

Please sign in to comment.