Added logging data on menu and distance
Added helper functionality to abort movements in state class and safeguards to NOT be able to abort in protected states. some caps removal
This commit is contained in:
@@ -52,6 +52,7 @@ class state{
|
||||
return this.stateManager.getRunTimeHours();
|
||||
}
|
||||
|
||||
|
||||
async moveTo(targetPosition) {
|
||||
|
||||
// Check for invalid conditions and throw errors
|
||||
@@ -86,14 +87,33 @@ class state{
|
||||
|
||||
// -------- State Transition Methods -------- //
|
||||
|
||||
abortCurrentMovement(reason = "group override") {
|
||||
if (this.abortController && !this.abortController.signal.aborted) {
|
||||
this.logger.warn(`Aborting movement: ${reason}`);
|
||||
this.abortController.abort();
|
||||
}
|
||||
}
|
||||
|
||||
async transitionToState(targetState, signal) {
|
||||
|
||||
const fromState = this.getCurrentState();
|
||||
const position = this.getCurrentPosition();
|
||||
|
||||
// Define states that cannot be aborted for safety reasons
|
||||
const protectedStates = ['warmingup', 'coolingdown'];
|
||||
const isProtectedTransition = protectedStates.includes(fromState);
|
||||
|
||||
try {
|
||||
|
||||
this.logger.debug(`Starting transition from ${fromState} to ${targetState}.`);
|
||||
if( isProtectedTransition){
|
||||
//overrule signal to prevent abortion
|
||||
signal = null; // Disable abortion for protected states
|
||||
//spit warning
|
||||
this.logger.warn(`Transition from ${fromState} to ${targetState} is protected and cannot be aborted.`);
|
||||
}
|
||||
|
||||
// Await the state transition and pass signal for abortion
|
||||
const feedback = await this.stateManager.transitionTo(targetState,signal);
|
||||
this.logger.info(`Statemanager: ${feedback}`);
|
||||
|
||||
@@ -108,7 +128,6 @@ class state{
|
||||
//trigger move
|
||||
await this.moveTo(this.delayedMove,signal);
|
||||
this.delayedMove = null;
|
||||
|
||||
this.logger.info(`moveTo : ${feedback} `);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"general": {
|
||||
"name": {
|
||||
"default": "State Configuration",
|
||||
"default": "state configuration",
|
||||
"rules": {
|
||||
"type": "string",
|
||||
"description": "A human-readable name for the state configuration."
|
||||
@@ -65,7 +65,7 @@
|
||||
}
|
||||
},
|
||||
"role": {
|
||||
"default": "StateController",
|
||||
"default": "statecontroller",
|
||||
"rules": {
|
||||
"type": "string",
|
||||
"description": "Functional role within the system."
|
||||
|
||||
Reference in New Issue
Block a user