Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

Fix status #57 #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions sucks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,29 @@ def _ctl_to_dict(self, xml):
result = xml.attrib.copy()
if 'td' not in result:
# This happens for commands with no response data, such as PlaySound
return

result['event'] = result.pop('td')
if xml:
result.update(xml[0].attrib)
# Handle response data with no 'td'

if 'type' in result: # single element with type and val
result['event'] = "LifeSpan" # seems to always be LifeSpan type
# don't need to update attrib since there's no child

else: # non-'type' result with child element that has attribs
if len(xml) > 0: # case where there is child element
if 'clean' in xml[0].tag:
result['event'] = "CleanReport"
elif 'charge' in xml[0].tag:
result['event'] = "ChargeState"
elif 'battery' in xml[0].tag:
result['event'] = "BatteryInfo"
else:
return
result.update(xml[0].attrib)
else: # for non-'type' result with no child element, e.g., result of PlaySound
return
else: # response includes 'td'
result['event'] = result.pop('td')
if xml:
result.update(xml[0].attrib)

for key in result:
result[key] = stringcase.snakecase(result[key])
Expand Down
15 changes: 15 additions & 0 deletions tests/test_ecovacs_xmpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,22 @@ def test_xml_to_dict():
assert_dict_equal(
x._ctl_to_dict(make_ctl('# <ctl td="LifeSpan" type="Brush" val="099" total="365"/>')),
{'event': 'life_span', 'type': 'brush', 'val': '099', 'total': '365'})
# set of xml responses without the td attrib
assert_dict_equal(
x._ctl_to_dict(make_ctl('<ctl type="DustCaseHeap" val="050" total="365"/>')),
{'event': 'life_span', 'type': 'dust_case_heap', 'val': '050', 'total': '365'})

assert_dict_equal(
x._ctl_to_dict(make_ctl('<ctl ret="ok" errno=""><battery power="099"/></ctl>')),
{'event': 'battery_info', 'power': '099', 'ret': 'ok', 'errno': ''})

assert_dict_equal(
x._ctl_to_dict(make_ctl('<ctl ret="ok" errno=""><clean type="stop" speed="strong" st="h" t="" a=""/></ctl>')),
{'event': 'clean_report', 'type': 'stop', 'speed': 'strong', 'st':'h', 't': '', 'a': '', 'ret':'ok', 'errno': ''})

assert_dict_equal(
x._ctl_to_dict(make_ctl('<ctl ret="ok" errno=""><charge type="SlotCharging"/></ctl>')),
{'event': 'charge_state', 'type': 'slot_charging', 'ret': 'ok', 'errno': ''})

def make_ecovacs_xmpp():
return EcoVacsXMPP('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12', 'na')
Expand Down