diff --git a/packages/helpermodules/update_config.py b/packages/helpermodules/update_config.py index 0987ef9a05..216465264b 100644 --- a/packages/helpermodules/update_config.py +++ b/packages/helpermodules/update_config.py @@ -57,7 +57,7 @@ class UpdateConfig: - DATASTORE_VERSION = 125 + DATASTORE_VERSION = 126 valid_topic = [ "^openWB/bat/config/bat_control_activated$", @@ -3160,3 +3160,20 @@ def upgrade(topic: str, payload) -> None: return {topic: provider} self._loop_all_received_topics(upgrade) self._append_datastore_version(125) + + def upgrade_datastore_126(self) -> None: + def upgrade(topic: str, payload) -> None: + if "openWB/optional/ep/flexible_tariff/provider" == topic: + provider = decode_payload(payload) + if provider.get("type") == "energycharts": + changed = False + if provider["configuration"].get("net") is None: + provider["configuration"]["net"] = True + changed = True + if provider["configuration"].get("tax") is None: + provider["configuration"]["tax"] = 19 + changed = True + if changed: + return {topic: provider} + self._loop_all_received_topics(upgrade) + self._append_datastore_version(126) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/energycharts/config.py b/packages/modules/electricity_pricing/flexible_tariffs/energycharts/config.py index 5f42af86c4..46b120af96 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/energycharts/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/energycharts/config.py @@ -5,6 +5,8 @@ class EnergyChartsTariffConfiguration: country: str = "DE-LU" surcharge: float = 0 + net: bool = True + tax: float = 19 @dataclass diff --git a/packages/modules/electricity_pricing/flexible_tariffs/energycharts/tariff.py b/packages/modules/electricity_pricing/flexible_tariffs/energycharts/tariff.py index 5cb3b0ec67..75fa6dbc82 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/energycharts/tariff.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/energycharts/tariff.py @@ -27,7 +27,10 @@ def create_request_url(config: EnergyChartsTariffConfiguration) -> str: def parse_response(config: EnergyChartsTariffConfiguration, raw_prices: Dict[str, float]) -> Dict[str, float]: prices: Dict[str, float] = {} for timestamp, price_per_MWh in zip(raw_prices['unix_seconds'], raw_prices['price']): - prices[str(int(timestamp))] = float(price_per_MWh)/1000000 + config.surcharge + formatted_price = float(price_per_MWh)/1000000 + config.surcharge + if config.net is False: + formatted_price = formatted_price * (1 + config.tax / 100) + prices[str(int(timestamp))] = formatted_price log.debug("converted prices: %s : %s", len(prices), prices) return prices diff --git a/packages/modules/electricity_pricing/flexible_tariffs/energycharts/tariff_test.py b/packages/modules/electricity_pricing/flexible_tariffs/energycharts/tariff_test.py new file mode 100644 index 0000000000..8bfa863da8 --- /dev/null +++ b/packages/modules/electricity_pricing/flexible_tariffs/energycharts/tariff_test.py @@ -0,0 +1,30 @@ +from modules.electricity_pricing.flexible_tariffs.energycharts.config import EnergyChartsTariffConfiguration +from modules.electricity_pricing.flexible_tariffs.energycharts.tariff import parse_response + + +def test_parse_response_net_prices(): + # setup + config = EnergyChartsTariffConfiguration(net=True, surcharge=0) + + # execution + prices = parse_response(config, SAMPLE_DATA) + + # evaluation + assert prices == {"1717200000": 0.0001, "1717203600": 0.0002} + + +def test_parse_response_gross_prices_with_tax(): + # setup + config = EnergyChartsTariffConfiguration(net=False, surcharge=0, tax=19) + + # execution + prices = parse_response(config, SAMPLE_DATA) + + # evaluation + assert prices == {"1717200000": 0.000119, "1717203600": 0.000238} + + +SAMPLE_DATA = { + "unix_seconds": [1717200000, 1717203600], + "price": [100.0, 200.0] +}