Skip to content

Commit

Permalink
Merge pull request #382 from MTrab:Add-automatic-discount-calculations
Browse files Browse the repository at this point in the history
Add discount tariffs
  • Loading branch information
MTrab committed Oct 11, 2023
2 parents 6d22b6e + bbbaa41 commit 8bbc984
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ async def async_get_tariffs(self):

try:
chargeowner = CHARGEOWNERS[self._chargeowner]

limit = "limit=500"
objfilter = 'filter=%7B"chargetypecode": {},"gln_number": ["{}"]%7D'.format( # pylint: disable=consider-using-f-string
str(chargeowner["type"]).replace("'", '"'), chargeowner["gln"]
)
sort = "sort=ValidFrom desc"

query = f"{objfilter}&{sort}&{limit}"
_LOGGER.info(query)
resp = await self.async_call_api(query)

if len(resp) == 0:
Expand All @@ -76,6 +78,7 @@ async def async_get_tariffs(self):
return
else:
# We got data from the DataHub - update the dataset

self._all_tariffs = resp

check_date = (datetime.utcnow()).strftime("%Y-%m-%d")
Expand All @@ -91,17 +94,18 @@ async def async_get_tariffs(self):
if "Price" in key:
hour = str(int("".join(filter(str.isdigit, key))) - 1)

current_val = val if val is not None else baseprice

if len(tariff_data) == 24:
current_val += tariff_data[hour]

tariff_data.update(
{hour: val if val is not None else baseprice}
{hour: current_val}
)

if len(tariff_data) == 24:
self._tariffs = tariff_data
break
self._tariffs.update(tariff_data)

_LOGGER.debug(
"Tariffs:\n%s", json.dumps(self.tariffs, indent=2, default=str)
)
return self.tariffs
except KeyError:
_LOGGER.error(
Expand All @@ -126,14 +130,19 @@ def get_dated_tariff(self, date: datetime) -> dict:
if "Price" in key:
hour = str(int("".join(filter(str.isdigit, key))) - 1)

current_val = val if val is not None else baseprice

if len(tariff_data) == 24:
current_val += tariff_data[hour]

tariff_data.update(
{hour: val if val is not None else baseprice}
{hour: current_val}
)

if len(tariff_data) == 24:
return tariff_data

return {}
if len(tariff_data) == 24:
return tariff_data
else:
return {}

def get_dated_system_tariff(self, date: datetime) -> dict:
"""Get system tariffs for this specific date."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"Konstant": {
"gln": "5790000704842",
"company": "Konstant Net A/S - 151",
"type": ["151-NT01T"],
"type": ["151-NT01T", "151-NRA04T"],
},
"Cerius": {
"gln": "5790000705184",
Expand All @@ -24,12 +24,12 @@
"N1": {
"gln": "5790001089030",
"company": "N1 A/S - 131",
"type": ["CD"],
"type": ["CD", "CD R"],
},
"Dinel": {
"gln": "5790000610099",
"company": "Dinel A/S",
"type": ["TCL>100_02"],
"type": ["TCL>100_02", "TCL<100_52"],
},
"TREFOR El-net": {
"gln": "5790000392261",
Expand Down Expand Up @@ -84,7 +84,7 @@
"Ikast El Net": {
"gln": "5790000682102",
"company": "Ikast El Net A/S",
"type": ["IEV-NT-01", "IEV-NT-11"],
"type": ["IEV-NT-11"],
},
"FLOW Elnet": {
"gln": "5790000392551",
Expand Down Expand Up @@ -114,7 +114,7 @@
"Tarm Elværk Net": {
"gln": "5790000706419",
"company": "Tarm Elværk Net A/S",
"type": ["TEV-NT-01"],
"type": ["TEV-NT-01", "TEV-NT-01R"],
},
"Zeanet": {
"gln": "5790001089375",
Expand All @@ -139,11 +139,11 @@
"Sunds Net": {
"gln": "5790001095444",
"company": "Sunds Net A.m.b.A",
"type": ["SEF-NT-05"],
"type": ["SEF-NT-05", "SEF-NT-05R"],
},
"Aal El-Net": {
"gln": "5790001095451",
"company": "Aal El-Net A.m.b.A",
"type": ["AAL-NT-05"],
"type": ["AAL-NT-05", "AAL-NTR05"],
},
}

0 comments on commit 8bbc984

Please sign in to comment.