Skip to content

Commit

Permalink
Merge pull request #519 from MTrab:Fix-fixed-price-issues
Browse files Browse the repository at this point in the history
Fix issue with fixed price sensor
  • Loading branch information
MTrab authored Jun 17, 2024
2 parents b87b938 + a74c0e8 commit 27dc729
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime, timedelta
from logging import getLogger

import pytz
import homeassistant.util.dt as dt_util

from ...const import CONF_FIXED_PRICE_VALUE, INTERVAL
from .regions import REGIONS
Expand All @@ -21,24 +21,19 @@

def prepare_data(value, date, tz) -> list: # pylint: disable=invalid-name
"""Get today prices."""
local_tz = pytz.timezone(tz)
dt = datetime.now() # pylint: disable=invalid-name
dt = pytz.utc.localize(dt) # pylint: disable=invalid-name
tmp_offset = str(dt.astimezone(local_tz).utcoffset()).split(":")
local_tz = dt_util.get_default_time_zone()
dt = dt_util.now(local_tz) # pylint: disable=invalid-name
offset = (str(dt).split('+'))[1]

offset = tmp_offset[0]
if len(offset) < 2:
offset = f"0{tmp_offset[0]}"

offset += f":{tmp_offset[1]}"
reslist = []
i = 0
while i < 24:
hour = str(i)
if len(hour) < 2:
hour = f"0{hour}"

tmpdate = datetime.fromisoformat(f"{date}T{hour}:00:00+{offset}")
# tmpdate = datetime.fromisoformat(f"{date}T{hour}:00:00+{offset}")
tmpdate = dt_util.parse_datetime(f"{date}T{hour}:00:00+{offset}")
tmp = INTERVAL(value, tmpdate)
if date in tmp.hour.strftime("%Y-%m-%d"):
reslist.append(tmp)
Expand Down
6 changes: 4 additions & 2 deletions custom_components/energidataservice/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"pricetype": "Price calculated in",
"cost_template": "Template for additional costs",
"in_cent": "Show prices in cent",
"fixed_value": "Insert price - WITHOUT VAT"
"fixed_value": "Insert price - WITHOUT VAT",
"fixed_vat": "VAT value in % (ie 25 for 25% VAT)"
},
"description": "Set details for {name} in {country}"
},
Expand Down Expand Up @@ -77,7 +78,8 @@
"pricetype": "Price calculated in",
"cost_template": "Template for additional costs",
"in_cent": "Show prices in cent",
"fixed_value": "Insert price - WITHOUT VAT"
"fixed_value": "Insert price - WITHOUT VAT",
"fixed_vat": "VAT value in % (ie 25 for 25% VAT)"
},
"description": "Set details for {name} in {country}"
},
Expand Down

0 comments on commit 27dc729

Please sign in to comment.