Skip to content

Commit 490a38f

Browse files
authored
Merge pull request #726 from helgeerbe/development
Prepare Release 2024.03.07
2 parents f0f8702 + c42d688 commit 490a38f

File tree

9 files changed

+316
-146
lines changed

9 files changed

+316
-146
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ jobs:
6060
- name: Get tags
6161
run: git fetch --force --tags origin
6262

63+
- name: Create and switch to a meaningful branch for pull-requests
64+
if: github.event_name == 'pull_request'
65+
run: |
66+
OWNER=${{ github.repository_owner }}
67+
NAME=${{ github.event.repository.name }}
68+
ID=${{ github.event.pull_request.number }}
69+
DATE=$(date +'%Y%m%d%H%M')
70+
git switch -c ${OWNER}/${NAME}/pr${ID}-${DATE}
71+
6372
- name: Cache pip
6473
uses: actions/cache@v4
6574
with:

include/BatteryStats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BatteryStats {
1515

1616
// the last time *any* datum was updated
1717
uint32_t getAgeSeconds() const { return (millis() - _lastUpdate) / 1000; }
18-
bool updateAvailable(uint32_t since) const { return _lastUpdate > since; }
18+
bool updateAvailable(uint32_t since) const;
1919

2020
uint8_t getSoC() const { return _soc; }
2121
uint32_t getSoCAgeSeconds() const { return (millis() - _lastUpdateSoC) / 1000; }

include/PowerLimiter.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <Hoymiles.h>
88
#include <memory>
99
#include <functional>
10+
#include <optional>
1011
#include <TaskSchedulerDeclarations.h>
1112
#include <frozen/string.h>
1213

@@ -15,10 +16,6 @@
1516
#define PL_UI_STATE_USE_SOLAR_ONLY 2
1617
#define PL_UI_STATE_USE_SOLAR_AND_BATTERY 3
1718

18-
#define PL_MODE_ENABLE_NORMAL_OP 0
19-
#define PL_MODE_FULL_DISABLE 1
20-
#define PL_MODE_SOLAR_PT_ONLY 2
21-
2219
typedef enum {
2320
EMPTY_WHEN_FULL= 0,
2421
EMPTY_AT_NIGHT
@@ -51,7 +48,7 @@ class PowerLimiterClass {
5148

5249
void init(Scheduler& scheduler);
5350
uint8_t getPowerLimiterState();
54-
int32_t getLastRequestedPowerLimit();
51+
int32_t getLastRequestedPowerLimit() { return _lastRequestedPowerLimit; }
5552

5653
enum class Mode : unsigned {
5754
Normal = 0,
@@ -69,8 +66,10 @@ class PowerLimiterClass {
6966
Task _loopTask;
7067

7168
int32_t _lastRequestedPowerLimit = 0;
72-
uint32_t _lastPowerLimitMillis = 0;
73-
uint32_t _shutdownTimeout = 0;
69+
bool _shutdownPending = false;
70+
std::optional<uint32_t> _oUpdateStartMillis = std::nullopt;
71+
std::optional<int32_t> _oTargetPowerLimitWatts = std::nullopt;
72+
std::optional<bool> _oTargetPowerState = std::nullopt;
7473
Status _lastStatus = Status::Initializing;
7574
uint32_t _lastStatusPrinted = 0;
7675
uint32_t _lastCalculation = 0;
@@ -93,7 +92,7 @@ class PowerLimiterClass {
9392
void unconditionalSolarPassthrough(std::shared_ptr<InverterAbstract> inverter);
9493
bool canUseDirectSolarPower();
9594
int32_t calcPowerLimit(std::shared_ptr<InverterAbstract> inverter, bool solarPowerEnabled, bool batteryDischargeEnabled);
96-
void commitPowerLimit(std::shared_ptr<InverterAbstract> inverter, int32_t limit, bool enablePowerProduction);
95+
bool updateInverter();
9796
bool setNewPowerLimit(std::shared_ptr<InverterAbstract> inverter, int32_t newPowerLimit);
9897
int32_t getSolarChargePower();
9998
float getLoadCorrectedVoltage();

include/WebApi_ws_live.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class WebApiWsLiveClass {
1717
static void generateInverterChannelJsonResponse(JsonObject& root, std::shared_ptr<InverterAbstract> inv);
1818
static void generateCommonJsonResponse(JsonVariant& root);
1919

20+
void generateOnBatteryJsonResponse(JsonVariant& root, bool all);
21+
void sendOnBatteryStats();
22+
2023
static void addField(JsonObject& root, std::shared_ptr<InverterAbstract> inv, const ChannelType_t type, const ChannelNum_t channel, const FieldId_t fieldId, String topic = "");
2124
static void addTotalField(JsonObject& root, const String& name, const float value, const String& unit, const uint8_t digits);
2225

@@ -25,6 +28,12 @@ class WebApiWsLiveClass {
2528

2629
AsyncWebSocket _ws;
2730

31+
uint32_t _lastPublishOnBatteryFull = 0;
32+
uint32_t _lastPublishVictron = 0;
33+
uint32_t _lastPublishHuawei = 0;
34+
uint32_t _lastPublishBattery = 0;
35+
uint32_t _lastPublishPowerMeter = 0;
36+
2837
uint32_t _lastPublishStats[INV_MAX_COUNT] = { 0 };
2938

3039
std::mutex _mutex;

src/BatteryStats.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static void addLiveViewAlarm(JsonVariant& root, std::string const& name,
5151
root["issues"][name] = 2;
5252
}
5353

54+
bool BatteryStats::updateAvailable(uint32_t since) const
55+
{
56+
auto constexpr halfOfAllMillis = std::numeric_limits<uint32_t>::max() / 2;
57+
return (_lastUpdate - since) < halfOfAllMillis;
58+
}
59+
5460
void BatteryStats::getLiveViewData(JsonVariant& root) const
5561
{
5662
root[F("manufacturer")] = _manufacturer;

0 commit comments

Comments
 (0)