Skip to content

Commit

Permalink
#281 fix bug in parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Jul 22, 2023
1 parent e350c78 commit e609a6f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/peaqev/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"requirements": [
"peaqevcore==19.0.1"
],
"version": "3.0.2"
"version": "3.0.3"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logging
from dataclasses import dataclass, field
from datetime import date, timedelta
from datetime import date, timedelta, datetime

_LOGGER = logging.getLogger(__name__)

@dataclass
class NordPoolModel:
Expand All @@ -18,9 +21,13 @@ class NordPoolModel:
dynamic_top_price_type: str = ""
dynamic_top_price: float|None = None

async def async_create_date_dict(self, numbers: dict[date,float]|list[float]) -> dict[date, float]:
async def async_create_date_dict(self, numbers: dict|list) -> dict[date, float]:
if isinstance(numbers, dict):
return numbers
try:
return {datetime.strptime(key, "%Y-%m-%d").date(): value for key, value in numbers.items()}
except ValueError:
_LOGGER.error("Could not convert date string to date object")
return {}
today = date.today()
delta = timedelta(days=len(numbers) - 1)
start_date = today - delta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async def async_add_average_data(self, new_val):
if isinstance(new_val, float):
rounded = round(new_val, 3)
if datetime.now().date not in self.model.average_data.keys():
self.model.average_data[datetime.now().date] = rounded
self.model.average_data[date.today()] = rounded
await self.async_cap_average_data_length()

async def async_cap_average_data_length(self):
Expand Down

0 comments on commit e609a6f

Please sign in to comment.