Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API integration #413

Merged
merged 5 commits into from
Oct 13, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove mutable kwargs
developerfromjokela committed Oct 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 69558799ab3b67dc3b79cded56c8cf4f59f3f451
9 changes: 6 additions & 3 deletions custom_components/nordpool/aio_price.py
Original file line number Diff line number Diff line change
@@ -171,7 +171,7 @@ async def _io(self, url, **kwargs):

return await resp.json()

def _parse_json(self, data, areas=[]):
def _parse_json(self, data, areas=None):
"""
Parse json response from fetcher.
Returns dictionary with
@@ -184,7 +184,10 @@ def _parse_json(self, data, areas=[]):
- possible other values, such as min, max, average for hourly
"""

if areas is None:
areas = []
# If areas isn't a list, make it one

if not isinstance(areas, list):
areas = list(areas)

@@ -244,8 +247,8 @@ def _parse_json(self, data, areas=[]):
async def _fetch_json(self, data_type, end_date=None, areas=None):
"""Fetch JSON from API"""
# If end_date isn't set, default to tomorrow
if areas is None:
areas = []
if areas is None or len(areas) == 0:
raise Exception("Cannot query with empty areas")
if end_date is None:
end_date = date.today() + timedelta(days=1)
# If end_date isn't a date or datetime object, try to parse a string
4 changes: 3 additions & 1 deletion custom_components/nordpool/test_parser.py
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ async def _io(self, url, **kwargs):

return await resp.json()

def _parse_json(self, data, areas=[]):
def _parse_json(self, data, areas=None):
"""
Parse json response from fetcher.
Returns dictionary with
@@ -59,6 +59,8 @@ def _parse_json(self, data, areas=[]):
"""

# If areas isn't a list, make it one
if areas is None:
areas = []
if not isinstance(areas, list):
areas = list(areas)