Skip to content

Commit 68276a9

Browse files
authored
Merge branch 'master' into feat/readme-update
2 parents 183d16d + 420ed02 commit 68276a9

File tree

5 files changed

+116
-18
lines changed

5 files changed

+116
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ ds_info = ds.get_info()
7575

7676
## Available Functions
7777

78-
At the moment there are around +300 APIs implemented, the majority is not documented, but some are.
78+
At the moment there are around +300 APIs implemented with countless methods for each, the majority is not documented, but some are.
7979

8080
You can find a exhaustive list here:
8181
[APIs - Supported APIs](https://n4s4.github.io/synology-api/docs/apis)

documentation/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
description='Python Synology API Wrapper',
1515
long_description=long_description,
1616
long_description_content_type='text/markdown',
17-
install_requires=['requests', 'urllib3', 'setuptools', 'requests_toolbelt', 'tqdm', 'cryptography'],
17+
install_requires=['requests', 'urllib3', 'setuptools', 'requests_toolbelt', 'tqdm', 'cryptography', 'treelib'],
1818
url='https://github.com/N4S4/synology-api',
1919
author='Renato Visaggio',
2020
author_email='synology.python.api@gmail.com'

synology_api/core_sys_info.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
2-
from typing import Optional
2+
from typing import Optional, List
33
from . import base_api
4+
import json
45

56

67
class SysInfo(base_api.BaseApi):
@@ -568,15 +569,7 @@ def hardware_ups(self) -> dict[str, object] | str:
568569
req_param = {'version': info['maxVersion'], 'method': 'get'}
569570

570571
return self.request_data(api_name, api_path, req_param)
571-
572-
def hardware_power_schedule(self) -> dict[str, object] | str:
573-
api_name = 'SYNO.Core.Hardware.PowerSchedule'
574-
info = self.core_list[api_name]
575-
api_path = info['path']
576-
req_param = {'version': info['maxVersion'], 'method': 'load'}
577-
578-
return self.request_data(api_name, api_path, req_param)
579-
572+
580573
def terminal_info(self) -> dict[str, object] | str:
581574
api_name = 'SYNO.Core.Terminal'
582575
info = self.core_list[api_name]

synology_api/event_scheduler.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from . import base_api
33
from .core_sys_info import SysInfo
44
import json
5+
from typing import List
56

67
class EventScheduler(base_api.BaseApi):
78
"""Event Scheduler API implementation.
@@ -14,6 +15,7 @@ class EventScheduler(base_api.BaseApi):
1415
- Get result output
1516
- Setters:
1617
- Set task settings
18+
- Set power schedule
1719
- Actions:
1820
- Enable task
1921
- Disable task
@@ -340,4 +342,107 @@ def task_create_or_set(
340342
api_name = 'SYNO.Core.EventScheduler.Root'
341343
req_param['SynoConfirmPWToken'] = self.__get_root_token()
342344

345+
return self.request_data(api_name, api_path, req_param)
346+
347+
def set_power_schedule(self, poweron_tasks: List[dict] = [], poweroff_tasks: List[dict] = []) -> dict:
348+
"""Set the power schedule, poweron tasks and poweroff tasks
349+
350+
Parameters
351+
----------
352+
poweron_tasks : List[dict], optional
353+
List of tasks for power on. Defaults to `[]`
354+
Example of a task:
355+
```python
356+
{
357+
"enabled": True, # Enable or not the task
358+
"hour": 13, # Hour 0-23
359+
"min": 59, # Minutes 0-59
360+
"weekdays": "0,1,2,3,4,5,6" # All days of the week (Sunday, Monday, Tuesday, Wednesday, Thrusday, Friday, Saturday)
361+
}
362+
```
363+
poweroff_tasks : List[dict], optional
364+
List of tasks for power off. Defaults to `[]`
365+
Example of a task:
366+
```python
367+
{
368+
"enabled": True, # Enable or not the task
369+
"hour": 13, # Hour 0-23
370+
"min": 59, # Minutes 0-59
371+
"weekdays": "0,1,2,3,4,5,6" # All days of the week (Sunday, Monday, Tuesday, Wednesday, Thrusday, Friday, Saturday)
372+
}
373+
```
374+
Returns
375+
-------
376+
dict
377+
List of tasks in power schedule
378+
379+
Example return
380+
----------
381+
```json
382+
{
383+
"data": {
384+
"poweroff_tasks": [],
385+
"poweron_tasks": [
386+
{
387+
"enabled": true,
388+
"hour": 0,
389+
"min": 0,
390+
"weekdays": "1,2,3,4,5"
391+
}
392+
]
393+
},
394+
"success": true
395+
}
396+
```
397+
"""
398+
399+
api_name = 'SYNO.Core.Hardware.PowerSchedule'
400+
info = self.core_list[api_name]
401+
api_path = info["path"]
402+
req_param = {
403+
"version": info["maxVersion"],
404+
"method": "save",
405+
"poweron_tasks": json.dumps(poweron_tasks),
406+
"poweroff_tasks": json.dumps(poweroff_tasks)
407+
}
408+
409+
return self.request_data(api_name, api_path, req_param)
410+
411+
412+
def load_power_schedule(self) -> dict:
413+
"""Load the power schedule, poweron tasks and poweroff tasks
414+
415+
Returns
416+
-------
417+
dict
418+
List of tasks in power schedule
419+
420+
Example return
421+
----------
422+
```json
423+
{
424+
"data": {
425+
"poweroff_tasks": [],
426+
"poweron_tasks": [
427+
{
428+
"enabled": true,
429+
"hour": 0,
430+
"min": 0,
431+
"weekdays": "1,2,3,4,5"
432+
}
433+
]
434+
},
435+
"success": true
436+
}
437+
```
438+
"""
439+
440+
api_name = 'SYNO.Core.Hardware.PowerSchedule'
441+
info = self.core_list[api_name]
442+
api_path = info['path']
443+
req_param = {
444+
'version': info['maxVersion'],
445+
'method': 'load'
446+
}
447+
343448
return self.request_data(api_name, api_path, req_param)

0 commit comments

Comments
 (0)