registerups.py: remove unneeded code
and add connection exception handling
This commit is contained in:
		
							parent
							
								
									9317eb30b9
								
							
						
					
					
						commit
						c2750889e1
					
				@ -18,10 +18,7 @@ class cps_ups:
 | 
			
		||||
        for i in ET.fromstring(self.connection.getresponse().read()).iter("data"):
 | 
			
		||||
            keepalive_data=i.attrib
 | 
			
		||||
        self.connection.close()
 | 
			
		||||
        result = {'boot': keepalive_data['boot'],
 | 
			
		||||
                  'upt': keepalive_data['upt'],
 | 
			
		||||
                  'id': keepalive_data['id']}
 | 
			
		||||
        return(result)
 | 
			
		||||
        return(keepalive_data)
 | 
			
		||||
    def __genxml__(self, keepalive_data):
 | 
			
		||||
        data_tag = '<data ver="1.1"'\
 | 
			
		||||
            'hash="hmac-md5-128" '\
 | 
			
		||||
@ -63,8 +60,12 @@ class cps_ups:
 | 
			
		||||
        self.contact = contact
 | 
			
		||||
        self.location = location
 | 
			
		||||
        self.bedt = bedt
 | 
			
		||||
        post_data = self.__genxml__(self.__get_keepalive_data__())
 | 
			
		||||
        self.connection.request("POST", "/setup.xml", body = post_data)
 | 
			
		||||
        try:
 | 
			
		||||
            post_data = self.__genxml__(self.__get_keepalive_data__())
 | 
			
		||||
            self.connection.request("POST", "/setup.xml", body = post_data)
 | 
			
		||||
        except (OSError, ConnectionError) as err:
 | 
			
		||||
            print('Unable to register: ' + str(err))
 | 
			
		||||
            sys.exit(3)
 | 
			
		||||
        response = self.connection.getresponse().read()
 | 
			
		||||
        self.connection.close()
 | 
			
		||||
        return(response)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user