use xml changes from mqtt xml messages
seems applicable to xmpp and maybe never implemented here. some other changes I made that seem consistent with my n79. no clue if this messes up other xmpp robots but seems like it shouldnt, need to test
This commit is contained in:
@@ -946,78 +946,155 @@ class EcoVacsXMPP(ClientXMPP):
|
|||||||
self.ctl_subscribers.append(function)
|
self.ctl_subscribers.append(function)
|
||||||
|
|
||||||
def _handle_ctl(self, message):
|
def _handle_ctl(self, message):
|
||||||
the_good_part = message.get_payload()[0][0]
|
the_good_part = str(message.payload.decode("utf-8"))
|
||||||
|
# the_good_part = message.get_payload()[0][0]
|
||||||
|
# other_part = "{'ret': 'ok'}"
|
||||||
|
# try:
|
||||||
|
# other_part = message.get_payload()[0][0][0]
|
||||||
|
# _LOGGER.debug("Other payload found:")
|
||||||
|
# _LOGGER.debug(other_part)
|
||||||
|
# except IndexError:
|
||||||
|
# _LOGGER.debug("No extra payload")
|
||||||
as_dict = self._ctl_to_dict(the_good_part)
|
as_dict = self._ctl_to_dict(the_good_part)
|
||||||
|
_LOGGER.debug("handle ctl called with as_dict:")
|
||||||
|
_LOGGER.debug(as_dict)
|
||||||
if as_dict is not None:
|
if as_dict is not None:
|
||||||
for s in self.ctl_subscribers:
|
for s in self.ctl_subscribers:
|
||||||
s(as_dict)
|
s(as_dict)
|
||||||
|
|
||||||
if as_dict is None:
|
# if as_dict is None:
|
||||||
try:
|
# try:
|
||||||
other_part = message.get_payload()[0][0][0]
|
# other_part = message.get_payload()[0][0][0]
|
||||||
# _LOGGER.debug("handle_ctl called with get_payload()[0][0][0], the other part:")
|
# # _LOGGER.debug("handle_ctl called with get_payload()[0][0][0], the other part:")
|
||||||
#_LOGGER.debug(other_part)
|
# #_LOGGER.debug(other_part)
|
||||||
other_dict = self._ctl_to_dict(other_part)
|
# other_dict = self._ctl_to_dict(other_part)
|
||||||
#_LOGGER.debug("other dict in query:")
|
# #_LOGGER.debug("other dict in query:")
|
||||||
#_LOGGER.debug(other_dict)
|
# #_LOGGER.debug(other_dict)
|
||||||
if other_dict is not None:
|
# if other_dict is not None:
|
||||||
for s in self.ctl_subscribers:
|
# for s in self.ctl_subscribers:
|
||||||
s(other_dict)
|
# s(other_dict)
|
||||||
except IndexError:
|
# except IndexError:
|
||||||
_LOGGER.warning("No extra payload")
|
# _LOGGER.debug("No extra payload")
|
||||||
|
|
||||||
def _ctl_to_dict(self, xml):
|
def _ctl_to_dict(self, xml):
|
||||||
|
#Including changes from jasonarends @ 28da7c2 below
|
||||||
result = xml.attrib.copy()
|
result = xml.attrib.copy()
|
||||||
_LOGGER.debug("result from xml is :")
|
if 'td' not in result:
|
||||||
_LOGGER.debug(result)
|
# This happens for commands with no response data, such as PlaySound
|
||||||
_LOGGER.debug("end of result")
|
# Handle response data with no 'td'
|
||||||
|
|
||||||
if 'td' in result:
|
if 'type' in result: # single element with type and val
|
||||||
|
_LOGGER.debug("type detected in result, result before event handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
result['event'] = "life_span" # seems to always be LifeSpan type
|
||||||
|
_LOGGER.debug("result after event life_span handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
|
||||||
|
else:
|
||||||
|
if len(xml) > 0: # case where there is child element
|
||||||
|
if 'clean' in xml[0].tag:
|
||||||
|
_LOGGER.debug("clean detected in result, result before event handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
result['event'] = "clean_report"
|
||||||
|
_LOGGER.debug("result after event clean handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
elif 'charge' in xml[0].tag:
|
||||||
|
_LOGGER.debug("charge detected in result, result before event handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
result['event'] = "charge_state"
|
||||||
|
_LOGGER.debug("result after event charge handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
elif 'battery' in xml[0].tag:
|
||||||
|
_LOGGER.debug("battery detected in result, result before event handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
result['event'] = "battery_info"
|
||||||
|
_LOGGER.debug("result after event battery handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
result.update(xml[0].attrib)
|
||||||
|
_LOGGER.debug("result after xml update attrib:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
else: # for non-'type' result with no child element, e.g., result of PlaySound
|
||||||
|
return
|
||||||
|
else: # response includes 'td'
|
||||||
|
_LOGGER.debug("td detected in result, result before event handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
result['event'] = result.pop('td')
|
result['event'] = result.pop('td')
|
||||||
|
_LOGGER.debug("result after event td handling:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
if xml:
|
if xml:
|
||||||
result.update(xml[0].attrib)
|
result.update(xml[0].attrib)
|
||||||
|
_LOGGER.debug("IF XML sub-check result after xml update attrib:")
|
||||||
|
_LOGGER.debug(result)
|
||||||
|
|
||||||
for key in result:
|
for key in result:
|
||||||
if not RepresentsInt(result[key]): #Fix to handle negative int values
|
#Check for RepresentInt to handle negative int values, and ',' for ignoring position updates
|
||||||
result[key] = stringcase.snakecase(result[key])
|
if not RepresentsInt(result[key]) and ',' not in result[key]:
|
||||||
|
result[key] = stringcase.snakecase(result[key])
|
||||||
|
|
||||||
|
return result
|
||||||
|
#
|
||||||
|
# result = xml.attrib.copy()
|
||||||
|
# other_result = other_xml.attrib.copy()
|
||||||
|
# _LOGGER.debug("result from xml is :")
|
||||||
|
# _LOGGER.debug(result)
|
||||||
|
# _LOGGER.debug("end of result")
|
||||||
|
# _LOGGER.debug("other_result from xml is :")
|
||||||
|
# _LOGGER.debug(other_result)
|
||||||
|
# _LOGGER.debug("end of other_result")
|
||||||
|
# if 'td' in result:
|
||||||
|
# result['event'] = result.pop('td')
|
||||||
|
# if xml:
|
||||||
|
# result.update(xml[0].attrib)
|
||||||
|
|
||||||
|
# for key in result:
|
||||||
|
# if not RepresentsInt(result[key]): #Fix to handle negative int values
|
||||||
|
# result[key] = stringcase.snakecase(result[key])
|
||||||
# _LOGGER.debug("td detected in result and result is:")
|
# _LOGGER.debug("td detected in result and result is:")
|
||||||
# _LOGGER.debug(result)
|
# _LOGGER.debug(result)
|
||||||
# _LOGGER.debug("end of td detect result")
|
# _LOGGER.debug("end of td detect result")
|
||||||
|
# return result
|
||||||
|
|
||||||
return result
|
# elif 'type' in result:
|
||||||
|
|
||||||
elif 'type' in result:
|
|
||||||
# result['event'] = result.pop('type')
|
# result['event'] = result.pop('type')
|
||||||
if 'errno' in result:
|
# if 'errno' in result:
|
||||||
if result['errno'] == '':
|
# if result['errno'] == '':
|
||||||
result['errno'] = 'life_span'
|
# result['errno'] = 'life_span'
|
||||||
result['event'] = result.pop('errno')
|
# result['event'] = result.pop('errno')
|
||||||
if xml:
|
# if xml:
|
||||||
result.update(xml[0].attrib)
|
# result.update(xml[0].attrib)
|
||||||
else:
|
# else:
|
||||||
result['event'] = result.pop('type')
|
# result['event'] = result.pop('type')
|
||||||
if xml:
|
# if xml:
|
||||||
result.update(xml[0].attrib)
|
# result.update(xml[0].attrib)
|
||||||
|
|
||||||
for key in result:
|
|
||||||
if not RepresentsInt(result[key]): #Fix to handle negative int values
|
|
||||||
result[key] = stringcase.snakecase(result[key])
|
|
||||||
|
|
||||||
|
# for key in result:
|
||||||
|
# if not RepresentsInt(result[key]): #Fix to handle negative int values
|
||||||
|
# result[key] = stringcase.snakecase(result[key])
|
||||||
# _LOGGER.debug("type detected in result and result is:")
|
# _LOGGER.debug("type detected in result and result is:")
|
||||||
# _LOGGER.debug(result)
|
# _LOGGER.debug(result)
|
||||||
# _LOGGER.debug("end of type detect result")
|
# _LOGGER.debug("end of type detect result")
|
||||||
|
# return result
|
||||||
|
|
||||||
return result
|
# elif 'type' in other_result:
|
||||||
|
# if len(xmlchild) > 0:
|
||||||
|
# result = xmlchild[0].attrib.copy()
|
||||||
|
# #Fix for difference in XMPP vs API response
|
||||||
|
# #Depending on the report will use the tag and add "report" to fit the mold of sucks library
|
||||||
|
# if xmlchild[0].tag == "clean":
|
||||||
|
# result['event'] = "CleanReport"
|
||||||
|
# elif xmlchild[0].tag == "charge":
|
||||||
|
# result['event'] = "ChargeState"
|
||||||
|
# elif xmlchild[0].tag == "battery":
|
||||||
|
# result['event'] = "BatteryInfo"
|
||||||
|
|
||||||
else:
|
# else:
|
||||||
# This happens for commands with no response data, such as PlaySound
|
# # This happens for commands with no response data, such as PlaySound
|
||||||
_LOGGER.debug("neither type nor td in result:")
|
# _LOGGER.debug("neither type nor td in result:")
|
||||||
_LOGGER.debug(result)
|
# _LOGGER.debug(result)
|
||||||
_LOGGER.debug("end of no td or type detect result")
|
# _LOGGER.debug("end of no td or type detect result")
|
||||||
return
|
# return
|
||||||
|
|
||||||
def register_callback(self, userdata, message):
|
def register_callback(self, userdata, message):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user