def turn_off(args): """Connects to the Harmony and turn everything off""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) client.turn_off() client.disconnect(send_close=True) return 0
def listen_to_music(args): """Connects to the Harmony and starts Naar muziek luisteren zonder tv""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) client.start_activity(4520384) client.disconnect(send_close=True) return 0
def watch_tv(args): """Connects to the Harmony and starts TV kijken""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) client.start_activity(2758917) client.disconnect(send_close=True) return 0
def login(self): self.token = auth.login(self.username, self.password) if not self.token: raise Exception('Could not log in to the harmony service') session_token = auth.swap_auth_token(self.ip, self.port, self.token) self.harmony_client = client.create_and_connect_client(self.ip, self.port, self.token) if not self.harmony_client: raise Exception('Could not log in to the harmony device')
def start_activity(args): """Connects to the Harmony and prints the current activity.""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client(args.harmony_ip, args.harmony_port, token) pprint.pprint(client.start_activity(args.activity_id)) client.disconnect(send_close=True) return 0
def send_command_to_device(args): """Connects to the Harmony and prints the current activity.""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) pprint.pprint(client.send_button_press_to_device(args.command, args.device_id)) client.disconnect(send_close=True) return 0
def show_config(args): """Connects to the Harmony and prints its configuration.""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) pprint.pprint(client.get_config()) client.disconnect(send_close=True) return 0
def show_config(args): """Connects to the Harmony and prints its configuration.""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client(args.harmony_ip, args.harmony_port, token) pprint.pprint(client.get_config()) client.disconnect(send_close=True) return 0
def start_activity(args): """Connects to the Harmony and prints the current activity.""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) pprint.pprint(client.start_activity(args.activity_id)) client.disconnect(send_close=True) return 0
def repl(args): """Connects to the Harmony and start ipython with client""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) console = EmbeddedConsole(locals()) console.start() client.disconnect(send_close=True) return 0
def send_command_to_device(args): """Connects to the Harmony and prints the current activity.""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client(args.harmony_ip, args.harmony_port, token) pprint.pprint( client.send_button_press_to_device(args.command, args.device_id)) client.disconnect(send_close=True) return 0
def repl(args): """Connects to the Harmony and start ipython with client""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client(args.harmony_ip, args.harmony_port, token) console = EmbeddedConsole(locals()) console.start() client.disconnect(send_close=True) return 0
def get_client(harmony_ip, harmony_port, email, password): token = auth.login(email, password) if not token: sys.exit('Could not get token from Logitech server.') session_token = auth.swap_auth_token( harmony_ip, harmony_port, token) if not session_token: sys.exit('Could not swap login token for session token.') client = harmony_client.create_and_connect_client( harmony_ip, harmony_port, token) return client
def show_devices(args): """Connects to the Harmony and prints its configuration.""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) deviceListFile = open("d:\devices_list.txt", 'w') client.get_config() deviceListFile.write(client.get_config()) #deviceListFile.write(str(client.get_config())) deviceListFile.close() client.disconnect(send_close=True) return 0
def show_devices(args): """Connects to the Harmony and prints its configuration.""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client(args.harmony_ip, args.harmony_port, token) deviceListFile = open("d:\devices_list.txt", 'w') client.get_config() deviceListFile.write(client.get_config()) #deviceListFile.write(str(client.get_config())) deviceListFile.close() client.disconnect(send_close=True) return 0
def get_current_activity_name(args): """Get current activity and print its name""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) activities = client.get_config()['activity'] current_activity_id = client.get_current_activity() for t in activities: if int(t['id']) == int(current_activity_id): print t['label'] client.disconnect(send_close=True) return 0
def start_activity(args): """Connects to the Harmony and starts an activity""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) config = client.get_config() activities = config['activity'] labels_and_ids = dict([(a['label'], a['id']) for a in activities]) matching = [label for label in labels_and_ids.keys() if args.activity.lower() in label.lower()] if len(matching) == 1: activity = matching[0] print "Found activity named %s (id %s)" % (activity, labels_and_ids[activity]) client.start_activity(labels_and_ids[activity]) else: print "found too many! %s" % (" ".join(matching)) client.disconnect(send_close=True) return 0
def start_activity(args): """Connects to the Harmony and starts an activity""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client(args.harmony_ip, args.harmony_port, token) config = client.get_config() activities = config['activity'] labels_and_ids = dict([(a['label'], a['id']) for a in activities]) matching = [ label for label in labels_and_ids.keys() if args.activity.lower() in label.lower() ] if len(matching) == 1: activity = matching[0] print "Found activity named %s (id %s)" % (activity, labels_and_ids[activity]) client.start_activity(labels_and_ids[activity]) else: print "found too many! %s" % (" ".join(matching)) client.disconnect(send_close=True) return 0
def get_client(ip, session_token, port=5222): return harmony_client.create_and_connect_client( ip, port, session_token)
def get_client_obj(email, password, harmony_ip, harmony_port): token = login_to_logitech_site(email, password) client = harmony_client.create_and_connect_client(harmony_ip, harmony_port, token) return client
def get_client(args): """Connect to the Harmony and return a Client instance.""" token = login_to_logitech(args) client = harmony_client.create_and_connect_client( args.harmony_ip, args.harmony_port, token) return client
from harmony import auth from harmony import client username = "******" password = "******" ip = "10.0.0.0" port = "5222" token = auth.login(username, password) session_token = auth.swap_auth_token(ip, port, token) harmony_client = client.create_and_connect_client(ip, port, token) configuration = harmony_client.get_config() counter = 0 for activity in configuration['activity']: print "%i: %s" % (counter, activity['label']) counter += 1 selection = int(input("Activity: ")) selected_id = int(configuration['activity'][selection]['id']) harmony_client.start_activity(selected_id) harmony_client.disconnect(send_close=True)