-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvetray.py
46 lines (39 loc) · 1.25 KB
/
vetray.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
from pyvesync import VeSync
from pystray import Icon as icon, Menu as menu, MenuItem as item
from PIL import Image
import json
# Rename account-ex.json to account.json and fill in your VeSync account details
with open('account.json') as j:
account = json.load(j)
dd = []
de = []
def refreshList():
manager = VeSync(account['email'], account['password'], time_zone=account['timezone'])
manager.login()
manager.update()
firstRun = 0
dd.clear()
de.clear()
for device in manager.outlets:
dd.append(device.displayJSON()['Device Name'])
de.append(device.displayJSON()['Status'])
return manager
manager = refreshList()
def toggle(x):
def inner(icon, item):
if de[x]=='on':
manager.outlets[x].turn_off()
de[x]='off'
elif de[x]=='off':
manager.outlets[x].turn_on()
de[x]='on'
return inner
menuObj=menu(lambda: [
item(dd[i],toggle(i))
for i in range(0,len(dd))]
+ [menu.SEPARATOR]
+ [item('Refresh Devices', lambda icon, item: refreshList())]
+ [item('Exit', lambda icon, item: icon.stop())]
)
# Plug icon made by https://www.flaticon.com/authors/pixel-perfect
icon("VeTray", icon=Image.open("plug.png"), title="VeTray", menu=menuObj).run()