Extracting duplication.

This commit is contained in:
William Pietri
2017-12-05 15:11:37 -08:00
parent edaf288b8b
commit 7daa4c837f
+9 -6
View File
@@ -195,9 +195,7 @@ class VacBot(ClientXMPP):
c.send() c.send()
def wrap_command(self, ctl): def wrap_command(self, ctl):
q = self.make_iq_query(xmlns=u'com:ctl', q = self.make_iq_query(xmlns=u'com:ctl', ito=self.__vacuum_adress(), ifrom=self.__my_address())
ito=self.vacuum['did'] + '@' + self.vacuum['class'] + '.ecorobot.net/atom',
ifrom=self.user + '@' + self.domain + '/' + self.resource)
q['type'] = 'set' q['type'] = 'set'
for child in q.xml: for child in q.xml:
if child.tag.endswith('query'): if child.tag.endswith('query'):
@@ -205,12 +203,17 @@ class VacBot(ClientXMPP):
return q return q
def send_ping(self): def send_ping(self):
q = self.make_iq_get(ito=self.vacuum['did'] + '@' + self.vacuum['class'] + '.ecorobot.net/atom', q = self.make_iq_get(ito=self.__vacuum_adress(), ifrom=self.__my_address())
ifrom=self.user + '@' + self.domain + '/' + self.resource) q.xml.append(ET.Element('ping', {'xmlns': 'urn:xmpp:ping'}))
logging.debug("*** sending ping ***") logging.debug("*** sending ping ***")
q.xml.append(ET.Element('ping', {'xmlns':'urn:xmpp:ping'}))
q.send() q.send()
def __my_address(self):
return self.user + '@' + self.domain + '/' + self.resource
def __vacuum_adress(self):
return self.vacuum['did'] + '@' + self.vacuum['class'] + '.ecorobot.net/atom'
def connect_and_wait_until_ready(self): def connect_and_wait_until_ready(self):
self.connect(('msg-{}.ecouser.net'.format(self.continent), '5223')) self.connect(('msg-{}.ecouser.net'.format(self.continent), '5223'))
self.process() self.process()