diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b6652b19..78fc7f39 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -45,7 +45,7 @@ repos: language: system types: [text] stages: [commit, push, manual] - - repo: https://github.com/prettier/prettier - rev: 2.1.2 + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.2.0 hooks: - id: prettier diff --git a/README.rst b/README.rst index b03430d3..5d16d625 100644 --- a/README.rst +++ b/README.rst @@ -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) + + # 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") diff --git a/src/synology_dsm/api/download_station/__init__.py b/src/synology_dsm/api/download_station/__init__.py index 94866dd5..bca12145 100644 --- a/src/synology_dsm/api/download_station/__init__.py +++ b/src/synology_dsm/api/download_station/__init__.py @@ -7,6 +7,7 @@ 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" @@ -14,6 +15,10 @@ 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): + """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): + """Update configuration about the Download Station instance.""" + self._config = self._dsm.get(self.INFO_API_KEY, "GetConfig")["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): + """Update schedule configuration about the Download Station instance.""" + self._schedule_config = self._dsm.get(self.SCHEDULE_API_KEY, "GetConfig")[ + "data" + ] + + 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): + """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): + """Update statistic about the Download Station instance.""" + self._stat = self._dsm.get(self.STAT_API_KEY, "GetInfo")["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): diff --git a/tests/__init__.py b/tests/__init__.py index b42188ac..ea1e6f67 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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 @@ -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"][ diff --git a/tests/api_data/dsm_6/__init__.py b/tests/api_data/dsm_6/__init__.py index 394e7587..3ab4be7f 100644 --- a/tests/api_data/dsm_6/__init__.py +++ b/tests/api_data/dsm_6/__init__.py @@ -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, ) @@ -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", diff --git a/tests/api_data/dsm_6/download_station/const_6_download_station_schedule_config.py b/tests/api_data/dsm_6/download_station/const_6_download_station_schedule_config.py new file mode 100644 index 00000000..3b7d2479 --- /dev/null +++ b/tests/api_data/dsm_6/download_station/const_6_download_station_schedule_config.py @@ -0,0 +1,6 @@ +"""DSM 6 SYNO.DownloadStation.Schedule data.""" + +DSM_6_DOWNLOAD_STATION_SCHEDULE_CONFIG = { + "data": {"enabled": True, "emule_enabled": False}, + "success": True, +} diff --git a/tests/test_synology_dsm.py b/tests/test_synology_dsm.py index d24023a9..892ba68d 100644 --- a/tests/test_synology_dsm.py +++ b/tests/test_synology_dsm.py @@ -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