Hub integration

Dear all,

i have a task to create a third party hub integration that will connect to a websocket of a third party application and create and maintain multiple devices, with each device having multiple entities. Each instance of this hub integration would connect to a specified host and maintain its own set of devices.
Reading the documentation and looking at github code, i’ve learned that hub integration should be the correct component type to use for this task, i’ve also decided that i would use aio websocket library for communication and use data push model for events.
Now i am wondering multiple things:

  • is it the correct approach to use hub integration component type?
  • where do i put the aio libraries, do i use my own instances, stored in my custom component folder?
  • will i be able to create areas, devices and their entities within code, based on the data i receive from websocket?
  • how do i resynchronize devices and/or entities for a device, if they change on the remote application or when home assistant restarts?

Thank you for any advise/pointers/input

Hi misterti,

There is a Developer category here you could move this to, and another one on the HA discord you could ask in.

The integration types are described here Integration manifest | Home Assistant Developer Docs and hub sounds like a match.

Not sure what you with where to put the aio libraries. If there are packages you depend on you include them in the manifest in the requirements section. Same page as linked above.

Typically you don’t use libraries like aiohttp directly, but you would write a package for communication with the hub and host it on PyPI. Then in the manifest put it in requirements.

You can create devices/entities from code. That is the main thing integrations do. I don’t think you are supposed to create areas directly, but you can provide a “suggested_area” when providing device_info Device registry | Home Assistant Developer Docs which effectively does the same.

In general I would make sure to start small and just build bit by bit.
You might want to look at some core integrations that have hubs for inspiration. For example Hue sounds similar, it has a hub/bridge where devices can be added/removed and updates get pushed to Home Assistant (with the v2 API).