commit f4da646a07a336b7ebda01e77423da3ae8e8a89c Author: Blagovest Petrov Date: Fri Dec 22 02:15:26 2023 +0200 first commit Signed-off-by: Blagovest Petrov diff --git a/lights.py b/lights.py new file mode 100644 index 0000000..453949d --- /dev/null +++ b/lights.py @@ -0,0 +1,46 @@ +import appuifw, e32 +import urllib + +class LampController: + def __init__(self): + self.script_lock = e32.Ao_lock() + self.main_menu_items = [u"Living Room", u"Exit"] + self.main_menu = appuifw.Listbox(self.main_menu_items, self.handle_main_selection) + self.sub_menu_items = [u"Lunichki on/off", u"Back"] + self.sub_menu = appuifw.Listbox(self.sub_menu_items, self.handle_sub_selection) + + def run(self): + appuifw.app.title = u"Lamp Control" + appuifw.app.body = self.main_menu + appuifw.app.exit_key_handler = self.exit_application + self.script_lock.wait() + + def handle_main_selection(self): + index = self.main_menu.current() + if index == len(self.main_menu_items) - 1: # Exit option + self.exit_application() + else: + appuifw.app.body = self.sub_menu + + def handle_sub_selection(self): + index = self.sub_menu.current() + if index == len(self.sub_menu_items) - 1: # Back option + appuifw.app.body = self.main_menu + elif index == 0: + self.lampa_hol() + + def lampa_hol(self): + data = '{"id":1, "method":"Switch.Set", "params":{"id":2, "on":false}}' + url = "http://relay1.home.blago.cloud/rpc" + try: + response = urllib.urlopen(url, data) + result = response.read() + appuifw.note(u"Lamp on/off triggered", "info") + except Exception, e: + appuifw.note(u"Error: " + str(e), "error") + + def exit_application(self): + self.script_lock.signal() + +if __name__ == '__main__': + LampController().run()