Skip to content

Commit

Permalink
Tweaks to support recording info in HA
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Oct 25, 2022
1 parent 42bb762 commit 9fc7742
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
44 changes: 28 additions & 16 deletions pyskyqremote/classes/recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@
import logging
from dataclasses import dataclass, field
from datetime import datetime
from operator import attrgetter

from pyskyqremote.classes.channel import build_channel_image_url

from ..const import (ALLRECORDINGS, PVR_IMAGE_URL, RESPONSE_OK,
REST_BOOK_PPVRECORDING, REST_BOOK_RECORDING,
REST_BOOK_SERIES_RECORDING, REST_DELETE, REST_POST,
REST_QUOTA_DETAILS, REST_RECORDING_DELETE,
REST_RECORDING_DETAILS, REST_RECORDING_ERASE,
REST_RECORDING_ERASE_ALL, REST_RECORDING_KEEP,
REST_RECORDING_LOCK,
REST_RECORDING_SET_LAST_PLAYED_POSITION,
REST_RECORDING_UNDELETE, REST_RECORDING_UNKEEP,
REST_RECORDING_UNLOCK, REST_RECORDINGS_LIST,
REST_SERIES_LINK, REST_SERIES_UNLINK)
from ..const import (
ALLRECORDINGS,
PVR_IMAGE_URL,
RESPONSE_OK,
REST_BOOK_PPVRECORDING,
REST_BOOK_RECORDING,
REST_BOOK_SERIES_RECORDING,
REST_DELETE,
REST_POST,
REST_QUOTA_DETAILS,
REST_RECORDING_DELETE,
REST_RECORDING_DETAILS,
REST_RECORDING_ERASE,
REST_RECORDING_ERASE_ALL,
REST_RECORDING_KEEP,
REST_RECORDING_LOCK,
REST_RECORDING_SET_LAST_PLAYED_POSITION,
REST_RECORDING_UNDELETE,
REST_RECORDING_UNKEEP,
REST_RECORDING_UNLOCK,
REST_RECORDINGS_LIST,
REST_SERIES_LINK,
REST_SERIES_UNLINK,
)
from .programme import Programme

_LOGGER = logging.getLogger(__name__)
Expand All @@ -37,17 +51,15 @@ def get_recordings(self, status, limit, offset):
REST_RECORDINGS_LIST.format(limit, offset)
)
if not resp or "pvrItems" not in resp:
_LOGGER.error(
"E0010R - Timeout retrieving recordings: %s", self._remote_config.host
)
return Recordings(recordings)
return None
rec_data = resp["pvrItems"]
for recording in rec_data:
if recording["status"] == status or status == ALLRECORDINGS:
built = self._build_recording(recording)
recordings.add(built)

return Recordings(recordings)
recordingssorted = sorted(recordings, key=attrgetter("starttime"))
return Recordings(recordingssorted)

def get_recording(self, pvrid):
"""Get the recording details."""
Expand Down
5 changes: 1 addition & 4 deletions pyskyqremote/skyq_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ def get_current_live_tv_programme(self, sid):
try:
query_date = datetime.utcnow()
programme = self.get_programme_from_epg(sid, query_date, query_date)
if not isinstance(programme, Programme):
return None

return programme
return programme if isinstance(programme, Programme) else None
except Exception as err: # pylint: disable=broad-except
_LOGGER.exception(
"X0010 - Error occurred: %s : %s : %s", self._host, sid, err
Expand Down

0 comments on commit 9fc7742

Please sign in to comment.