forked from MiZai2/ayaled
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
executable file
·113 lines (99 loc) · 3.85 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
import decky
try:
from config import logger, IS_LED_SUSPEND_MODE_SUPPORTED
from huesync import LedControl
from utils import Color
import update
logger.info("HueSync main.py")
except Exception as e:
logger.error(e, exc_info=True)
class Plugin:
async def _main(self):
try:
self.ledControl = LedControl()
except Exception as e:
logger.error(e, exc_info=True)
async def setRGB(self, r: int, g: int, b: int, brightness: int = 100):
try:
logger.info(f"set_ledOn:{r},{g},{b}, brightness={brightness}")
self.ledControl.set_Color(Color(r, g, b), brightness=100)
except Exception as e:
logger.error(e, exc_info=True)
return False
async def setOff(self):
try:
self.ledControl.set_Color(Color(0, 0, 0), brightness=0)
logger.info("set_ledoff")
except Exception as e:
logger.error(e)
return False
async def get_suspend_mode(self):
try:
return self.ledControl.get_suspend_mode()
except Exception as e:
logger.error(e, exc_info=True)
return ""
async def set_suspend_mode(self, mode: str):
try:
if IS_LED_SUSPEND_MODE_SUPPORTED:
self.ledControl.set_suspend_mode(mode)
return True
else:
return False
except Exception as e:
logger.error(e, exc_info=True)
return False
async def is_support_suspend_mode(self):
return IS_LED_SUSPEND_MODE_SUPPORTED
async def update_latest(self):
logger.info("Updating latest")
try:
return update.update_latest()
except Exception as e:
logger.error(e, exc_info=True)
return False
async def get_version(self):
try:
return update.get_version()
except Exception as e:
logger.error(e, exc_info=True)
return ""
async def get_latest_version(self):
try:
return update.get_latest_version()
except Exception as e:
logger.error(e, exc_info=True)
# Function called first during the unload process, utilize this to handle your plugin being removed
async def _unload(self):
decky.logger.info("Goodbye World!")
pass
# Migrations that should be performed before entering `_main()`.
async def _migration(self):
decky.logger.info("Migrating")
# Here's a migration example for logs:
# - `~/.config/decky-template/template.log` will be migrated to `decky.DECKY_PLUGIN_LOG_DIR/template.log`
decky.migrate_logs(
os.path.join(
decky.DECKY_USER_HOME,
".config",
"decky-template",
"template.log",
)
)
# Here's a migration example for settings:
# - `~/homebrew/settings/template.json` is migrated to `decky.DECKY_PLUGIN_SETTINGS_DIR/template.json`
# - `~/.config/decky-template/` all files and directories under this root are migrated to `decky.DECKY_PLUGIN_SETTINGS_DIR/`
decky.migrate_settings(
os.path.join(decky.DECKY_HOME, "settings", "template.json"),
os.path.join(decky.DECKY_USER_HOME, ".config", "decky-template"),
)
# Here's a migration example for runtime data:
# - `~/homebrew/template/` all files and directories under this root are migrated to `decky.DECKY_PLUGIN_RUNTIME_DIR/`
# - `~/.local/share/decky-template/` all files and directories under this root are migrated to `decky.DECKY_PLUGIN_RUNTIME_DIR/`
decky.migrate_runtime(
os.path.join(decky.DECKY_HOME, "template"),
os.path.join(
decky.DECKY_USER_HOME, ".local", "share", "decky-template"
),
)