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

Store energy in mWs #2535

Open
mcspr opened this issue Sep 9, 2022 · 0 comments
Open

Store energy in mWs #2535

mcspr opened this issue Sep 9, 2022 · 0 comments
Labels
enhancement New feature or request sensors

Comments

@mcspr
Copy link
Collaborator

mcspr commented Sep 9, 2022

subj

Current conversion does truncation

constexpr WattSeconds(Watts watts, espurna::duration::Seconds seconds) :
value(static_cast<Type>(watts.value * seconds.count()))
{}

https://en.cppreference.com/w/cpp/language/operator_arithmetic#Conversions
https://en.cppreference.com/w/cpp/language/implicit_conversion#Floating.E2.80.93integral_conversions
For example, sensor read 0.9W over 1 second will result in 0. Longer interval will eventually allow for the value to appear, but this may also result in loss of precision when it is truncated to the integer part.

Current Energy pair is kWh + Ws, which could become kWh + mWs instead

struct Energy {
struct Pair {
KilowattHours kwh;
WattSeconds ws;

This needs new type and a proper math adjustment.
Plus, everything related to serialization needs to know of these different conversion rules. Right now it only understands kWh + Ws

@mcspr mcspr added enhancement New feature or request sensors labels Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sensors
Projects
None yet
Development

No branches or pull requests

1 participant