|
| 1 | +# Testing EMHASS-Add-on |
| 2 | + |
| 3 | +To test EMHASS-Add-on integration, you will need a Home Assistant (with Supervisor) environment. |
| 4 | + |
| 5 | +The common Home Assistant options are: |
| 6 | + |
| 7 | +- Adding EMHASS-Add-on into a pre-existing Home Assistant environment. |
| 8 | +- Testing EMHASS-Add-on on a Home Assistant inside a vertual test environment _(Using VS-Code)_. |
| 9 | + |
| 10 | +See the following steps for both options. |
| 11 | + |
| 12 | +_The following examples are for testing the EMHASS-Add-on integration _(Docker wrapper of EMHASS for Home Assistant)_. To develop/test the EMHASS Packadge itself, check EMHASS [Develop page](https://emhass.readthedocs.io/en/latest/develop.html)_. |
| 13 | + |
| 14 | +_See [Test EMHASS-Add-On build](#Test-EMHASS-Add-On-build) for an example of testing Home Assistants Docker image build._ |
| 15 | + |
| 16 | +## Develop on VS-Code DevContainer with Home Assistant test environment |
| 17 | + |
| 18 | +Using VS-Code DevContainers, you can generate a Home Assistant test environment for the Add-on before release. We can pull a version of the EMHASS package (required with EMHASS-Add-on) from a Git repo/branch, or via pip. Alternately, we can specify different pre-built EMHASS-Add-On versions _(EMHASS-Add-On Docker images)_ from DockerHub. |
| 19 | + |
| 20 | +See the following steps: |
| 21 | + |
| 22 | +- DockerHub: |
| 23 | + - Edit the `version` line from from [`config.yml`](./emhass/config.yml) to pull different versions of EMHASS-Add-On via DockerHub |
| 24 | +- Git/pip: |
| 25 | + - Comment out `image: "davidusb/image-{arch}-emhass"` line from [`config.yml`](./emhass/config.yml). This will tell the addon to build from the local Dockerfile and not pull Image from DockerHub |
| 26 | + - Git |
| 27 | + - Change `build_version: addon` in [_build.yaml_](./emhass/build.yaml) to `build_version: addon-git`. _(This overrides the pip version of EMHASS specified via [requirements.txt](./emhass/requirements.txt))_ |
| 28 | + - To specify the Git repo and branch, change lines accordingly in [*build.yaml*](/emhass/build.yaml). |
| 29 | + - repo: `#build_repo: https://github.com/davidusb-geek/emhass.git #addon-git mode` |
| 30 | + - branch: `#build_branch: master #addon-git mode` |
| 31 | + |
| 32 | + - pip |
| 33 | + - Change `emhass` version in [requirements.txt](/emhass/requirements.txt) to pull EMHASS via pip version. |
| 34 | + - You may need to modify the other python packages to different versions to match |
| 35 | +- Finally |
| 36 | + - Run _(if not already)_ the VS-Code DevContainer _(Shortcut: `F1` > `Dev Containers: Rebuild and Reopen in Container`)_ - This requires DevContainers to be operational. See [visualstudio.com - Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers) for more info |
| 37 | + - Start VS-Code Task to start Home Assistant (`ctrl+shift+p`>`Tasks: Run Task`> `Start Home Assistant`) |
| 38 | + - Login to the generated HA Portal: `localhost:7123` |
| 39 | + - Navigate to Home Assistant: `Add-ons` > `ADD-ON STORE` |
| 40 | + - Install/Run and Test Add-on |
| 41 | + - For more infomation see Home Assistant's [local addon testing](https://developers.home-assistant.io/docs/add-ons/testing). |
| 42 | + |
| 43 | +_Note: If, on run, the emhass version looks off. Try: uninstalling Add-on, `check for updates` on Add-on Store page, and re-installing._ |
| 44 | + _If you have chosen Git, also try removing the `emhass` python package from requirements.txt ._ |
| 45 | + |
| 46 | +## Adding EMHASS-Add-on into pre-existing Home Assistant environment |
| 47 | + |
| 48 | +If you would like to test a version of EMHASS-Add-on inside a pre-existing Home Assistant (with Supervisor) environment, see the following steps: |
| 49 | + |
| 50 | +- With your preferred method of choice, clone the emhass-add-on repository to the addons folder |
| 51 | + - One method is to use the [`Home Assistant Add-on: SSH server`](https://github.com/home-assistant/addons/blob/master/ssh/DOCS.md) addon to add: |
| 52 | + - Install addon and click `OPEN WEB UI` |
| 53 | + - See [SSH Addon README](https://github.com/home-assistant/addons/blob/master/ssh/DOCS.md#installation) for install steps |
| 54 | + - Type commands: |
| 55 | + ```bash |
| 56 | + cd ~/addons/ |
| 57 | + git clone https://github.com/davidusb-geek/emhass-add-on |
| 58 | + ``` |
| 59 | +- With your preferred method of choice, indicate which EMHASS package to build with (`image`), or specify what built DockerHub version of EMHASS-Add-on (`version`) to use, in section of [`config.yml`](./emhass/config.yml) file: |
| 60 | + - Comment out the **image** line `image: "davidusb/image-{arch}-emhass"` if you wish to pull a EMHASS version from pip or Git repo/branch |
| 61 | + - ssh example: |
| 62 | + ```bash |
| 63 | + sed -i.bak '/image:/ s/./#&/' ~/addons/emhass-add-on/emhass/config.yml |
| 64 | + ``` |
| 65 | + - Change **version** if you would like to pull in an older version of EMHASS-Add-on _(pre built Docker image)_ from DockerHub (Default state) |
| 66 | + - ssh example: |
| 67 | + ```bash |
| 68 | + emhassVersion=0.6.5 |
| 69 | + sed -i.bak "s/version:.*/version: $emhassVersion/g" ~/addons/emhass-add-on/emhass/config.yml |
| 70 | + ``` |
| 71 | +- If you want EMHASS from **pip**: |
| 72 | + - To specify the EMHASS pip version, modify the `emhass` version number in [requirements.txt](/emhass/requirements.txt) |
| 73 | + - ssh example: |
| 74 | + ```bash |
| 75 | + emhassVersion=0.7.7 |
| 76 | + sed -i.bak "s/emhass==.*/emhass==$emhassVersion/g" ~/addons/emhass-add-on/emhass/requirements.txt |
| 77 | + ``` |
| 78 | + |
| 79 | +- If you want EMHASS from **Git**: |
| 80 | + - Tell the Add-on to use Git, and specify what EMHASS repo and branch you would like to pull. |
| 81 | + |
| 82 | + - To tell Docker to pull from Git, change the build argument from `addon` to `addon-git` in the [_build.yaml_](./emhass/build.yaml). |
| 83 | + - ssh example: |
| 84 | + ```bash |
| 85 | + sed -i.bak "s/build_version:.*/build_version: addon-git/g" ~/addons/emhass-add-on/emhass/build.yaml |
| 86 | + ``` |
| 87 | + - To specify the EMHASS Git repository and branch values, _(optional)_ change lines in [*build.yaml*](/emhass/build.yaml): |
| 88 | + - `#build_repo: https://github.com/davidusb-geek/emhass.git #addon-git mode` |
| 89 | + - `#build_branch: master #addon-git mode` _ |
| 90 | + |
| 91 | + - ssh example: |
| 92 | + |
| 93 | + ```bash |
| 94 | + repo=https://github.com/daviasdasdsasddusb-geek/emhass.git |
| 95 | + branch=masaddasdasdter |
| 96 | +
|
| 97 | + sed -i.bak "s%build_repo:\s.*%build_repo: $repo%g" ~/addons/emhass-add-on/emhass/build.yaml |
| 98 | + sed -i.bak "s/build_branch:\s.*/build_repo: $branch/g" ~/addons/emhass-add-on/emhass/build.yaml |
| 99 | + ``` |
| 100 | +- Finally: |
| 101 | + - head to Home Assistant: `Add-ons` > `ADD-ON STORE` |
| 102 | + - you should see an `EMHASS` Add-on under `Local add-ons` |
| 103 | + - If you don't, try hamburger button _(3 dots)_ on top right > check updates > refresh page |
| 104 | + - Install and test Add-on |
| 105 | + - Use the Supervisor logs _(on the config/logs page)_ to see any logs with the Add-on. |
| 106 | +
|
| 107 | +</br> |
| 108 | +
|
| 109 | +_Note: If, on run, the emhass version looks off. Try: uninstalling Add-on, check for updates on Add-on Store page, and re-installing._ |
| 110 | + _If you have chosen Git, also try removing the emhass python package from requirements.txt ._ |
| 111 | +
|
| 112 | +## Test EMHASS-Add-On build |
| 113 | +
|
| 114 | +You can test the EMHASS-Add-On docker image build using the Home Assistant builder. |
| 115 | +
|
| 116 | +**emhass-add-on local repo** |
| 117 | +
|
| 118 | +Linux example: |
| 119 | +
|
| 120 | +```bash |
| 121 | +architecture=amd64 #your host machine architecture |
| 122 | +
|
| 123 | +docker run --rm --privileged -v ~/.docker:/root/.docker -v ${PWD}:/data ghcr.io/home-assistant/${architecture}-builder:latest --test --${architecture} --target /data/emhass |
| 124 | +``` |
| 125 | +
|
| 126 | +_confirm terminal directory is in root `emhass-add-on` folder_ |
| 127 | +
|
| 128 | +**emhass-add-on Git repo** |
| 129 | +
|
| 130 | +Linux example: |
| 131 | +
|
| 132 | +```bash |
| 133 | +architecture=amd64 #your host machine architecture |
| 134 | +
|
| 135 | +repo=https://github.com/davidusb-geek/emhass-add-on.git #repo example |
| 136 | +branch=main #branch example |
| 137 | +
|
| 138 | +docker run --rm --privileged -v ~/.docker:/root/.docker ghcr.io/home-assistant/${architecture}-builder:latest --test --${architecture} --target emhass -r ${repo} -b ${branch} |
| 139 | +``` |
0 commit comments