Run HAOS with custom python library (package)

Is it possible to run HAOS with a custom Python library package for testing purposes? For example, I want to test changes in the xknx library used in knx integration, which should fix HAOS related descriptor-limit issues that are not reproduced in other environments, but I have not found any way to do this except waiting for a new beta release.
There is declined PR #108997 that could help test such cases. Is there any other suggestions exist?

1 Like

Generally, that should be possible for sure, but I don’t have a lot of knowledge in that regard.
You could use a computer, setup a virtual environment, clone the repository, do some preparations, and then you can run it: hass -c config (see developer docs).
Alternatively, you could try to modify you existing HA installation. I’ve seen this some times to overcome problems in working installations (e.g., here). Be sure to have a good back up of all your data in case something goes wrong.

In case you want to dive deeper than just seeing if it works, the Remote Python Debugger integration could be helpful.

You can use the code of the integration as a custom_component and update the library it should use in the manifest.json.

Roughly the steps would be

  • Get the integration code from core/homeassistant/components/knx at dev · home-assistant/core · GitHub and put it in config/custom_components/knx
  • Edit the manifest.json
    • Add ,"version": "0.0.0" as the last line, just before the closing }, this is needed to make it load as a custom component. Be sure that it stays valid json!
    • Update "xknx==3.12.0" to the version you want to test

Restart Home Assistant and it should load the custom component version. You can check in the integrations screen to see if it has the custom integration icon.

Make sure to delete the custom component when you are done to use the built in version again.

I’m sure this works, but it requires the library maintainer to publish a release beforehand, wouldn’t it?

Yes, it is easiest if it is a published release, but it is also possible to specify a branch in a git repo.

From Integration manifest | Home Assistant Developer Docs

It is also possible to use a public git repository to install a requirement. This can be useful, for example, to test changes to a requirement dependency before it’s been published to PyPI. Syntax:

{  "requirements": ["<library>@git+https://github.com/<user>/<project>.git@<git ref>"]}

<git ref> can be any git reference: branch, tag, commit hash, … . See PIP documentation about git support.

The following example will install the except_connect branch of the pycoolmaster library directly from GitHub:

{  "requirements": ["pycoolmaster@git+https://github.com/issacg/pycoolmaster.git@except_connect"]}

I remember having issues this when trying this in the past myself, but it is documented, so it has to be an issue on my side back then.

1 Like