Skip to content

Commit

Permalink
Fix key error when notification returns empty list.
Browse files Browse the repository at this point in the history
  • Loading branch information
RenierM26 committed Aug 11, 2022
1 parent 53d54d9 commit 91b177f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions pyhyypapi/alarm_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ def _last_notice(self, site_id: int) -> dict[Any, Any]:
site_id=site_id, json_key=0
)

_last_event = _last_notification["eventNumber"]
_last_event_datetime = str(
datetime.fromtimestamp(_last_notification["timestamp"] / 1000)
) # Epoch in ms

_response = {
"lastNoticeTime": _last_event_datetime,
"lastNoticeName": EventNumber[str(_last_event)],
}
if _last_notification:

_last_event = _last_notification["eventNumber"]
_last_event_datetime = str(
datetime.fromtimestamp(_last_notification["timestamp"] / 1000)
) # Epoch in ms

_response = {
"lastNoticeTime": _last_event_datetime,
"lastNoticeName": EventNumber[str(_last_event)],
}

return _response

Expand Down
2 changes: 1 addition & 1 deletion pyhyypapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def site_notifications(
f"Error getting site notifications from api: {_json_result['error']}"
)

if json_key is None:
if not json_key or _json_result["listSiteNotifications"][str(site_id)] is None:
return _json_result["listSiteNotifications"][str(site_id)]

return _json_result["listSiteNotifications"][str(site_id)][json_key]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='pyhyypapi',
version="0.0.0.5",
version="0.0.0.6",
license='Apache Software License 2.0',
author='Renier Moorcroft',
author_email='[email protected]',
Expand Down

0 comments on commit 91b177f

Please sign in to comment.