Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 18 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

class UpdateConfig:

DATASTORE_VERSION = 125
DATASTORE_VERSION = 126

valid_topic = [
"^openWB/bat/config/bat_control_activated$",
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class EnergyChartsTariffConfiguration:
country: str = "DE-LU"
surcharge: float = 0
net: bool = True
tax: float = 19


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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]
}
Loading