Skip to main content

State Machines

The coordination layer uses finite state machines to track and guard asset lifecycles. Each controllable asset has a state machine instance that ensures commands are only dispatched when the asset is in a valid state.

Generic State Machine

The StateMachine class is a reusable, configurable FSM:

Transition Guards

Invalid transitions raise InvalidTransition with diagnostic info:

History Tracking

Every transition is recorded:

EV Charger State Machine

OCPP-aligned lifecycle with 7 states:

Key Scenarios

AVAILABLE → PREPARING → CHARGING → FINISHING → AVAILABLEThe happy path: vehicle plugs in, charging starts, completes, vehicle unplugs.
CHARGING → SUSPENDED → CHARGINGCharging paused (e.g., grid signal, user request) then resumed.
CHARGING → AVAILABLE (via unplug)Vehicle unplugs before charging completes. The dispatch engine should detect this and mark remaining commands as cancelled.
Any State → FAULTED → AVAILABLE (via reset)Hardware fault detected. After reset, charger returns to available.

Battery State Machine

5-state battery management with direct mode switching:

Direct Mode Switching

The battery state machine supports direct transitions between charging and discharging without requiring a stop in between. This enables the dispatch engine to switch modes immediately when the optimization schedule transitions from charge to discharge.

Event Bus Integration

All state machines can publish STATE_CHANGED events: