-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from wildmountainfarms/local-actions
Local actions
- Loading branch information
Showing
51 changed files
with
759 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
client/src/main/java/me/retrodaredevil/solarthing/actions/command/EnvironmentUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package me.retrodaredevil.solarthing.actions.command; | ||
|
||
import me.retrodaredevil.solarthing.type.open.OpenSource; | ||
import me.retrodaredevil.action.node.environment.InjectEnvironment; | ||
import me.retrodaredevil.solarthing.reason.ExecutionReason; | ||
|
||
public interface EnvironmentUpdater { | ||
void updateInjectEnvironment(OpenSource source, InjectEnvironment.Builder injectEnvironmentBuilder); | ||
void updateInjectEnvironment(ExecutionReason executionReason, InjectEnvironment.Builder injectEnvironmentBuilder); | ||
|
||
EnvironmentUpdater DO_NOTHING = (dataSource, injectEnvironmentBuilder) -> {}; | ||
EnvironmentUpdater DO_NOTHING = (_executionReason, _injectEnvironmentBuilder) -> {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...in/java/me/retrodaredevil/solarthing/actions/environment/MultiRoverModbusEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package me.retrodaredevil.solarthing.actions.environment; | ||
|
||
import me.retrodaredevil.solarthing.annotations.Nullable; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class MultiRoverModbusEnvironment { | ||
private final Map<Integer, RoverModbusEnvironment> map; | ||
|
||
public MultiRoverModbusEnvironment(Map<Integer, RoverModbusEnvironment> map) { | ||
this.map = Collections.unmodifiableMap(new HashMap<>(map)); | ||
} | ||
public MultiRoverModbusEnvironment() { | ||
this.map = Collections.emptyMap(); | ||
} | ||
|
||
public @Nullable RoverModbusEnvironment getOrNull(int number) { | ||
return map.get(number); | ||
} | ||
|
||
public MultiRoverModbusEnvironment plus(MultiRoverModbusEnvironment environment) { | ||
Map<Integer, RoverModbusEnvironment> newMap = new HashMap<>(map); | ||
newMap.putAll(environment.map); | ||
return new MultiRoverModbusEnvironment(newMap); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...n/java/me/retrodaredevil/solarthing/actions/environment/MultiTracerModbusEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package me.retrodaredevil.solarthing.actions.environment; | ||
|
||
|
||
import me.retrodaredevil.solarthing.annotations.Nullable; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class MultiTracerModbusEnvironment { | ||
private final Map<Integer, TracerModbusEnvironment> map; | ||
|
||
public MultiTracerModbusEnvironment(Map<Integer, TracerModbusEnvironment> map) { | ||
this.map = Collections.unmodifiableMap(new HashMap<>(map)); | ||
} | ||
public MultiTracerModbusEnvironment() { | ||
this.map = Collections.emptyMap(); | ||
} | ||
|
||
public @Nullable TracerModbusEnvironment getOrNull(int number) { | ||
return map.get(number); | ||
} | ||
|
||
public MultiTracerModbusEnvironment plus(MultiTracerModbusEnvironment environment) { | ||
Map<Integer, TracerModbusEnvironment> newMap = new HashMap<>(map); | ||
newMap.putAll(environment.map); | ||
return new MultiTracerModbusEnvironment(newMap); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...src/main/java/me/retrodaredevil/solarthing/actions/environment/RoverErrorEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package me.retrodaredevil.solarthing.actions.environment; | ||
|
||
import me.retrodaredevil.solarthing.actions.error.ActionErrorState; | ||
|
||
public class RoverErrorEnvironment { | ||
private final ActionErrorState actionErrorState; | ||
|
||
public RoverErrorEnvironment(ActionErrorState actionErrorState) { | ||
this.actionErrorState = actionErrorState; | ||
} | ||
public RoverErrorEnvironment() { | ||
this(new ActionErrorState()); | ||
} | ||
|
||
public ActionErrorState getRoverActionErrorState() { | ||
return actionErrorState; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rc/main/java/me/retrodaredevil/solarthing/actions/environment/TracerErrorEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package me.retrodaredevil.solarthing.actions.environment; | ||
|
||
import me.retrodaredevil.solarthing.actions.error.ActionErrorState; | ||
|
||
public class TracerErrorEnvironment { | ||
private final ActionErrorState actionErrorState; | ||
|
||
public TracerErrorEnvironment(ActionErrorState actionErrorState) { | ||
this.actionErrorState = actionErrorState; | ||
} | ||
public TracerErrorEnvironment() { | ||
this(new ActionErrorState()); | ||
} | ||
|
||
public ActionErrorState getTracerActionErrorState() { | ||
return actionErrorState; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
client/src/main/java/me/retrodaredevil/solarthing/actions/error/ActionErrorState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package me.retrodaredevil.solarthing.actions.error; | ||
|
||
public final class ActionErrorState { | ||
|
||
private int errorCount = 0; | ||
private int successCount = 0; | ||
|
||
public int getErrorCount() { | ||
return errorCount; | ||
} | ||
public void incrementErrorCount() { | ||
errorCount++; | ||
} | ||
|
||
public int getSuccessCount() { | ||
return successCount; | ||
} | ||
public void incrementSuccessCount() { | ||
successCount++; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
client/src/main/java/me/retrodaredevil/solarthing/actions/error/TryErrorStateAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package me.retrodaredevil.solarthing.actions.error; | ||
|
||
import me.retrodaredevil.action.Action; | ||
import me.retrodaredevil.action.LinkedAction; | ||
import me.retrodaredevil.action.SimpleAction; | ||
|
||
import java.util.List; | ||
|
||
public class TryErrorStateAction extends SimpleAction implements LinkedAction { | ||
|
||
private final List<Action> actions; | ||
private final Action successAction; | ||
private final Action errorAction; | ||
private final ActionErrorState actionErrorState; | ||
private int index = 0; | ||
private Action nextAction; | ||
|
||
public TryErrorStateAction(List<Action> actions, Action successAction, Action errorAction, ActionErrorState actionErrorState) { | ||
super(false); | ||
this.actions = actions; | ||
this.successAction = successAction; | ||
this.errorAction = errorAction; | ||
this.actionErrorState = actionErrorState; | ||
} | ||
|
||
@Override | ||
protected void onUpdate() { | ||
super.onUpdate(); | ||
|
||
while (true) { | ||
if (index >= actions.size()) { // finished all actions successfully | ||
nextAction = successAction; | ||
setDone(true); | ||
return; | ||
} | ||
Action activeAction = actions.get(index); | ||
activeAction.update(); | ||
if (activeAction.isDone()) { | ||
activeAction.end(); | ||
index++; | ||
if (actionErrorState.getErrorCount() > 0) { // an error occurred from something and the action that caused it has just finished | ||
nextAction = errorAction; | ||
setDone(true); | ||
return; | ||
} | ||
} else { | ||
break; // continue next iteration. This action is not done | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Action getNextAction() { | ||
return nextAction; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.