Skip to content

Commit d901117

Browse files
authored
Merge pull request #209 from FBoissadier/feature/implement-save-power-schedule
Implementation of the save method of PowerSchedule API in core_sys_info
2 parents 2477249 + 68de376 commit d901117

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

synology_api/core_sys_info.py

Lines changed: 66 additions & 1 deletion
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):
@@ -576,6 +577,70 @@ def hardware_power_schedule(self) -> dict[str, object] | str:
576577
req_param = {'version': info['maxVersion'], 'method': 'load'}
577578

578579
return self.request_data(api_name, api_path, req_param)
580+
581+
def hardware_set_power_schedule(self, poweron_tasks: List[dict] = [], poweroff_tasks: List[dict] = []) -> dict:
582+
"""Set the power schedule, poweron tasks and poweroff tasks
583+
584+
Parameters
585+
----------
586+
poweron_tasks : List[dict], optional
587+
List of tasks for power on. Defaults to `[]`
588+
Example of a task:
589+
```python
590+
{
591+
"enabled": True, # Enable or not the task
592+
"hour": 13, # Hour 0-23
593+
"min": 59, # Minutes 0-59
594+
"weekdays": "0,1,2,3,4,5,6" # All days of the week (Sunday, Monday, Tuesday, Wednesday, Thrusday, Friday, Saturday)
595+
}
596+
```
597+
poweroff_tasks : List[dict], optional
598+
List of tasks for power off. Defaults to `[]`
599+
Example of a task:
600+
```python
601+
{
602+
"enabled": True, # Enable or not the task
603+
"hour": 13, # Hour 0-23
604+
"min": 59, # Minutes 0-59
605+
"weekdays": "0,1,2,3,4,5,6" # All days of the week (Sunday, Monday, Tuesday, Wednesday, Thrusday, Friday, Saturday)
606+
}
607+
```
608+
Returns
609+
-------
610+
dict
611+
List of tasks in power schedule
612+
613+
Example return
614+
----------
615+
```json
616+
{
617+
"data": {
618+
"poweroff_tasks": [],
619+
"poweron_tasks": [
620+
{
621+
"enabled": true,
622+
"hour": 0,
623+
"min": 0,
624+
"weekdays": "1,2,3,4,5"
625+
}
626+
]
627+
},
628+
"success": true
629+
}
630+
```
631+
"""
632+
633+
api_name = 'SYNO.Core.Hardware.PowerSchedule'
634+
info = self.core_list[api_name]
635+
api_path = info["path"]
636+
req_param = {
637+
"version": info["maxVersion"],
638+
"method": "save",
639+
"poweron_tasks": json.dumps(poweron_tasks),
640+
"poweroff_tasks": json.dumps(poweroff_tasks)
641+
}
642+
643+
return self.request_data(api_name, api_path, req_param)
579644

580645
def terminal_info(self) -> dict[str, object] | str:
581646
api_name = 'SYNO.Core.Terminal'

0 commit comments

Comments
 (0)