You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.6 KiB
46 lines
1.6 KiB
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()
|
|
|