Skip to content

Would you be open to an asyncio transport? #579

Description

@johnnyh1975

Title: Would you be open to an asyncio transport? (asking before writing anything)


@pschmitt
I maintain ha_roomba_plus, a Home Assistant integration built on roombapy, and separately wrote roombapy-prime for the newer cloud protocol. So I have spent a while inside both this library and the async equivalent.

I would like to ask before writing code rather than after: would you be open to roombapy growing an asyncio transport? If the answer is no, or not now, that is a completely fine answer and I will stop there.

What prompted it

My integration has 111 places that exist only to cross the thread boundary this library's paho loop creates:

72x  async_add_executor_job     every command out
27x  run_coroutine_threadsafe   every response back
12x  call_soon_threadsafe       callbacks from the paho thread

Each one is a rule that has to be remembered. Forget call_soon_threadsafe in a callback and you touch Home Assistant's event loop from the wrong thread — which fails intermittently and is miserable to reproduce. I have my own notes-to-self about this, which is how I know I have got it wrong before.

An exception raised inside a paho callback also disappears into the thread rather than surfacing at the call site.

What I think the change actually is

Smaller than it sounds, which is part of why I am asking:

  • remote_client.py (~180 lines) is the real work — paho's loop_start() becomes an aiomqtt client, or paho v2 bound to the running loop
  • roomba.py: connect / disconnect / send_command / set_preference become coroutines
  • The periodic_connection thread disappears rather than being ported — it only serves continuous=False, which Home Assistant never uses
  • The message handling stays exactly as it is. It is pure state logic with no I/O, and it is the part that has been stable for years. I would not touch it.

The part that is your call, not mine

roombapy is a Home Assistant core dependency. Anything I propose has to answer what happens to the core roomba integration — either the sync surface stays alongside the async one, or core migrates, and that is not a decision a contributor should make for you.

I can see a version where RoombaFactory gains an async variant and nothing existing changes, but you would know better whether that is worth the maintenance surface.

What I am offering

The work, if you want it, in whatever shape you would accept it — one PR or split up, sync surface preserved or not. I would rather build what you would merge than present something finished and awkward to decline.

And if the answer is that roombapy is fine as it is: also a good answer. It has been reliable for a long time, and "my integration would need less glue" is my problem before it is yours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions