Skip to content

Commit

Permalink
added check to make sure either fuel_type or in_kwh=True is provided …
Browse files Browse the repository at this point in the history
…and get_options() to _EnergyFromHeating to return unit of each fuel_type
  • Loading branch information
Milli97 committed Feb 19, 2025
1 parent 251327a commit 9362c62
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion co2calculator/api/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
"""Energy classes"""
from typing import Optional
import pandas as pd

from co2calculator import ConversionFactors

Expand All @@ -10,7 +11,6 @@
calc_co2_heating,
)
from co2calculator.api.emission import EnergyEmissions

from co2calculator.energy.calculate_energy import conversion_factors


Expand Down Expand Up @@ -67,6 +67,9 @@ def from_heating(self, in_kwh: bool = False):
:param in_kwh: if True, consumption is in kWh
"""
if self.fuel_type is None and not in_kwh:
raise ValueError("Please provide a fuel type or set in_kwh to True")

return _EnergyFromHeating(
consumption=self.consumption,
fuel_type=self.fuel_type,
Expand Down Expand Up @@ -190,3 +193,19 @@ def calculate_co2e(self):
unit=unit,
)
return emissions

def get_options(self):
"""Return fuel type options and their corresponding units as a table."""

options = {
"fuel_type": [
"oil",
"liquid gas",
"coal",
"wood pellets",
"wood chips",
"gas",
],
"unit": ["l", "kg", "kg", "kg", "kg", "m^3"],
}
return pd.DataFrame(options)

0 comments on commit 9362c62

Please sign in to comment.