Open Rafsisa opened 6 months ago
You don’t seem to know how asyncio works.
roomba.connect() and roomba.disconnect() are not async methods.
Sorry, I was a bit exhausted then...
I'm now using this wrapper class:
import asyncio
import roomba as wrapped
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
lruc = loop.run_until_complete
class Roomba980:
def __init__(self, *args, **kwargs):
self._roomba = wrapped.Roomba(*args, **kwargs)
def connect(self):
return lruc(self._connect_async())
def disconnect(self):
return self._roomba.disconnect()
def start(self):
lruc(self._command_async('start', 15))
def stop(self):
lruc(self._command_async('stop'))
def dock(self):
lruc(self._command_async('dock'))
@property
def phase(self):
return self._get_prop('phase')
@property
def current_state(self):
return self._get_prop('current_state')
@property
def sku(self):
return self._get_prop('sku')
async def _connect_async(self):
return await self._roomba.connect()
async def _command_async(self, cmd, sleep=5):
self._roomba.send_command(cmd)
await asyncio.sleep(sleep)
def _get_prop(self, name):
return self._roomba.get_property(name)
roomba = Roomba980('172.17.23.104')
roomba.connect()
print('connected')
roomba.start()
print('started')
roomba.stop()
print('stopped')
roomba.dock()
print('docked')
print('phase : %r'%roomba.phase)
print('current_state: %r'%roomba.current_state)
print('sku : %r'%roomba.sku)
roomba.disconnect()
print('disconnected')
The properties (phase, current_state and sku) are None when run without the start-stop-dock code. Is that the case with your Roomba too? Also sometimes the connection is lost after successfully stopping of the Roomba (printing 'Unexpected Disconnect! - reconnecting') and docking is omitted. In some cases, this still succeeds after the 'Unexpected Disconnect'. How can I handle or even fix that?
Besides that, since I'm running Python 3.12.3 I had to modify roomba.py:
diff --git a/roomba/roomba.py b/roomba/roomba.py
index 09da3bf..4a6c021 100755
--- a/roomba/roomba.py
+++ b/roomba/roomba.py
@@ -609,7 +609,7 @@ class Roomba(object):
async def _disconnect(self):
#if self.ws:
# await self.ws.cancel()
- tasks = [t for t in asyncio.Task.all_tasks() if t is not asyncio.Task.current_task()]
+ tasks = [t for t in asyncio.all_tasks(asyncio.get_event_loop()) if t is not asyncio.current_task()]
[task.cancel() for task in tasks]
self.log.info("Cancelling {} outstanding tasks".format(len(tasks)))
await asyncio.gather(*tasks, return_exceptions=True)
Thank you for maintainig this module!
Hi!
I'm working with the current script:
This indeed starts the Roomba 980 at 172.17.23.104, but that's the last thing that works. The vacuum never stops or docks as it should. The output of this script is as follows: