It seems that to fulfil my need, and have something I can share with the world I need to write a proper integration. So, my question is, what are good practices and recommendation when developing one?
So far my HA installation does not handle anything critical, so I am kinda OK with testing on prod. However, I would like to avoid situations where I am making some typo, and everything - including HA - explodes.
Any tools or procedures to run before pulling the changes into HA? Any particular places to look? Any recommendations regarding writing tests for my integration?
To give you some reference point about my skills. I am comfortable with python. I can hack some dirty JavaScript, but not proud of the results. I am not a webdev person, but if you want to use webdev related labels, I am certainly backend person. So, for the frontend part I would appreciate more newbie-friendly approach.
I am creating a separate docker image with the language of my choice and exposing devices/entities via mqtt autodiscovery and controlling other entities via the rest api. Using the websocket api also works if you want your integration to react to changes of other entities.
This way I can use Swift, that I use for my day job, so I already know the best practices and how to write tests.
For the config I just use json5 (so people can keep the comments when they copy the sample config instead of having to make sure that the file has proper JSON syntax). Creating a simple html configuration page is also an option if you are into that.
I have a separate config for development where the names are suffixed with _test, so that the last release can run on my home server while the debug instance is connecting from my pc.
All my integrations start with this blueprint, everything is done inside a devcontainer (or codespace). I actually use GitHub codespaces for cloud based integrations.
However if I need something local (say a usb device) I’ll generally use the same devcontainer via docker on a local machine and modify the config for this.
I also have 3 instances of Home Assistant configured, dev, test and “prod”. Each release of my integrations go through each instance, it catches some bugs, but not everything.
Your integration should only contain code responsible for getting the data into Home Assistant one way or another. Any API connectivity logic, parsing etc should be contained to a separate python library. A long time ago I wondered why the core devs don’t allow library logic in a integration itself, however after trying to make sense of a number of other people’s custom integrations, I now understand why… Combining these two makes the whole thing unreadable in my view.
Use the dev docs https://developers.home-assistant.io/ and finally if you do get stuck, there is a development support channel in the HA Discord where you’ll find someone who can help.