Events now flow to Vacbot as reasonably sane dicts.
This commit is contained in:
@@ -9,7 +9,52 @@ from sucks import *
|
||||
# the library's design and its multithreaded nature and lack of explicit testing support.
|
||||
|
||||
def test_wrap_command():
|
||||
x = EcoVacsXMPP('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12', 'na')
|
||||
x = make_ecovacs_xmpp()
|
||||
c = str(x._wrap_command(Clean(1).to_xml(), 'E0000000001234567890@126.ecorobot.net/atom'))
|
||||
assert_true(search(r'from="20170101abcdefabcdefa@ecouser.net/abcdef12"', c))
|
||||
assert_true(search(r'to="E0000000001234567890@126.ecorobot.net/atom"', c))
|
||||
|
||||
|
||||
def test_subscribe_to_ctls():
|
||||
response = None
|
||||
|
||||
def save_response(value):
|
||||
nonlocal response
|
||||
response = value
|
||||
|
||||
x = make_ecovacs_xmpp()
|
||||
|
||||
query = x.make_iq_query()
|
||||
query.set_payload(
|
||||
ET.fromstring('<query xmlns="com:ctl"><ctl td="CleanReport"> <clean type="auto" /> </ctl></query>'))
|
||||
|
||||
x.subscribe_to_ctls(save_response)
|
||||
x._handle_ctl(query)
|
||||
assert_dict_equal(response, {'event': 'clean_report', 'type': 'auto'})
|
||||
|
||||
|
||||
def test_xml_to_dict():
|
||||
x = make_ecovacs_xmpp()
|
||||
|
||||
assert_dict_equal(
|
||||
x._ctl_to_dict(make_ctl('<ctl td="CleanReport"> <clean type="auto" /> </ctl>')),
|
||||
{'event': 'clean_report', 'type': 'auto'})
|
||||
assert_dict_equal(
|
||||
x._ctl_to_dict(make_ctl('<ctl td="CleanReport"> <clean type="auto" speed="strong" /> </ctl>')),
|
||||
{'event': 'clean_report', 'type': 'auto', 'speed': 'strong'})
|
||||
|
||||
assert_dict_equal(
|
||||
x._ctl_to_dict(make_ctl('<ctl td="BatteryInfo"><battery power="095"/></ctl>')),
|
||||
{'event': 'battery_info', 'power': '095'})
|
||||
|
||||
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'})
|
||||
|
||||
|
||||
def make_ecovacs_xmpp():
|
||||
return EcoVacsXMPP('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12', 'na')
|
||||
|
||||
|
||||
def make_ctl(string):
|
||||
return ET.fromstring('<query xmlns="com:ctl">' + string + '</query>')[0]
|
||||
|
||||
+61
-5
@@ -3,16 +3,72 @@ from nose.tools import *
|
||||
from sucks import *
|
||||
|
||||
|
||||
|
||||
def test_handle_clean_report():
|
||||
v = a_vacbot()
|
||||
assert_equals(None, v.clean_status)
|
||||
|
||||
v._handle_ctl({'event': 'clean_report', 'type': 'auto', 'speed': 'strong'})
|
||||
assert_equals('auto', v.clean_status)
|
||||
|
||||
|
||||
def test_handle_charge_state():
|
||||
v = a_vacbot()
|
||||
assert_equals(None, v.clean_status)
|
||||
|
||||
v._handle_ctl({'event': 'charge_state', 'type': 'going'})
|
||||
assert_equals('returning', v.charge_status)
|
||||
|
||||
v._handle_ctl({'event': 'charge_state', 'type': 'slot_charging'})
|
||||
assert_equals('charging', v.charge_status)
|
||||
|
||||
v._handle_ctl({'event': 'charge_state', 'type': 'idle'})
|
||||
assert_equals('idle', v.charge_status)
|
||||
|
||||
|
||||
def test_handle_battery_info():
|
||||
v = a_vacbot()
|
||||
assert_equals(None, v.battery_status)
|
||||
|
||||
v._handle_ctl({'event': 'battery_info', 'power': '100'})
|
||||
assert_equals(1.0, v.battery_status)
|
||||
|
||||
v._handle_ctl({'event': 'battery_info', 'power': '095'})
|
||||
assert_equals(0.95, v.battery_status)
|
||||
|
||||
v._handle_ctl({'event': 'battery_info', 'power': '000'})
|
||||
assert_equals(0.0, v.battery_status)
|
||||
|
||||
|
||||
def test_handle_unknown_ctl():
|
||||
v = a_vacbot()
|
||||
v._handle_ctl({'event': 'weird_and_unknown_event', 'type': 'pretty_weird'})
|
||||
# as long as it doesn't blow up, that's fine
|
||||
|
||||
|
||||
# as-yet unhandled messages:
|
||||
#
|
||||
# <ctl td="LifeSpan" type="Brush" val="099" total="365"/>
|
||||
# <ctl td="LifeSpan" type="DustCaseHeap" val="098" total="365"/>
|
||||
# <ctl td="LifeSpan" type="SideBrush" val="098" total="365"/>
|
||||
# <ctl td="Sched2"/>
|
||||
# <ctl td="Sched2" id="30800321"/>
|
||||
#
|
||||
# plus errors!
|
||||
|
||||
def test_bot_address():
|
||||
v = vacbot_for_bot({"did": "E0000000001234567890", "class": "126", "nick": "bob"})
|
||||
assert_equals('E0000000001234567890@126.ecorobot.net/atom', v._vacuum_adress())
|
||||
v = a_vacbot(bot={"did": "E0000000001234567890", "class": "126", "nick": "bob"})
|
||||
assert_equals('E0000000001234567890@126.ecorobot.net/atom', v._vacuum_address())
|
||||
|
||||
|
||||
def test_model_variation():
|
||||
v = vacbot_for_bot({"did": "E0000000001234567890", "class": "141", "nick": "bob"})
|
||||
assert_equals('E0000000001234567890@141.ecorobot.net/atom', v._vacuum_adress())
|
||||
v = a_vacbot(bot={"did": "E0000000001234567890", "class": "141", "nick": "bob"})
|
||||
assert_equals('E0000000001234567890@141.ecorobot.net/atom', v._vacuum_address())
|
||||
|
||||
|
||||
def vacbot_for_bot(bot):
|
||||
|
||||
def a_vacbot(bot=None):
|
||||
if bot is None:
|
||||
bot = {"did": "E0000000001234567890", "class": "126", "nick": "bob"}
|
||||
return VacBot('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12',
|
||||
bot, 'na')
|
||||
|
||||
Reference in New Issue
Block a user