Skip to content
Stijn Spijker edited this page Aug 1, 2024 · 1 revision

Working on this Home Assistant integration

All help is welcome, so if you want to do some work on ha-button-plus, here's some info to get you started.

Make sure Python 3 is installed, at time of writing, Python 3.12 or high. You can check the requires-python value in the core/pyproject.toml in the homeassistant/core repository. The best way to install python is with a tool that manages different Python installs on your machine, most people use pyenv, you can find the pyenv project here.

Make sure you install pytest, packaging, homeassistant with pip (Pythons package installer, it should come with Python). You can install hatch if you want to test packaging, but you normally don't need it.

Testing

You can find tests in the /tests directory, check them out, they're pretty easy to write and makes sure our code doesn't break in the future!

Running tests is simple, just execute pytest in the root of the repository.

Running the integration / monkey testing

Sometimes it's really convenient to be able to test the integration in a live Home Assistant instance. There are two ways to do this. You can add your own fork + commits to HACS and use your updated version in your live Home Assistant install. The second way is a bit more involved but entirely possible.

Testing and running locally with Docker

You can also run a Mosquitto broker and Home Assistant virtually on your PC. You can do this by installing Docker, and making sure it's running. Then run docker compose up in the root of the repository. This will start a Mosquitto broker on your local machine, and a Home Assistant instance. You can access Home Assistant by opening up http://localhost:8123/ after all containers are running.

For convenience there is a docker_compose.sh in the repo, which was made on a Mac (so it might not run right on other platforms!). It will automatically start docker images, setup logging levels to info for Home Assistant and debug for ha-button-plus and open up the browser. It will then attach to the Home Assistant container so you can see the logging scroll by.

To detach just press CTRL+C once, Docker will stop the containers gracefully and remove all traces. Giving you a clean start every time.