-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #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
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
15 changes: 15 additions & 0 deletions
15
packages/modules/electricity_tariffs/energycharts/config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
packages/modules/electricity_tariffs/energycharts/tariff.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |