Possibly adding support for other models.

This commit is contained in:
William Pietri
2017-12-03 08:56:53 -08:00
parent fbf4916a8b
commit a66888d05e
2 changed files with 25 additions and 8 deletions
+3 -3
View File
@@ -190,7 +190,7 @@ class VacBot(ClientXMPP):
c.send() c.send()
def wrap_command(self, ctl): 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) ifrom=self.user + '@' + self.domain + '/' + self.resource)
q['type'] = 'set' q['type'] = 'set'
for child in q.xml: for child in q.xml:
@@ -396,8 +396,8 @@ def run(actions, charge, debug):
if actions: if actions:
config = read_config() config = read_config()
api = EcoVacsAPI(config['device_id'], config['email'], config['password_hash']) api = EcoVacsAPI(config['device_id'], config['email'], config['password_hash'])
vacuum_id = api.devices()[0]['did'] vacuum = api.devices()[0]
vacbot = VacBot(api.uid, api.REALM, api.resource, api.user_access_token, vacuum_id) vacbot = VacBot(api.uid, api.REALM, api.resource, api.user_access_token, vacuum)
vacbot.connect_and_wait_until_ready() vacbot.connect_and_wait_until_ready()
for action in actions: for action in actions:
+22 -5
View File
@@ -75,6 +75,21 @@ def test_should_run():
assert_almost_equal(count, 9000, delta=200) 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(): def test_main_api_called():
with requests_mock.mock() as m: with requests_mock.mock() as m:
r1 = m.get(re.compile('user/login'), r1 = m.get(re.compile('user/login'),
@@ -92,22 +107,24 @@ def test_main_api_called():
def test_device_lookup(): def test_device_lookup():
api = make_api() api = make_api()
with requests_mock.mock() as m: with requests_mock.mock() as m:
device_id = 'E0000693817603910264' device_id = 'E0000001234567890123'
r = m.post(re.compile('user.do'), r = m.post(re.compile('user.do'),
text='{"todo": "result", "devices": [{"did": "%s", "class": "126", "nick": "bob"}], "result": "ok"}' % device_id) text='{"todo": "result", "devices": [{"did": "%s", "class": "126", "nick": "bob"}], "result": "ok"}' % device_id)
d = api.devices() d = api.devices()
assert_equals(r.call_count, 1) assert_equals(r.call_count, 1)
assert_equals(len(d), 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(): def make_api():
with requests_mock.mock() as m: with requests_mock.mock() as m:
m.get(re.compile('user/login'), 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'), 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'), 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") return EcoVacsAPI("long_device_id", "account_id", "password_hash")