Skip to content

Commit

Permalink
add "limit_version" event
Browse files Browse the repository at this point in the history
  • Loading branch information
KipK committed Jan 31, 2023
1 parent 5dd90df commit 622e810
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

#include "limit.h"
#include "debug.h"
#include <Arduino.h>
#include <ArduinoJson.h>
#include <MicroTasks.h>
#include "evse_man.h"

#include "event.h"
// ---------------------------------------------
//
// LimitType Class
Expand Down Expand Up @@ -71,8 +67,6 @@ LimitProperties::LimitProperties()

LimitProperties::~LimitProperties()
{
DBUGLN("LimitProperties Destructor");

};

void LimitProperties::init()
Expand Down Expand Up @@ -140,7 +134,11 @@ bool LimitProperties::serialize(JsonObject &obj)
Limit limit;

Limit::Limit() : Limit::Task() {
_version = 0;
_limit_properties.init();
StaticJsonDocument<32> doc;
doc["limit_version"] = ++_version;
event_send(doc);
};

Limit::~Limit() {
Expand Down Expand Up @@ -277,6 +275,9 @@ bool Limit::set(String json) {

bool Limit::set(LimitProperties props) {
_limit_properties = props;
StaticJsonDocument<32> doc;
doc["limit_version"] = ++_version;
event_send(doc);
return true;
};

Expand All @@ -285,6 +286,10 @@ bool Limit::clear() {
return true;
};

uint8_t Limit::getVersion() {
return _version;
}

LimitProperties Limit::getLimitProperties() {
return _limit_properties;
};
2 changes: 2 additions & 0 deletions src/limit.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Limit: public MicroTasks::Task
private:
EvseManager *_evse;
LimitProperties _limit_properties;
uint8_t _version;
bool _has_vehicle;
bool limitTime(uint32_t val);
bool limitEnergy(uint32_t val);
Expand All @@ -81,6 +82,7 @@ class Limit: public MicroTasks::Task
bool set(LimitProperties props);
bool clear();
LimitProperties getLimitProperties();
uint8_t getVersion();
};

extern Limit limit;
Expand Down
1 change: 1 addition & 0 deletions src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ void buildStatus(DynamicJsonDocument &doc) {
doc["override_version"] = manual.getVersion();
doc["schedule_version"] = scheduler.getVersion();
doc["schedule_plan_version"] = scheduler.getPlanVersion();
doc["limit_version"] = limit.getVersion();

doc["vehicle_state_update"] = (millis() - evse.getVehicleLastUpdated()) / 1000;
if(teslaClient.getVehicleCnt() > 0) {
Expand Down

0 comments on commit 622e810

Please sign in to comment.