-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add schedule API and refactor info/config/stat apis in DownloadStation #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -140,9 +140,21 @@ Download Station usage | |||||||
|
||||||||
if "SYNO.DownloadStation.Info" in api.apis: | ||||||||
|
||||||||
api.download_station.update_info() | ||||||||
api.download_station.get_info() | ||||||||
|
||||||||
api.download_station.update_config() | ||||||||
api.download_station.get_config() | ||||||||
|
||||||||
api.download_station.update_stat() | ||||||||
api.download_station.get_stat() | ||||||||
|
||||||||
api.download_station.update_schedule_config() | ||||||||
api.download_station.get_schedule_config() | ||||||||
# set_schedule_config(self, enabled: bool = None, emule_enabled: bool = None) | ||||||||
api.download_station.set_schedule_config(True, False) | ||||||||
Comment on lines
+154
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
|
||||||||
# The download list will be updated after each of the following functions: | ||||||||
# You should have the right on the (default) directory that the download will be saved, or you will get a 403 or 406 error | ||||||||
api.download_station.create("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4") | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,18 @@ class SynoDownloadStation: | |
|
||
API_KEY = "SYNO.DownloadStation.*" | ||
INFO_API_KEY = "SYNO.DownloadStation.Info" | ||
SCHEDULE_API_KEY = "SYNO.DownloadStation.Schedule" | ||
STAT_API_KEY = "SYNO.DownloadStation.Statistic" | ||
TASK_API_KEY = "SYNO.DownloadStation.Task" | ||
|
||
def __init__(self, dsm): | ||
"""Initialize a Download Station.""" | ||
self._dsm = dsm | ||
self._tasks_by_id = {} | ||
self._schedule_config = {} | ||
self._stat = {} | ||
self._info = {} | ||
self._config = {} | ||
self.additionals = [ | ||
"detail", | ||
"file", | ||
|
@@ -32,17 +37,50 @@ def update(self): | |
self._tasks_by_id[task_data["id"]] = SynoDownloadTask(task_data) | ||
|
||
# Global | ||
def update_info(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the intention of this dedicated update method? |
||
"""Update info about the Download Station instance.""" | ||
self._info = self._dsm.get(self.INFO_API_KEY, "GetInfo")["data"] | ||
|
||
def get_info(self): | ||
"""Return general informations about the Download Station instance.""" | ||
return self._dsm.get(self.INFO_API_KEY, "GetInfo") | ||
return self._info | ||
|
||
def update_config(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the intention of this dedicated update method? |
||
"""Update configuration about the Download Station instance.""" | ||
self._config = self._dsm.get(self.INFO_API_KEY, "GetConfig")["data"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def get_config(self): | ||
"""Return configuration about the Download Station instance.""" | ||
return self._dsm.get(self.INFO_API_KEY, "GetConfig") | ||
return self._config | ||
|
||
def update_schedule_config(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the intention of this dedicated update method? |
||
"""Update schedule configuration about the Download Station instance.""" | ||
self._schedule_config = self._dsm.get(self.SCHEDULE_API_KEY, "GetConfig")[ | ||
"data" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could cause KeyError, in case _dsm.get() was unsuccessful |
||
] | ||
|
||
def get_schedule_config(self): | ||
"""Return schedule configuration about the Download Station instance.""" | ||
return self._schedule_config | ||
|
||
def set_schedule_config(self, enabled: bool = None, emule_enabled: bool = None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set defaults to |
||
"""Set schedule configuration about the Download Station instance.""" | ||
config = {} | ||
if enabled is not None: | ||
config["enabled"] = enabled | ||
if emule_enabled is not None: | ||
config["emule_enabled"] = emule_enabled | ||
res = self._dsm.get(self.SCHEDULE_API_KEY, "SetConfig", config) | ||
self.update_schedule_config() | ||
return res | ||
|
||
def update_stat(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the intention of this dedicated update method? |
||
"""Update statistic about the Download Station instance.""" | ||
self._stat = self._dsm.get(self.STAT_API_KEY, "GetInfo")["data"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def get_stat(self): | ||
"""Return statistic about the Download Station instance.""" | ||
return self._dsm.get(self.STAT_API_KEY, "GetInfo") | ||
return self._stat | ||
|
||
# Downloads | ||
def get_all_tasks(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""DSM 6 SYNO.DownloadStation.Schedule data.""" | ||
|
||
DSM_6_DOWNLOAD_STATION_SCHEDULE_CONFIG = { | ||
"data": {"enabled": True, "emule_enabled": False}, | ||
"success": True, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rebase to current
master
branch