This is a recommended approach by Home Assistant, but feels a bit buggy at the moment.
- Install
ms-vscode-remote.remote-containers
VSCode plugin. - Restart VSCode and click
Reopen in Container
on bottom right. - Wait few moments to finish the setup and open the command palette, search for
Tasks: Run Task
and selectRun the mock API server
. This will start the mock go-e REST API. - Open the command palette again, search for
Tasks: Run Task
and selectRun Home Assistant on port 9123
. This will start the Home Assistant with the custom component on port9123
. - Open the http://127.0.0.1:9123 in a browser.
- Create an account. This feels quite buggy at the moment and you have to refresh the browser several times.
- You should see bunch of auto-created cards on the dashboard.
If you change the code, you'll have to restart the task Run Home Assistant on port 9123
by running Tasks: Restart Running Task
from the command palette.
Known issues:
/bin/bash: line 1: container: command not found
- try to rebuild the container[59923 ms] postCreateCommand failed with exit code 2. Skipping any further user-provided commands.
- same as above, try to rebuild the container- there are issues with zeroconf installation which leads to some subsequent errors - this is probably caused by the fact that the
ghcr.io/ludeeus/devcontainer/integration:stable
image is just too old
If you have issues running VSCode devcontainer
, there is a script to achieve live reloads of the custom component in the running Docker container.
Run:
./start-dev.sh
# by default the script uses podman, but you can use also other container engines, for example:
./start-dev.sh docker "docker compose"
# or
./start-dev.sh docker docker-compose
After few minutes, Home Assistant should be running and script should be in the watch mode. Whenever you change a file in the custom_components/smartenergy_goecharger
folder, it will restart the Home Assistant within a few seconds. Thus, you have a quick development feedback.
- Open the http://127.0.0.1:8123 in a browser.
- Create an account.
- You should see bunch of auto-created cards on the dashboard.
- Continue with the chapter Working with virtual env and below to test all the dev capabilities.
In case you want to try HACS locally, run:
./start-local.sh
- Open the http://127.0.0.1:8123 in a browser.
- Create an account - make sure that timezone is set correctly, otherwise it will fail to connect to the Github.
- Go to Settings -> Integrations and click on the
ADD INTEGRATION
. - Search for
HACS
and go through the process. - In the left menu you should have HACS icon, click it.
- Click on
Integrations
-> click 3 dots top right corner -> clickCustom repositories
. - In the dialog window, add
https://github.com/openkfw/smartenergy.goecharger
as a repository and selectIntegration
as a category. - Click
ADD
, wait for spinner to finish and close the dialog. - Click
EXPLORE & DOWNLOAD REPOSITORIES
-> search forgo-e
-> select thego-e Charger Cloud
-> wait and clickDOWNLOAD
. - Go to Settings -> System -> click
RESTART
and wait few seconds. - Go to Settings -> Devices & Services. Click the
ADD INTEGRATION
button. - Search for
go-e Charger Cloud
-> click -> fill in details -> clickSUBMIT
.
Example config:
Make sure that there is no trailing slash in the API host, otherwise the validation fails. When pressing submit, validation will also check the connectivity and fails if not able to connect and authenticate.
- Go to the dashboard screen, you should see bunch of sensors for the go-e Charger Cloud integration.
It is highly recommended to work from within a virtual environment as especially dependencies can mess up quite easily.
Create:
python3 -m venv env
Activate:
source env/bin/activate
Deactivate:
deactivate
python3 -m pip install -r requirements.txt
pre-commit install -t pre-push
In case you need to refresh your virtual environment, you can uninstall everything and the install again from scratch:
pip freeze | xargs pip uninstall -y
Linting is done via Pylint.
python3 -m pylint tests/**/*.py custom_components/**/*.py mock_api/**/*.py
Formatting is done via Black.
black custom_components/smartenergy_goecharger
# sort imports
isort --profile black custom_components
To have autoformatting in the VSCode, install the extension ms-python.black-formatter
.
Unit testing is done via Pytest.
python3 -m pytest
# show logs
python3 -m pytest -o log_cli=true
# code coverage
python3 -m pytest --durations=10 --cov-report term-missing --cov=custom_components.smartenergy_goecharger tests
Note: In case you have issues with bcrypt circular import, run this:
python3 -m pip uninstall bcrypt -y && python3 -m pip install bcrypt