registerups.py: remove unneeded code

and add connection exception handling
This commit is contained in:
Sergey Morozov 2019-08-26 13:17:55 +03:00
parent 9317eb30b9
commit c2750889e1
1 changed files with 7 additions and 6 deletions

View File

@ -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
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)