Skip to content

Commit

Permalink
Boersenmodul (#1568)
Browse files Browse the repository at this point in the history
* #Boersenstrompreise allgemein energycharts mit Grundpreisoption

* #Laenderauswahl fix

* #Boersenmodul v1

* #removed unused import

* #removed topics, cleaned code

* #removed whitespace flake8

* #use req

* # change variable serve_price to surchar_price

* #requested changes

* # requested change, cleaned code
  • Loading branch information
pama87 authored Jun 12, 2024
1 parent e539421 commit 3e6725a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Empty file.
15 changes: 15 additions & 0 deletions packages/modules/electricity_tariffs/energycharts/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

class EnergyChartsTariffConfiguration:
def __init__(self, country: str = 'de', surcharge: float = 0):
self.country = country
self.surcharge = surcharge


class EnergyChartsTariff:
def __init__(self,
name: str = "Energy-Charts",
type: str = "energycharts",
configuration: EnergyChartsTariffConfiguration = None) -> None:
self.name = name
self.type = type
self.configuration = configuration or EnergyChartsTariffConfiguration()
33 changes: 33 additions & 0 deletions packages/modules/electricity_tariffs/energycharts/tariff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from typing import Dict
from datetime import datetime, timedelta
from modules.common import req

from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_state import TariffState
from modules.common.configurable_tariff import ConfigurableElectricityTariff
from modules.electricity_tariffs.energycharts.config import EnergyChartsTariffConfiguration
from modules.electricity_tariffs.energycharts.config import EnergyChartsTariff


def fetch_prices(config: EnergyChartsTariffConfiguration) -> Dict[int, float]:
current_dateTime = datetime.now()
tomorrow = datetime.now() + timedelta(1)
start_time = current_dateTime.strftime("%Y-%m-%d") + 'T00%3A00%2B01%3A00'
end_time = tomorrow.strftime("%Y-%m-%d") + 'T23%3A59%2B01%3A00'
url = f'https://api.energy-charts.info/price?bzn={config.country}&start={start_time}&end={end_time}'
raw_prices = req.get_http_session().get(url).json()
price_arr = []
for price in raw_prices['price']:
price_arr.append((float(price + (config.surcharge*10))/1000000)) # €/MWh -> €/Wh + Aufschlag
prices: Dict[int, float] = {}
prices = dict(zip(raw_prices['unix_seconds'], price_arr))
return prices


def create_electricity_tariff(config: EnergyChartsTariff):
def updater():
return TariffState(prices=fetch_prices(config.configuration))
return ConfigurableElectricityTariff(config=config, component_updater=updater)


device_descriptor = DeviceDescriptor(configuration_factory=EnergyChartsTariff)

0 comments on commit 3e6725a

Please sign in to comment.