|
1 | 1 | from __future__ import annotations |
2 | | -from typing import Optional |
| 2 | +from typing import Optional, List |
3 | 3 | from . import base_api |
| 4 | +import json |
4 | 5 |
|
5 | 6 |
|
6 | 7 | class SysInfo(base_api.BaseApi): |
@@ -576,6 +577,70 @@ def hardware_power_schedule(self) -> dict[str, object] | str: |
576 | 577 | req_param = {'version': info['maxVersion'], 'method': 'load'} |
577 | 578 |
|
578 | 579 | 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) |
579 | 644 |
|
580 | 645 | def terminal_info(self) -> dict[str, object] | str: |
581 | 646 | api_name = 'SYNO.Core.Terminal' |
|
0 commit comments