22from . import base_api
33from .core_sys_info import SysInfo
44import json
5+ from typing import List
56
67class 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