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
TheStateMachine class is a reusable, configurable FSM:
Transition Guards
Invalid transitions raiseInvalidTransition with diagnostic info:
History Tracking
Every transition is recorded:EV Charger State Machine
OCPP-aligned lifecycle with 7 states:Key Scenarios
Normal Charging Session
Normal Charging Session
AVAILABLE → PREPARING → CHARGING → FINISHING → AVAILABLEThe happy path: vehicle plugs in, charging starts, completes, vehicle unplugs.Suspended Charging
Suspended Charging
CHARGING → SUSPENDED → CHARGINGCharging paused (e.g., grid signal, user request) then resumed.Early Departure
Early Departure
CHARGING → AVAILABLE (via unplug)Vehicle unplugs before charging completes. The dispatch engine should detect this and mark remaining commands as cancelled.Fault Recovery
Fault Recovery
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 publishSTATE_CHANGED events: