Possibly adding support for other models.
This commit is contained in:
@@ -190,7 +190,7 @@ class VacBot(ClientXMPP):
|
||||
c.send()
|
||||
|
||||
def wrap_command(self, ctl):
|
||||
q = self.make_iq_query(xmlns=u'com:ctl', ito=self.vacuum + '@126.ecorobot.net/atom',
|
||||
q = self.make_iq_query(xmlns=u'com:ctl', ito=self.vacuum['did'] + '@' + self.vacuum['class'] + '.ecorobot.net/atom',
|
||||
ifrom=self.user + '@' + self.domain + '/' + self.resource)
|
||||
q['type'] = 'set'
|
||||
for child in q.xml:
|
||||
@@ -396,8 +396,8 @@ def run(actions, charge, debug):
|
||||
if actions:
|
||||
config = read_config()
|
||||
api = EcoVacsAPI(config['device_id'], config['email'], config['password_hash'])
|
||||
vacuum_id = api.devices()[0]['did']
|
||||
vacbot = VacBot(api.uid, api.REALM, api.resource, api.user_access_token, vacuum_id)
|
||||
vacuum = api.devices()[0]
|
||||
vacbot = VacBot(api.uid, api.REALM, api.resource, api.user_access_token, vacuum)
|
||||
vacbot.connect_and_wait_until_ready()
|
||||
|
||||
for action in actions:
|
||||
|
||||
+22
-5
@@ -75,6 +75,21 @@ def test_should_run():
|
||||
assert_almost_equal(count, 9000, delta=200)
|
||||
|
||||
|
||||
def test_wrap_command():
|
||||
v = VacBot('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12',
|
||||
{"did": "E0000000001234567890", "class": "126", "nick": "bob"})
|
||||
c = str(v.wrap_command(Clean(1).to_xml()))
|
||||
assert_true(re.search(r'from="20170101abcdefabcdefa@ecouser.net/abcdef12"', c))
|
||||
assert_true(re.search(r'to="E0000000001234567890@126.ecorobot.net/atom"', c))
|
||||
|
||||
|
||||
def test_model_variation():
|
||||
v = VacBot('20170101abcdefabcdefa', 'ecouser.net', 'abcdef12', 'A1b2C3d4efghijklmNOPQrstuvwxyz12',
|
||||
{"did": "E0000000001234567890", "class": "141", "nick": "bob"})
|
||||
c = str(v.wrap_command(Clean(1).to_xml()))
|
||||
assert_true(re.search(r'to="E0000000001234567890@141.ecorobot.net/atom"', c))
|
||||
b
|
||||
|
||||
def test_main_api_called():
|
||||
with requests_mock.mock() as m:
|
||||
r1 = m.get(re.compile('user/login'),
|
||||
@@ -92,22 +107,24 @@ def test_main_api_called():
|
||||
def test_device_lookup():
|
||||
api = make_api()
|
||||
with requests_mock.mock() as m:
|
||||
device_id = 'E0000693817603910264'
|
||||
device_id = 'E0000001234567890123'
|
||||
|
||||
r = m.post(re.compile('user.do'),
|
||||
text='{"todo": "result", "devices": [{"did": "%s", "class": "126", "nick": "bob"}], "result": "ok"}' % device_id)
|
||||
d = api.devices()
|
||||
assert_equals(r.call_count, 1)
|
||||
assert_equals(len(d), 1)
|
||||
assert_equals(d[0]['did'], device_id)
|
||||
vacuum = d[0]
|
||||
assert_equals(vacuum['did'], device_id)
|
||||
assert_equals(vacuum['class'], '126')
|
||||
|
||||
|
||||
def make_api():
|
||||
with requests_mock.mock() as m:
|
||||
m.get(re.compile('user/login'),
|
||||
text='{"time": 1511200804243, "data": {"accessToken": "7a375650b0b1efd780029284479c4e41", "uid": "2017102559f0ee63c588d", "username": null, "email": "william-ecovacs@pota.to", "country": "us"}, "code": "0000", "msg": "X"}')
|
||||
text='{"time": 1511200804243, "data": {"accessToken": "0123456789abcdef0123456789abcdef", "uid": "20170101abcdefabcdefa", "username": null, "email": "username@example.com", "country": "us"}, "code": "0000", "msg": "X"}')
|
||||
m.get(re.compile('user/getAuthCode'),
|
||||
text='{"time": 1511200804607, "data": {"authCode": "5c28dac1ff580210e11292df57e87bef"}, "code": "0000", "msg": "X"}')
|
||||
text='{"time": 1511200804607, "data": {"authCode": "abcdef01234567890abcdef012345678"}, "code": "0000", "msg": "X"}')
|
||||
m.post(re.compile('user.do'),
|
||||
text='{"todo": "result", "token": "jt5O7oDR3gPHdVKCeb8Czx8xw8mDXM6s", "result": "ok", "userId": "2017102559f0ee63c588d", "resource": "f8d99c4d"}')
|
||||
text='{"todo": "result", "token": "base64base64base64base64base64ba", "result": "ok", "userId": "20170101abcdefabcdefa", "resource": "abcdef12"}')
|
||||
return EcoVacsAPI("long_device_id", "account_id", "password_hash")
|
||||
|
||||
Reference in New Issue
Block a user