-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Handle hardware reset of total energy reportings.
- Loading branch information
Showing
15 changed files
with
690 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using NMolecules.DDD; | ||
using OpenEMS.Domain.Units; | ||
|
||
namespace OpenEMS.Domain; | ||
|
||
[ValueObject] | ||
public class TotalEnergy | ||
{ | ||
private TotalEnergy() { } | ||
|
||
public static TotalEnergy Zero => new(); | ||
|
||
/// <summary> | ||
/// Gets the last reported value. | ||
/// This value may be reset to zero if the hardware has been reset. | ||
/// </summary> | ||
public WattHours LastReported { get; private set; } = WattHours.Zero; | ||
|
||
/// <summary> | ||
/// Gets the actual total energy. | ||
/// This value is not affected by hardware resets. | ||
/// </summary> | ||
public WattHours Value { get; private set; } = WattHours.Zero; | ||
|
||
public TotalEnergy WithReported(WattHours reportedValue) | ||
{ | ||
if (reportedValue < LastReported) | ||
{ | ||
// Hardware has been reset | ||
return new TotalEnergy { LastReported = reportedValue, Value = Value + reportedValue }; | ||
} | ||
|
||
return new TotalEnergy | ||
{ | ||
LastReported = reportedValue, | ||
Value = Value + (reportedValue - LastReported), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.