-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuwindow.py
38 lines (30 loc) · 1.14 KB
/
uwindow.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
from ulanzi import UlanziApp
class UlanziWindowAlert(UlanziApp):
def initialize(self):
super().initialize()
self.open_windows = set()
try:
self.windows = self.args['windows']
except KeyError as err:
self.error("Failed getting configuration {}".format(err.args[0]))
return
for window in self.windows:
window_entity = window['entity']
window_name = window['name']
self.listen_state(self.window_action, window_entity, window_name=window_name)
self.log(f"Initialized {len(self.windows)} windows")
def window_action(self, entity, attribute, old, new, kwargs):
window_name = kwargs['window_name']
if old != new and new == 'on':
self.open_windows.add(window_name)
elif old != new and new == 'off':
try:
self.open_windows.remove(window_name)
except KeyError:
pass
if len(self.open_windows) > 0:
self.update_app()
else:
self.delete_app()
def get_app_text(self):
return ", ".join(self.open_windows)