Skip to content

Commit

Permalink
Fix Energytotals cannot be set to negative values
Browse files Browse the repository at this point in the history
Fix Energytotals cannot be set to negative values (#17965)
  • Loading branch information
arendst committed Feb 17, 2023
1 parent 19b183c commit 4c59b5b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ All notable changes to this project will be documented in this file.
### Changed

### Fixed
- SEN5X floats and units (#17961)
- Energytotals cannot be set to negative values (#17965)

### Removed

Expand Down
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,5 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
### Changed

### Fixed
- SEN5X floats and units [#17961](https://github.com/arendst/Tasmota/issues/17961)
- Energytotals cannot be set to negative values [#17965](https://github.com/arendst/Tasmota/issues/17965)
16 changes: 8 additions & 8 deletions tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ void CmndEnergyTotal(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Total
RtcSettings.energy_kWhtotal_ph[phase] = values[0];
RtcSettings.energy_kWhtotal_ph[phase] = (int32_t)values[0];
Settings->energy_kWhtotal_ph[phase] = RtcSettings.energy_kWhtotal_ph[phase];
if (params > 1) {
Settings->energy_kWhtotal_time = values[1];
Expand All @@ -716,7 +716,7 @@ void CmndEnergyYesterday(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Yesterday
Settings->energy_kWhyesterday_ph[phase] = values[0] * 100;
Settings->energy_kWhyesterday_ph[phase] = (int32_t)values[0] * 100;
if (params > 1) {
Settings->energy_kWhtotal_time = values[1];
}
Expand All @@ -732,7 +732,7 @@ void CmndEnergyToday(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Today
Energy->kWhtoday_offset[phase] = values[0] * 100;
Energy->kWhtoday_offset[phase] = (int32_t)values[0] * 100;
Energy->kWhtoday[phase] = 0;
Energy->kWhtoday_delta[phase] = 0;
Energy->start_energy[phase] = 0;
Expand Down Expand Up @@ -760,7 +760,7 @@ void CmndEnergyExportActive(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Export Active
RtcSettings.energy_kWhexport_ph[phase] = values[0];
RtcSettings.energy_kWhexport_ph[phase] = (int32_t)values[0];
Settings->energy_kWhexport_ph[phase] = RtcSettings.energy_kWhexport_ph[phase];
if (params > 1) {
Settings->energy_kWhtotal_time = values[1];
Expand Down Expand Up @@ -789,9 +789,9 @@ void CmndEnergyUsage(void) {
uint32_t params = ParseParameters(2, values);
if (params > 0) {
// Reset energy_usage.usage totals
RtcSettings.energy_usage.usage1_kWhtotal = values[0];
RtcSettings.energy_usage.usage1_kWhtotal = (int32_t)values[0];
if (params > 1) {
RtcSettings.energy_usage.usage2_kWhtotal = values[1];
RtcSettings.energy_usage.usage2_kWhtotal = (int32_t)values[1];
}
Settings->energy_usage.usage1_kWhtotal = RtcSettings.energy_usage.usage1_kWhtotal;
Settings->energy_usage.usage2_kWhtotal = RtcSettings.energy_usage.usage2_kWhtotal;
Expand All @@ -804,9 +804,9 @@ void CmndEnergyExport(void) {
uint32_t params = ParseParameters(2, values);
if (params > 0) {
// Reset energy_usage.return totals
RtcSettings.energy_usage.return1_kWhtotal = values[0] * 100;
RtcSettings.energy_usage.return1_kWhtotal = (int32_t)values[0] * 100;
if (params > 1) {
RtcSettings.energy_usage.return2_kWhtotal = values[1] * 100;
RtcSettings.energy_usage.return2_kWhtotal = (int32_t)values[1] * 100;
}
Settings->energy_usage.return1_kWhtotal = RtcSettings.energy_usage.return1_kWhtotal;
Settings->energy_usage.return2_kWhtotal = RtcSettings.energy_usage.return2_kWhtotal;
Expand Down
16 changes: 8 additions & 8 deletions tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ void CmndEnergyTotal(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Total
RtcEnergySettings.energy_total_kWh[phase] = (float)values[0] / 1000;
RtcEnergySettings.energy_total_kWh[phase] = (float)(int32_t)values[0] / 1000;
Energy->Settings.energy_total_kWh[phase] = RtcEnergySettings.energy_total_kWh[phase];
if (params > 1) {
Energy->Settings.energy_kWhtotal_time = values[1];
Expand All @@ -949,7 +949,7 @@ void CmndEnergyYesterday(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Yesterday
Energy->Settings.energy_yesterday_kWh[phase] = (float)values[0] / 1000;
Energy->Settings.energy_yesterday_kWh[phase] = (float)(int32_t)values[0] / 1000;
if (params > 1) {
Energy->Settings.energy_kWhtotal_time = values[1];
}
Expand All @@ -965,7 +965,7 @@ void CmndEnergyToday(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Today
Energy->energy_today_offset_kWh[phase] = (float)values[0] / 1000;
Energy->energy_today_offset_kWh[phase] = (float)(int32_t)values[0] / 1000;
Energy->kWhtoday[phase] = 0;
Energy->kWhtoday_delta[phase] = 0;
Energy->start_energy[phase] = 0;
Expand Down Expand Up @@ -993,7 +993,7 @@ void CmndEnergyExportActive(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Export Active
RtcEnergySettings.energy_export_kWh[phase] = (float)values[0] / 1000;
RtcEnergySettings.energy_export_kWh[phase] = (float)(int32_t)values[0] / 1000;
Energy->Settings.energy_export_kWh[phase] = RtcEnergySettings.energy_export_kWh[phase];
if (params > 1) {
Energy->Settings.energy_kWhtotal_time = values[1];
Expand All @@ -1017,9 +1017,9 @@ void CmndEnergyUsage(void) {
uint32_t params = ParseParameters(2, values);
if (params > 0) {
// Reset energy_usage.usage totals
RtcEnergySettings.energy_usage.usage_total_kWh[0] = (float)values[0] / 1000;
RtcEnergySettings.energy_usage.usage_total_kWh[0] = (float)(int32_t)values[0] / 1000;
if (params > 1) {
RtcEnergySettings.energy_usage.usage_total_kWh[1] = (float)values[1] / 1000;
RtcEnergySettings.energy_usage.usage_total_kWh[1] = (float)(int32_t)values[1] / 1000;
}
Energy->Settings.energy_usage.usage_total_kWh[0] = RtcEnergySettings.energy_usage.usage_total_kWh[0];
Energy->Settings.energy_usage.usage_total_kWh[1] = RtcEnergySettings.energy_usage.usage_total_kWh[1];
Expand All @@ -1032,9 +1032,9 @@ void CmndEnergyExport(void) {
uint32_t params = ParseParameters(2, values);
if (params > 0) {
// Reset energy_usage.return totals
RtcEnergySettings.energy_usage.return_total_kWh[0] = (float)values[0] / 1000;
RtcEnergySettings.energy_usage.return_total_kWh[0] = (float)(int32_t)values[0] / 1000;
if (params > 1) {
RtcEnergySettings.energy_usage.return_total_kWh[1] = (float)values[1] / 1000;
RtcEnergySettings.energy_usage.return_total_kWh[1] = (float)(int32_t)values[1] / 1000;
}
Energy->Settings.energy_usage.return_total_kWh[0] = RtcEnergySettings.energy_usage.return_total_kWh[0];
Energy->Settings.energy_usage.return_total_kWh[1] = RtcEnergySettings.energy_usage.return_total_kWh[1];
Expand Down

0 comments on commit 4c59b5b

Please # to comment.