Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: differentiate between Finished EVSE and EV #954

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions modules/API/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ static void remove_error_from_list(std::vector<module::SessionInfo::Error>& 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<std::mutex> 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Comment on lines +172 to +173
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That probably belongs to #956

}
return "Unknown";
}
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions modules/API/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -95,7 +95,10 @@ class SessionInfo {
ChargingPausedEV,
ChargingPausedEVSE,
Charging,
Finished
AuthTimeout,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That probably belongs to #956

Finished,
FinishedEVSE,
FinishedEV
} state;

bool is_state_charging(const SessionInfo::State current_state);
Expand Down
3 changes: 3 additions & 0 deletions modules/API/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ This variable is published every second and contains a json object with informat
- ChargingPausedEV
- ChargingPausedEVSE
- Finished
- FinishedEV
- FinishedEVSE
- AuthTimeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That probably belongs to #956


### everest_api/evse_manager/var/limits
This variable is published every second and contains a json object with information
Expand Down
2 changes: 1 addition & 1 deletion modules/EvseManager/Charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading