From 8a3b86671878b826447921d3bc33a27f904cc3dc Mon Sep 17 00:00:00 2001 From: camille-bouvy-frequenz Date: Fri, 12 Jan 2024 20:57:29 +0100 Subject: [PATCH 1/2] Add unit conversion methods for Energy type Signed-off-by: camille-bouvy-frequenz --- .../client/electricity_trading/_types.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/py/frequenz/client/electricity_trading/_types.py b/py/frequenz/client/electricity_trading/_types.py index 036f6a4..7522396 100644 --- a/py/frequenz/client/electricity_trading/_types.py +++ b/py/frequenz/client/electricity_trading/_types.py @@ -144,6 +144,46 @@ def to_pb(self) -> energy_pb2.Energy: decimal_mwh.value = str(self.mwh) return energy_pb2.Energy(mwh=decimal_mwh) + def as_watt_hours(self) -> Decimal: + """Return the energy in watt hours. + + Returns: + The energy in watt hours. + """ + return self.mwh * Decimal(1e6) + + def as_kilowatt_hours(self) -> Decimal: + """Return the energy in kilowatt hours. + + Returns: + The energy in kilowatt hours. + """ + return self.mwh * Decimal(1e3) + + @classmethod + def from_watt_hours(cls, watt_hours: Decimal) -> Self: + """Initialize a new energy quantity from watt hours. + + Args: + watt_hours: The energy in watt hours. + + Returns: + A new energy quantity. + """ + return cls(mwh=watt_hours / Decimal(1e6)) + + @classmethod + def from_kilowatt_hours(cls, kilowatt_hours: Decimal) -> Self: + """Initialize a new energy quantity from kilowatt hours. + + Args: + kilowatt_hours: The energy in kilowatt hours. + + Returns: + A new energy quantity. + """ + return cls(mwh=kilowatt_hours / Decimal(1e3)) + class EnergyMarketCodeType(enum.Enum): """ From 6f25b32f122b104f11f1ef7510e478d4f5996a75 Mon Sep 17 00:00:00 2001 From: camille-bouvy-frequenz Date: Fri, 12 Jan 2024 21:05:10 +0100 Subject: [PATCH 2/2] Update release notes Signed-off-by: camille-bouvy-frequenz --- RELEASE_NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 75cd00b..6739bb5 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -16,6 +16,7 @@ Commiting the API definitions and preparing the repo to the pass all CI tests. - Commiting the electricity trading api specs. - Rename PublicOrders to PublicTrades - Add a python client with pyton wrappers for methods & classes and support for streaming orders. +- Add unit conversion methods to the Energy type ## Bug Fixes