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

Add schedule API and refactor info/config/stat apis in DownloadStation #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ repos:
language: system
types: [text]
stages: [commit, push, manual]
- repo: https:/prettier/prettier
rev: 2.1.2
- repo: https:/pre-commit/mirrors-prettier
rev: v2.2.0
Comment on lines +48 to +49
Copy link

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

hooks:
- id: prettier
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# set_schedule_config(self, enabled: bool = None, emule_enabled: bool = None)
api.download_station.set_schedule_config(True, False)
api.download_station.set_schedule_config(enabled=True, emule_enabled=False)



# 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")
Expand Down
44 changes: 41 additions & 3 deletions src/synology_dsm/api/download_station/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,17 +37,50 @@ def update(self):
self._tasks_by_id[task_data["id"]] = SynoDownloadTask(task_data)

# Global
def update_info(self):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the intention of this dedicated update method?
Those the user is forced to do an manually initial update before info can be accessed

"""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):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the intention of this dedicated update method?
Those the user is forced to do an manually initial update before config data can be accessed

"""Update configuration about the Download Station instance."""
self._config = self._dsm.get(self.INFO_API_KEY, "GetConfig")["data"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • this could cause KeyError, in case _dsm.get() was unsuccessful
  • prior result was not restricted to content of data


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):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the intention of this dedicated update method?
Those the user is forced to do an manually initial update before schedule config data can be accessed

"""Update schedule configuration about the Download Station instance."""
self._schedule_config = self._dsm.get(self.SCHEDULE_API_KEY, "GetConfig")[
"data"
Copy link

Choose a reason for hiding this comment

The 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):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set defaults to False

"""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):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the intention of this dedicated update method?
Those the user is forced to do an manually initial update before stat data can be accessed

"""Update statistic about the Download Station instance."""
self._stat = self._dsm.get(self.STAT_API_KEY, "GetInfo")["data"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • this could cause KeyError, in case _dsm.get() was unsuccessful
  • prior result was not restricted to content of data


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):
Expand Down
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .api_data.dsm_6 import DSM_6_CORE_UTILIZATION_ERROR_1055
from .api_data.dsm_6 import DSM_6_DOWNLOAD_STATION_INFO_CONFIG
from .api_data.dsm_6 import DSM_6_DOWNLOAD_STATION_INFO_INFO
from .api_data.dsm_6 import DSM_6_DOWNLOAD_STATION_SCHEDULE_CONFIG
from .api_data.dsm_6 import DSM_6_DOWNLOAD_STATION_STAT_INFO
from .api_data.dsm_6 import DSM_6_DOWNLOAD_STATION_TASK_LIST
from .api_data.dsm_6 import DSM_6_DSM_INFORMATION
Expand Down Expand Up @@ -254,6 +255,9 @@ def _execute_request(self, method, url, params, **kwargs):
if SynoDownloadStation.TASK_API_KEY in url:
if "List" in url:
return DSM_6_DOWNLOAD_STATION_TASK_LIST
if SynoDownloadStation.SCHEDULE_API_KEY in url:
if "GetConfig" in url:
return DSM_6_DOWNLOAD_STATION_SCHEDULE_CONFIG

if SynoStorage.API_KEY in url:
return API_SWITCHER[self.dsm_version]["STORAGE_STORAGE"][
Expand Down
4 changes: 4 additions & 0 deletions tests/api_data/dsm_6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
from .download_station.const_6_download_station_info import (
DSM_6_DOWNLOAD_STATION_INFO_INFO,
)
from .download_station.const_6_download_station_schedule_config import (
DSM_6_DOWNLOAD_STATION_SCHEDULE_CONFIG,
)
from .download_station.const_6_download_station_stat import (
DSM_6_DOWNLOAD_STATION_STAT_INFO,
)
Expand Down Expand Up @@ -77,6 +80,7 @@
"DSM_6_DOWNLOAD_STATION_INFO_CONFIG",
"DSM_6_DOWNLOAD_STATION_INFO_INFO",
"DSM_6_DOWNLOAD_STATION_STAT_INFO",
"DSM_6_DOWNLOAD_STATION_SCHEDULE_CONFIG",
"DSM_6_DOWNLOAD_STATION_TASK_LIST",
"DSM_6_DSM_INFORMATION",
"DSM_6_DSM_NETWORK_2LAN_1PPPOE",
Expand Down
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,
}
16 changes: 13 additions & 3 deletions tests/test_synology_dsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,19 @@ def test_download_station(self):
assert self.api.download_station
assert not self.api.download_station.get_all_tasks()

assert self.api.download_station.get_info()["data"]["version"]
assert self.api.download_station.get_config()["data"]["default_destination"]
assert self.api.download_station.get_stat()["data"]["speed_download"]
self.api.download_station.update_info()
assert self.api.download_station.get_info()["version"]

self.api.download_station.update_config()
assert self.api.download_station.get_config()["default_destination"]

self.api.download_station.update_stat()
assert self.api.download_station.get_stat()["speed_download"]

self.api.download_station.update_schedule_config()
assert self.api.download_station.get_schedule_config()["enabled"]
assert not self.api.download_station.get_schedule_config()["emule_enabled"]

self.api.download_station.update()
assert self.api.download_station.get_all_tasks()
assert len(self.api.download_station.get_all_tasks()) == 8
Expand Down