diff --git a/packages/control/optional.py b/packages/control/optional.py index e1ef9688b8..975ca28567 100644 --- a/packages/control/optional.py +++ b/packages/control/optional.py @@ -42,7 +42,7 @@ def flexible_tariff_module(self) -> TypingOptional[ConfigurableFlexibleTariff]: def flexible_tariff_module(self, value: TypingOptional[ConfigurableFlexibleTariff]): if (value is None or (self._flexible_tariff_module and value and - self._flexible_tariff_module.config.name != value.config.name)): + self._flexible_tariff_module.config != value.config)): self.data.electricity_pricing.flexible_tariff.get = PricingGet() self._reset_state(self.data.electricity_pricing.flexible_tariff) self._flexible_tariff_module = value @@ -56,7 +56,7 @@ def grid_fee_module(self) -> TypingOptional[ConfigurableGridFee]: def grid_fee_module(self, value: TypingOptional[ConfigurableGridFee]): if (value is None or (self._grid_fee_module and value and - self._grid_fee_module.config.name != value.config.name)): + self._grid_fee_module.config != value.config)): self.data.electricity_pricing.grid_fee.get = PricingGet() self._reset_state(self.data.electricity_pricing.grid_fee) self._grid_fee_module = value diff --git a/packages/modules/electricity_pricing/flexible_tariffs/awattar/config.py b/packages/modules/electricity_pricing/flexible_tariffs/awattar/config.py index 77f87d5805..783799dca6 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/awattar/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/awattar/config.py @@ -1,24 +1,18 @@ +from dataclasses import dataclass, field + + +@dataclass class AwattarTariffConfiguration: - def __init__(self, - country: str = "de", - net: bool = True, - fix: float = 0.000015, - proportional: float = 3, - tax: float = 20) -> None: - self.country = country - self.net = net - self.fix = fix - self.proportional = proportional - self.tax = tax + country: str = "de" + net: bool = True + fix: float = 0.000015 + proportional: float = 3 + tax: float = 20 +@dataclass class AwattarTariff: - def __init__(self, - name: str = "aWATTar/tado° HOURLY", - type: str = "awattar", - official: bool = True, - configuration: AwattarTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or AwattarTariffConfiguration() + name: str = "aWATTar/tado° HOURLY" + type: str = "awattar" + official: bool = True + configuration: AwattarTariffConfiguration = field(default_factory=AwattarTariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/ekz/config.py b/packages/modules/electricity_pricing/flexible_tariffs/ekz/config.py index 8bc8bfeae4..3719530e87 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/ekz/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/ekz/config.py @@ -1,17 +1,16 @@ +from dataclasses import dataclass, field + + +@dataclass class EkzTariffConfiguration: - def __init__(self): - self.country = "ch" - self.unit = "Rp" - self.update_hours = [18, 19] + country: str = "ch" + unit: str = "Rp" + update_hours: list[int] = field(default_factory=lambda: [18, 19]) +@dataclass class EkzTariff: - def __init__(self, - name: str = "EKZ (CH)", - type: str = "ekz", - official: bool = False, - configuration: EkzTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or EkzTariffConfiguration() + name: str = "EKZ (CH)" + type: str = "ekz" + official: bool = False + configuration: EkzTariffConfiguration = field(default_factory=EkzTariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/energycharts/config.py b/packages/modules/electricity_pricing/flexible_tariffs/energycharts/config.py index 789a4f2ffc..5f42af86c4 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/energycharts/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/energycharts/config.py @@ -1,16 +1,15 @@ +from dataclasses import dataclass, field + + +@dataclass class EnergyChartsTariffConfiguration: - def __init__(self, country: str = "DE-LU", surcharge: float = 0): - self.country = country - self.surcharge = surcharge + country: str = "DE-LU" + surcharge: float = 0 +@dataclass class EnergyChartsTariff: - def __init__(self, - name: str = "Energy-Charts", - type: str = "energycharts", - official: bool = True, - configuration: EnergyChartsTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or EnergyChartsTariffConfiguration() + name: str = "Energy-Charts" + type: str = "energycharts" + official: bool = True + configuration: EnergyChartsTariffConfiguration = field(default_factory=EnergyChartsTariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/config.py b/packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/config.py index 299ec37a18..4e39618144 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/config.py @@ -1,44 +1,38 @@ -from typing import List, Dict +from dataclasses import dataclass, field +from typing import Any +@dataclass class FixedHoursTariffConfiguration: - def __init__(self, - default_price: float = 0, - tariffs: List[Dict[str, any]] = None, - update_hours: List[int] = None) -> None: - self.default_price = default_price - self.tariffs = tariffs if tariffs is not None else [] - self.update_hours = update_hours if update_hours is not None else list(range(24)) - ''' - Example configuration: - "tariffs": [ - { - "name": "high_tariff", - "price": 0.20, - "active_times": { - "dates": [("01-01", "31-03"), ("01-07", "30-09")], # applicable date ranges (day-month) - "times": [("08:00", "12:00"), ("18:00", "22:00")] # active times during the day - } - }, - { - "name": "low_tariff", - "price": 0.05, - "active_times": { - "dates": [("01-04", "30-06"), ("01-10", "31-12")], # applicable date ranges (day-month) - "times": [("00:00", "06:00"), ("22:00", "23:59")] # active times during the day - } + ''' + Example configuration: + "tariffs": [ + { + "name": "high_tariff", + "price": 0.20, + "active_times": { + "dates": [("01-01", "31-03"), ("01-07", "30-09")], # applicable date ranges (day-month) + "times": [("08:00", "12:00"), ("18:00", "22:00")] # active times during the day } - ] - ''' + }, + { + "name": "low_tariff", + "price": 0.05, + "active_times": { + "dates": [("01-04", "30-06"), ("01-10", "31-12")], # applicable date ranges (day-month) + "times": [("00:00", "06:00"), ("22:00", "23:59")] # active times during the day + } + } + ] + ''' + default_price: float = 0 + tariffs: list[dict[str, Any]] = field(default_factory=list) + update_hours: list[int] = field(default_factory=lambda: list(range(24))) +@dataclass class FixedHoursTariff: - def __init__(self, - name: str = "Feste Tarifstunden (z.b. §14a EnWG Modul3)", - type: str = "fixed_hours", - official: bool = False, - configuration: FixedHoursTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or FixedHoursTariffConfiguration() + name: str = "Feste Tarifstunden (z.b. §14a EnWG Modul3)" + type: str = "fixed_hours" + official: bool = False + configuration: FixedHoursTariffConfiguration = field(default_factory=FixedHoursTariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/groupe_e/config.py b/packages/modules/electricity_pricing/flexible_tariffs/groupe_e/config.py index 54c89de4f0..9f4ba513a9 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/groupe_e/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/groupe_e/config.py @@ -1,16 +1,15 @@ +from dataclasses import dataclass, field + + +@dataclass class GroupeETariffConfiguration: - def __init__(self): - self.country = "ch" - self.unit = "Rp" + country: str = "ch" + unit: str = "Rp" +@dataclass class GroupeETariff: - def __init__(self, - name: str = "Groupe E (CH)", - type: str = "groupe_e", - official: bool = False, - configuration: GroupeETariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or GroupeETariffConfiguration() + name: str = "Groupe E (CH)" + type: str = "groupe_e" + official: bool = False + configuration: GroupeETariffConfiguration = field(default_factory=GroupeETariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/octopusenergy/config.py b/packages/modules/electricity_pricing/flexible_tariffs/octopusenergy/config.py index d255d41f1e..a4db21d2bf 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/octopusenergy/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/octopusenergy/config.py @@ -1,23 +1,17 @@ +from dataclasses import dataclass, field from typing import Optional +@dataclass class OctopusEnergyTariffConfiguration: - def __init__(self, - email: Optional[str] = None, - accountId: Optional[str] = None, - password: Optional[str] = None): - self.email = email - self.accountId = accountId - self.password = password + email: Optional[str] = None + accountId: Optional[str] = None + password: Optional[str] = None +@dataclass class OctopusEnergyTariff: - def __init__(self, - name: str = "Octopus Energy Deutschland", - type: str = "octopusenergy", - official: bool = False, - configuration: OctopusEnergyTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or OctopusEnergyTariffConfiguration() + name: str = "Octopus Energy Deutschland" + type: str = "octopusenergy" + official: bool = False + configuration: OctopusEnergyTariffConfiguration = field(default_factory=OctopusEnergyTariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/ostrom/config.py b/packages/modules/electricity_pricing/flexible_tariffs/ostrom/config.py index eb5192f7f7..8d5a2ecf2e 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/ostrom/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/ostrom/config.py @@ -1,24 +1,18 @@ +from dataclasses import dataclass, field from typing import Optional +@dataclass class OstromTariffConfiguration: - def __init__(self, - client_id: Optional[str] = None, - client_secret: Optional[str] = None, - zip: Optional[str] = None): - self.client_id = client_id - self.client_secret = client_secret - self.zip = zip - self.update_hours = [2, 8, 14, 20] # expected time to get next chunk of prices + client_id: Optional[str] = None + client_secret: Optional[str] = None + zip: Optional[str] = None + update_hours: list[int] = field(default_factory=lambda: [2, 8, 14, 20]) # expected time to get next chunk of prices +@dataclass class OstromTariff: - def __init__(self, - name: str = "ostrom", - type: str = "ostrom", - official: bool = False, - configuration: OstromTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or OstromTariffConfiguration() + name: str = "ostrom" + type: str = "ostrom" + official: bool = False + configuration: OstromTariffConfiguration = field(default_factory=OstromTariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/rabot/config.py b/packages/modules/electricity_pricing/flexible_tariffs/rabot/config.py index f9f994131d..f630b6b8b3 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/rabot/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/rabot/config.py @@ -1,22 +1,18 @@ +from dataclasses import dataclass, field from typing import Optional +@dataclass class RabotTariffConfiguration: - def __init__(self, - customer_number: Optional[str] = None, - contract_number: Optional[str] = None): - self.customer_number = customer_number - self.contract_number = contract_number - self.update_hours = [0] # Rabot publishes once daily at 00:00 for the following day + customer_number: Optional[str] = None + contract_number: Optional[str] = None + # Rabot publishes once daily at 00:00 for the following day + update_hours: list[int] = field(default_factory=lambda: [0]) +@dataclass class RabotTariff: - def __init__(self, - name: str = "Rabot", - type: str = "rabot", - official: bool = True, - configuration: RabotTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or RabotTariffConfiguration() + name: str = "Rabot" + type: str = "rabot" + official: bool = True + configuration: RabotTariffConfiguration = field(default_factory=RabotTariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/tibber/config.py b/packages/modules/electricity_pricing/flexible_tariffs/tibber/config.py index 6dc55067c5..32061e868d 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/tibber/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/tibber/config.py @@ -1,25 +1,20 @@ +from dataclasses import dataclass, field from typing import Optional +@dataclass class TibberTariffConfiguration: - def __init__(self, token: Optional[str] = None, home_id: Optional[str] = None): - self.token = token - self.home_id = home_id - self.update_hours = [14] # tibber publishes once daily before 14:00 - ''' - dynamische Netzentgelte müssen umgerechnet werden, - damit der Gesamtpreis nicht um den Normalpreis der Netzentgelte verzerrt wird. - ''' - self.includes_grid_fee = True + token: Optional[str] = None + home_id: Optional[str] = None + update_hours: list[int] = field(default_factory=lambda: [14]) # tibber publishes once daily before 14:00 + # dynamische Netzentgelte müssen umgerechnet werden, + # damit der Gesamtpreis nicht um den Normalpreis der Netzentgelte verzerrt wird. + includes_grid_fee: bool = True +@dataclass class TibberTariff: - def __init__(self, - name: str = "Tibber", - type: str = "tibber", - official: bool = True, - configuration: TibberTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or TibberTariffConfiguration() + name: str = "Tibber" + type: str = "tibber" + official: bool = True + configuration: TibberTariffConfiguration = field(default_factory=TibberTariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/voltego/config.py b/packages/modules/electricity_pricing/flexible_tariffs/voltego/config.py index b6d3b48cab..484d7d1a79 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/voltego/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/voltego/config.py @@ -1,33 +1,24 @@ +from dataclasses import dataclass, field from typing import Optional -class VoltegoToken(): - def __init__(self, - access_token: Optional[str] = None, - expires_in: Optional[str] = None, - created_at: Optional[str] = None) -> None: - self.access_token = access_token # don't show in UI - self.expires_in = expires_in # don't show in UI - self.created_at = created_at # don't show in UI +@dataclass +class VoltegoToken: + access_token: Optional[str] = field(default=None, repr=False) # don't show in UI + expires_in: Optional[int] = field(default=None) # don't show in UI + created_at: Optional[int] = field(default=None) # don't show in UI +@dataclass class VoltegoTariffConfiguration: - def __init__(self, - client_id: Optional[str] = None, - client_secret: Optional[str] = None, - token: VoltegoToken = None): - self.client_id = client_id - self.client_secret = client_secret - self.token = token or VoltegoToken() + client_id: Optional[str] = None + client_secret: Optional[str] = None + token: VoltegoToken = field(default_factory=VoltegoToken, compare=False) +@dataclass class VoltegoTariff: - def __init__(self, - name: str = "Voltego", - type: str = "voltego", - official: bool = True, - configuration: VoltegoTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or VoltegoTariffConfiguration() + name: str = "Voltego" + type: str = "voltego" + official: bool = True + configuration: VoltegoTariffConfiguration = field(default_factory=VoltegoTariffConfiguration) diff --git a/packages/modules/electricity_pricing/flexible_tariffs/westfalen_wind/config.py b/packages/modules/electricity_pricing/flexible_tariffs/westfalen_wind/config.py index 8cb3718fe0..78e1d4817e 100644 --- a/packages/modules/electricity_pricing/flexible_tariffs/westfalen_wind/config.py +++ b/packages/modules/electricity_pricing/flexible_tariffs/westfalen_wind/config.py @@ -1,39 +1,27 @@ +from dataclasses import dataclass, field from typing import Optional -class WestfalenWindToken(): - def __init__(self, - access_token: Optional[str] = None, - refresh_token: Optional[str] = None, - token_type: Optional[str] = None, - expires: Optional[int] = None, - created_at: Optional[float] = None) -> None: - self.access_token = access_token # don't show in UI - self.refresh_token = refresh_token # don't show in UI - self.token_type = token_type # don't show in UI - self.expires = expires # don't show in UI - self.created_at = created_at # don't show in UI +@dataclass +class WestfalenWindToken: + access_token: Optional[str] = field(default=None, repr=False) # don't show in UI + refresh_token: Optional[str] = field(default=None, repr=False) # don't show in UI + token_type: Optional[str] = field(default=None) # don't show in UI + expires: Optional[int] = field(default=None) # don't show in UI + created_at: Optional[float] = field(default=None) # don't show in UI +@dataclass class WestfalenWindTariffConfiguration: - def __init__(self, - username: Optional[str] = None, - password: Optional[str] = None, - contract_id: Optional[str] = None, - token: WestfalenWindToken = None): - self.username = username - self.password = password - self.contract_id = contract_id - self.token = token or WestfalenWindToken() + username: Optional[str] = None + password: Optional[str] = None + contract_id: Optional[str] = None + token: WestfalenWindToken = field(default_factory=WestfalenWindToken, compare=False) +@dataclass class WestfalenWindTariff: - def __init__(self, - name: str = "WestfalenWind", - type: str = "westfalen_wind", - official: bool = True, - configuration: WestfalenWindTariffConfiguration = None) -> None: - self.name = name - self.type = type - self.official = official - self.configuration = configuration or WestfalenWindTariffConfiguration() + name: str = "WestfalenWind" + type: str = "westfalen_wind" + official: bool = True + configuration: WestfalenWindTariffConfiguration = field(default_factory=WestfalenWindTariffConfiguration)