Merge branch 'Zenconomy-error-handling'
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
__pycache__
|
||||||
|
Pipfile.lock
|
||||||
+18
-14
@@ -141,7 +141,6 @@ class VacBot(ClientXMPP):
|
|||||||
self.ready_flag = Event()
|
self.ready_flag = Event()
|
||||||
self.clean_status = None
|
self.clean_status = None
|
||||||
self.charge_status = None
|
self.charge_status = None
|
||||||
self.battery_status = None
|
|
||||||
|
|
||||||
def wait_until_ready(self):
|
def wait_until_ready(self):
|
||||||
self.ready_flag.wait()
|
self.ready_flag.wait()
|
||||||
@@ -151,26 +150,26 @@ class VacBot(ClientXMPP):
|
|||||||
logging.debug("event = {}".format(event))
|
logging.debug("event = {}".format(event))
|
||||||
self.ready_flag.set()
|
self.ready_flag.set()
|
||||||
|
|
||||||
self.register_handler(Callback('clean report',
|
self.__register_callback("CleanReport", self.handle_clean_report)
|
||||||
MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}ctl[@td="CleanReport"]'),
|
self.__register_callback("ChargeState", self.handle_charge_report)
|
||||||
self.handle_clean_report))
|
self.__register_callback("BatteryInfo", self.handle_battery_report)
|
||||||
self.register_handler(Callback('charge state',
|
self.__register_callback("error", self.handle_error)
|
||||||
MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}ctl[@td="ChargeState"]'),
|
|
||||||
self.handle_charge_report))
|
def __register_callback(self, kind, function):
|
||||||
self.register_handler(Callback('battery info',
|
self.register_handler(Callback(kind,
|
||||||
MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}ctl[@td="BatteryInfo"]'),
|
MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}ctl[@td="' + kind + '"]'),
|
||||||
self.handle_battery_report))
|
function))
|
||||||
|
|
||||||
def handle_clean_report(self, iq):
|
def handle_clean_report(self, iq):
|
||||||
self.clean_status = iq.find('{com:ctl}query/{com:ctl}ctl/{com:ctl}clean').get('type')
|
self.clean_status = iq.find('{com:ctl}query/{com:ctl}ctl/{com:ctl}clean').get('type')
|
||||||
logging.debug("*** clean_status =" + self.clean_status)
|
logging.debug("*** clean_status = " + self.clean_status)
|
||||||
|
|
||||||
def handle_battery_report(self, iq):
|
def handle_battery_report(self, iq):
|
||||||
try:
|
try:
|
||||||
self.battery_status = float(iq.find('{com:ctl}query/{com:ctl}ctl/{com:ctl}battery').get('power')) / 100
|
battery_status = float(iq.find('{com:ctl}query/{com:ctl}ctl/{com:ctl}battery').get('power')) / 100
|
||||||
|
logging.debug("*** battery_status = {:.0%}".format(battery_status))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logging.warning("couldn't parse battery status " + ET.tostring(iq))
|
logging.warning("couldn't parse battery status " + ET.tostring(iq))
|
||||||
logging.debug("*** battery_status = {:.0%}".format(self.battery_status))
|
|
||||||
|
|
||||||
def handle_charge_report(self, iq):
|
def handle_charge_report(self, iq):
|
||||||
report = iq.find('{com:ctl}query/{com:ctl}ctl/{com:ctl}charge').get('type')
|
report = iq.find('{com:ctl}query/{com:ctl}ctl/{com:ctl}charge').get('type')
|
||||||
@@ -182,7 +181,12 @@ class VacBot(ClientXMPP):
|
|||||||
self.charge_status = 'idle'
|
self.charge_status = 'idle'
|
||||||
else:
|
else:
|
||||||
logging.warning("Unknown charging status '" + report + "'")
|
logging.warning("Unknown charging status '" + report + "'")
|
||||||
logging.debug("*** charge_status =" + self.charge_status)
|
logging.debug("*** charge_status = " + self.charge_status)
|
||||||
|
|
||||||
|
def handle_error(self, iq):
|
||||||
|
error = iq.find('{com:ctl}query/{com:ctl}ctl').get('error')
|
||||||
|
error_no = iq.find('{com:ctl}query/{com:ctl}ctl').get('errno')
|
||||||
|
logging.debug("*** error = " + error_no + " " + error)
|
||||||
|
|
||||||
def send_command(self, xml):
|
def send_command(self, xml):
|
||||||
c = self.wrap_command(xml)
|
c = self.wrap_command(xml)
|
||||||
|
|||||||
Reference in New Issue
Block a user