diff --git a/modules/API/API.cpp b/modules/API/API.cpp index fd56c74b6..054229a0c 100644 --- a/modules/API/API.cpp +++ b/modules/API/API.cpp @@ -76,13 +76,13 @@ static void remove_error_from_list(std::vector& list list.end()); } -void SessionInfo::update_state(const types::evse_manager::SessionEventEnum event) { +void SessionInfo::update_state(const types::evse_manager::SessionEvent event) { std::lock_guard lock(this->session_info_mutex); using Event = types::evse_manager::SessionEventEnum; // using switch since some code analysis tools can detect missing cases // (when new events are added) - switch (event) { + switch (event.event) { case Event::Enabled: this->state = State::Unplugged; break; @@ -111,11 +111,22 @@ void SessionInfo::update_state(const types::evse_manager::SessionEventEnum event this->state = State::WaitingForEnergy; break; case Event::ChargingFinished: - case Event::PluginTimeout: - case Event::StoppingCharging: - case Event::TransactionFinished: this->state = State::Finished; break; + case Event::StoppingCharging: + this->state = State::FinishedEV; + break; + case Event::TransactionFinished: { + if (event.transaction_finished->reason == types::evse_manager::StopTransactionReason::Local) { + this->state = State::FinishedEVSE; + } else { + this->state = State::Finished; + } + break; + } + case Event::PluginTimeout: + this->state = State::AuthTimeout; + break; case Event::ReservationStart: this->state = State::Reserved; break; @@ -154,6 +165,12 @@ std::string SessionInfo::state_to_string(SessionInfo::State s) { return "Charging"; case SessionInfo::State::Finished: return "Finished"; + case SessionInfo::State::FinishedEVSE: + return "FinishedEVSE"; + case SessionInfo::State::FinishedEV: + return "FinishedEV"; + case SessionInfo::State::AuthTimeout: + return "AuthTimeout"; } return "Unknown"; } @@ -364,7 +381,7 @@ void API::init() { evse->subscribe_session_event( [this, var_session_info, var_logging_path, &session_info](types::evse_manager::SessionEvent session_event) { - session_info->update_state(session_event.event); + session_info->update_state(session_event); if (session_event.source.has_value()) { const auto source = session_event.source.value(); diff --git a/modules/API/API.hpp b/modules/API/API.hpp index d4ea8880d..c83004ef8 100644 --- a/modules/API/API.hpp +++ b/modules/API/API.hpp @@ -54,7 +54,7 @@ class SessionInfo { false}; ///< Indicate if end export energy value (optional) has been received or not void reset(); - void update_state(const types::evse_manager::SessionEventEnum event); + void update_state(const types::evse_manager::SessionEvent event); void set_start_energy_import_wh(int32_t start_energy_import_wh); void set_end_energy_import_wh(int32_t end_energy_import_wh); void set_latest_energy_import_wh(int32_t latest_energy_wh); @@ -95,7 +95,10 @@ class SessionInfo { ChargingPausedEV, ChargingPausedEVSE, Charging, - Finished + AuthTimeout, + Finished, + FinishedEVSE, + FinishedEV } state; bool is_state_charging(const SessionInfo::State current_state); diff --git a/modules/API/README.md b/modules/API/README.md index afb4c211b..b40a37d05 100644 --- a/modules/API/README.md +++ b/modules/API/README.md @@ -77,6 +77,9 @@ This variable is published every second and contains a json object with informat - ChargingPausedEV - ChargingPausedEVSE - Finished + - FinishedEV + - FinishedEVSE + - AuthTimeout ### everest_api/evse_manager/var/limits This variable is published every second and contains a json object with information diff --git a/modules/EvseManager/Charger.cpp b/modules/EvseManager/Charger.cpp index b17c44717..cd7ce327c 100644 --- a/modules/EvseManager/Charger.cpp +++ b/modules/EvseManager/Charger.cpp @@ -735,7 +735,7 @@ void Charger::run_state_machine() { case EvseState::StoppingCharging: if (initialize_state) { bcb_toggle_reset(); - if (shared_context.transaction_active or shared_context.session_active) { + if (shared_context.transaction_active) { signal_simple_event(types::evse_manager::SessionEventEnum::StoppingCharging); }