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

Align watt-second/kilowatt-hour calculations with watts #20

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 8 additions & 26 deletions greeneye/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ def __init__(
self._monitor = monitor
self.number: int = number
self.net_metering: Optional[bool] = net_metering
self.total_absolute_watt_seconds: Optional[int] = None
self.total_polarized_watt_seconds: Optional[int] = None
self.absolute_watt_seconds: Optional[int] = None
self.polarized_watt_seconds: Optional[int] = None
self.amps: Optional[float] = None
Expand All @@ -177,38 +175,22 @@ def __init__(

@property
def watt_seconds(self) -> Optional[float]:
if self.net_metering is None:
return None
elif not self.net_metering:
return self.absolute_watt_seconds
else:
return self.net_watt_seconds

@property
def kilowatt_hours(self) -> Optional[float]:
if self.net_metering is None:
return None
elif not self.net_metering:
return self.absolute_kilowatt_hours
else:
return self.net_kilowatt_hours

@property
def net_watt_seconds(self) -> Optional[float]:
if self.absolute_watt_seconds is None or self.polarized_watt_seconds is None:
if self.absolute_watt_seconds is None:
return None

consumed = self.absolute_watt_seconds - self.polarized_watt_seconds
produced = self.polarized_watt_seconds
# Polarized can be None if net metering is off for a channel
polarized_watt_seconds = self.polarized_watt_seconds or 0
consumed = self.absolute_watt_seconds - polarized_watt_seconds
produced = polarized_watt_seconds

return consumed - produced

@property
def net_kilowatt_hours(self) -> Optional[float]:
if self.net_watt_seconds is None:
def kilowatt_hours(self) -> Optional[float]:
if self.watt_seconds is None:
return None

return self.net_watt_seconds / WATTS_PER_KILOWATT / SECONDS_PER_HOUR
return self.watt_seconds / WATTS_PER_KILOWATT / SECONDS_PER_HOUR

@property
def absolute_kilowatt_hours(self) -> Optional[float]:
Expand Down