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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from dataclasses import dataclass, field


@dataclass
class SmartEnergyTariffConfiguration:
pass


@dataclass
class SmartEnergyTariff:
name: str = "smartEnergy"
type: str = "smart_energy"
official: bool = True
Comment on lines +10 to +13
configuration: SmartEnergyTariffConfiguration = field(default_factory=SmartEnergyTariffConfiguration)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
import datetime
import logging
from typing import Dict

from modules.common import req
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_state import TariffState
from modules.electricity_pricing.flexible_tariffs.smart_energy.config import SmartEnergyTariff

log = logging.getLogger(__name__)


def fetch(config: SmartEnergyTariff) -> Dict[str, float]:
raw_prices = req.get_http_session().get(
"https://apis.smartenergy.at/market/v1/price",
timeout=15
).json()["data"]
if len(raw_prices) == 0:
raise Exception("Es konnten keine Preise vom SmartEnergy-Server abgerufen werden.")
prices: Dict[str, float] = {}
for data in raw_prices:
formatted_price = data["value"] / 100000 # ct/kWh -> €/Wh
timestamp = datetime.datetime.strptime(data["date"], "%Y-%m-%dT%H:%M:%S%z").timestamp()
prices.update({str(int(timestamp)): formatted_price})
return prices


def create_electricity_tariff(config: SmartEnergyTariff):
def updater():
return TariffState(prices=fetch(config))
return updater


device_descriptor = DeviceDescriptor(configuration_factory=SmartEnergyTariff)