Skip to content

Commit

Permalink
Merge pull request #195 from PatrickFrederiksen/main
Browse files Browse the repository at this point in the history
Handle no Events returned from EasyIQ fixes #186
  • Loading branch information
scaarup authored Nov 22, 2024
2 parents 7e01660 + 41b1532 commit 66f6a23
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions custom_components/aula/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,47 +583,50 @@ def is_correct_format(date_string, format):
"Could not parse timestamp: " + str(date_string)
)
return False

for i in ugeplaner.json()["Events"]:
if is_correct_format(i["start"], "%Y/%m/%d %H:%M"):
_LOGGER.debug("No Event")
start_datetime = datetime.datetime.strptime(
i["start"], "%Y/%m/%d %H:%M"
)
_LOGGER.debug(start_datetime)
end_datetime = datetime.datetime.strptime(
i["end"], "%Y/%m/%d %H:%M"
)
if start_datetime.date() == end_datetime.date():
formatted_day = findDay(
start_datetime.strftime("%d %m %Y")
try:
for i in ugeplaner.json()["Events"]:
if is_correct_format(i["start"], "%Y/%m/%d %H:%M"):
_LOGGER.debug("No Event")
start_datetime = datetime.datetime.strptime(
i["start"], "%Y/%m/%d %H:%M"
)
formatted_start = start_datetime.strftime(" %H:%M")
formatted_end = end_datetime.strftime("- %H:%M")
dresult = f"{formatted_day} {formatted_start} {formatted_end}"
else:
formatted_start = findDay(
start_datetime.strftime("%d %m %Y")
)
formatted_end = findDay(
end_datetime.strftime("%d %m %Y")
)
dresult = f"{formatted_start} {formatted_end}"
_ugep = _ugep + "<br><b>" + dresult + "</b><br>"
if i["itemType"] == "5":
_ugep = (
_ugep + "<br><b>" + str(i["title"]) + "</b><br>"
_LOGGER.debug(start_datetime)
end_datetime = datetime.datetime.strptime(
i["end"], "%Y/%m/%d %H:%M"
)
if start_datetime.date() == end_datetime.date():
formatted_day = findDay(
start_datetime.strftime("%d %m %Y")
)
formatted_start = start_datetime.strftime(" %H:%M")
formatted_end = end_datetime.strftime("- %H:%M")
dresult = f"{formatted_day} {formatted_start} {formatted_end}"
else:
formatted_start = findDay(
start_datetime.strftime("%d %m %Y")
)
formatted_end = findDay(
end_datetime.strftime("%d %m %Y")
)
dresult = f"{formatted_start} {formatted_end}"
_ugep = _ugep + "<br><b>" + dresult + "</b><br>"
if i["itemType"] == "5":
_ugep = (
_ugep + "<br><b>" + str(i["title"]) + "</b><br>"
)
else:
_ugep = (
_ugep
+ "<br><b>"
+ str(i["ownername"])
+ "</b><br>"
)
_ugep = _ugep + str(i["description"]) + "<br>"
else:
_ugep = (
_ugep
+ "<br><b>"
+ str(i["ownername"])
+ "</b><br>"
)
_ugep = _ugep + str(i["description"]) + "<br>"
else:
_LOGGER.debug("None")
_LOGGER.debug("None")
except KeyError:
_LOGGER.debug("None")

if thisnext == "this":
self.ugep_attr[first_name] = _ugep
elif thisnext == "next":
Expand Down

0 comments on commit 66f6a23

Please sign in to comment.