From e84a79f4ade791ec731043e4292449dd29e5af5f Mon Sep 17 00:00:00 2001 From: Joshua Shannon Date: Fri, 25 Nov 2022 01:21:59 -0600 Subject: [PATCH] Fixed bug in local actions that caused environment to contain old packet collection --- .../solarthing/program/PacketHandlerInit.java | 8 +++++++- .../actions/alert_generator_off_while_aux_on.json | 2 +- config_templates/actions/low_battery_alert.json | 3 ++- other/docs/todo.md | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/src/main/java/me/retrodaredevil/solarthing/program/PacketHandlerInit.java b/client/src/main/java/me/retrodaredevil/solarthing/program/PacketHandlerInit.java index 3eef3db8..997c328d 100644 --- a/client/src/main/java/me/retrodaredevil/solarthing/program/PacketHandlerInit.java +++ b/client/src/main/java/me/retrodaredevil/solarthing/program/PacketHandlerInit.java @@ -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; @@ -231,7 +232,12 @@ private static 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() @@ -239,7 +245,7 @@ private static PacketHandler cr .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(); diff --git a/config_templates/actions/alert_generator_off_while_aux_on.json b/config_templates/actions/alert_generator_off_while_aux_on.json index a358577e..6feb0828 100644 --- a/config_templates/actions/alert_generator_off_while_aux_on.json +++ b/config_templates/actions/alert_generator_off_while_aux_on.json @@ -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"}] ] } }, diff --git a/config_templates/actions/low_battery_alert.json b/config_templates/actions/low_battery_alert.json index b47736c1..86241f63 100644 --- a/config_templates/actions/low_battery_alert.json +++ b/config_templates/actions/low_battery_alert.json @@ -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", diff --git a/other/docs/todo.md b/other/docs/todo.md index bb0c40e6..2c7f1add 100644 --- a/other/docs/todo.md +++ b/other/docs/todo.md @@ -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