def login_to_logitech(args): """Logs in to the Logitech service. Args: args: argparse arguments needed to login. Returns: Session token that can be used to log in to the Harmony device. """ file = open('harmonyLogin.txt', 'r') email = file.readline().strip() #print email #print args.email password = file.readline().strip() #print password #print args.password print "Create token" #token = auth.login(args.email, args.password) token = auth.login(email, password) if not token: sys.exit('Could not get token from Logitech server.') print "Create session token" session_token = auth.swap_auth_token( args.harmony_ip, args.harmony_port, token) if not session_token: sys.exit('Could not swap login token for session token.') return session_token
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 login_to_logitech_site(email, password, harmony_ip, harmony_port): 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.') return session_token
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 login_to_logitech(args): """Logs in to the Logitech service. Args: args: argparse arguments needed to login. Returns: Session token that can be used to log in to the Harmony device. """ token = auth.login(args.email, args.password) if not token: sys.exit('Could not get token from Logitech server.') session_token = auth.swap_auth_token(args.harmony_ip, args.harmony_port, token) if not session_token: sys.exit('Could not swap login token for session token.') return session_token
def _create_connection(self): try: with timeout(15, exception=RuntimeError): self._token = login(self._user, self._password) self._conn = HarmonyClient(self._token) print "he" +str(self._ip) + ":" + str(self._port) self._conn.connect(address=(self._ip, self._port), use_tls=False, use_ssl=False) print 'adf' self._conn.process(block=False) while not self._conn.sessionstarted: time.sleep(0.1) except RuntimeError: self._logger.error("Harmony: Connection error") raise RuntimeError return False return True
def _create_connection(self): try: with timeout(15, exception=RuntimeError): self._token = login(self._user, self._password) self._conn = HarmonyClient(self._token) print "he" + str(self._ip) + ":" + str(self._port) self._conn.connect(address=(self._ip, self._port), use_tls=False, use_ssl=False) print 'adf' self._conn.process(block=False) while not self._conn.sessionstarted: time.sleep(0.1) except RuntimeError: self._logger.error("Harmony: Connection error") raise RuntimeError return False return True
def __init__(self, plugin, device): self.plugin = plugin self.deviceId = device.id self.activityList = dict() self.harmony_ip = device.pluginProps['address'] self.harmony_port = 5222 self.ready = False try: self.auth_token = auth.login(device.pluginProps['harmonyLogin'], device.pluginProps['harmonyPassword']) if not self.auth_token: self.plugin.debugLog(device.name + u': Could not get token from Logitech server.') self.client = auth.SwapAuthToken(self.auth_token) if not self.client.connect(address=(self.harmony_ip, self.harmony_port), reattempt=False, use_tls=False, use_ssl=False): raise Exception("connect failure on SwapAuthToken") self.client.process(block=False) while not self.client.uuid: self.plugin.debugLog(device.name + u": Waiting for client.uuid") time.sleep(0.5) self.session_token = self.client.uuid if not self.session_token: self.plugin.debugLog(device.name + u': Could not swap login token for session token.') self.client = harmony_client.HarmonyClient(self.session_token) self.client.registerHandler(Callback('Hub Message Handler', MatchMessage(''), self.messageHandler)) if not self.client.connect(address=(self.harmony_ip, self.harmony_port), reattempt=False, use_tls=False, use_ssl=False): raise Exception("connect failure on HarmonyClient") self.client.process(block=False) while not self.client.sessionstarted: self.plugin.debugLog(device.name + u": Waiting for client.sessionstarted") time.sleep(0.5) self.ready = True except Exception as e: self.plugin.debugLog(device.name + u": Error setting up hub connection: " + str(e)) return try: self.config = self.client.get_config() except Exception as e: self.plugin.debugLog(device.name + u": Error in client.get_config: " + str(e)) try: self.current_activity_id = str(self.client.get_current_activity()) except sleekxmpp.exceptions.IqTimeout: self.plugin.debugLog(device.name + u": Time out in client.get_current_activity") self.current_activity_id = "0" except sleekxmpp.exceptions.IqError: self.plugin.debugLog(device.name + u": IqError in client.get_current_activity") self.current_activity_id = "0" except Exception as e: self.plugin.debugLog(device.name + u": Error in client.get_current_activity: " + str(e)) self.current_activity_id = "0" for activity in self.config["activity"]: if activity["id"] == "-1": if '-1' == self.current_activity_id: device.updateStateOnServer(key="currentActivityNum", value=activity[u'id']) device.updateStateOnServer(key="currentActivityName", value=activity[u'label']) else: try: action = json.loads(activity["controlGroup"][0]["function"][0]["action"]) soundDev = action["deviceId"] self.activityList[activity[u'id']] = {'label': activity[u'label'], 'type': activity[u'type'], 'soundDev': soundDev } except Exception as e: # Not all Activities have sound devices... self.activityList[activity[u'id']] = {'label': activity[u'label'], 'type': activity[u'type'] } if activity[u'id'] == self.current_activity_id: device.updateStateOnServer(key="currentActivityNum", value=activity[u'id']) device.updateStateOnServer(key="currentActivityName", value=activity[u'label']) self.plugin.debugLog(device.name + u": Activity: %s (%s)" % (activity[u'label'], activity[u'id'])) self.plugin.debugLog(device.name + u": current_activity_id = " + self.current_activity_id)
result = iq.send(block=True) payload = result.get_payload() self.disconnect(send_close=False) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Test script for pyharmony.') parser.add_argument('username', help=('Logitech username. Should be in the ' 'form of an email address.')) parser.add_argument('password', help='Logitech password.') args = parser.parse_args() logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s') token = auth.login(args.username, args.password) if not token: sys.exit('Could not get token from Logitech server.') plugin_config = {} # Enables PLAIN authentication which is off by default. plugin_config['feature_mechanisms'] = {'unencrypted_plain': True} xmpp = auth.SwapAuthToken(token, '*****@*****.**', 'guest', plugin_config=plugin_config) xmpp.connect(address=('192.168.1.115', 5222)) xmpp.process(block=True) xmpp = SendMsgBot('*****@*****.**' % xmpp.uuid, xmpp.uuid, plugin_config=plugin_config) xmpp.connect(address=('192.168.1.115', 5222))
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)