|
| 1 | +## Developing with Visual Studio Code + devcontainer |
| 2 | + |
| 3 | +The easiest way to get started with custom integration development is to use Visual Studio Code with devcontainers. This approach will create a preconfigured development environment with all the tools you need. |
| 4 | + |
| 5 | +In the container you will have a dedicated Home Assistant core instance running with your custom component code. You can configure this instance by updating the `./devcontainer/configuration.yaml` file. |
| 6 | + |
| 7 | +**Prerequisites** |
| 8 | + |
| 9 | +- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) |
| 10 | +- Docker |
| 11 | + - For Linux, macOS, or Windows 10 Pro/Enterprise/Education use the [current release version of Docker](https://docs.docker.com/install/) |
| 12 | + - Windows 10 Home requires [WSL 2](https://docs.microsoft.com/windows/wsl/wsl2-install) and the current Edge version of Docker Desktop (see instructions [here](https://docs.docker.com/docker-for-windows/wsl-tech-preview/)). This can also be used for Windows Pro/Enterprise/Education. |
| 13 | +- [Visual Studio code](https://code.visualstudio.com/) |
| 14 | +- [Remote - Containers (VSC Extension)][extension-link] |
| 15 | + |
| 16 | +[More info about requirements and devcontainer in general](https://code.visualstudio.com/docs/remote/containers#_getting-started) |
| 17 | + |
| 18 | +[extension-link]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers |
| 19 | + |
| 20 | +**Getting started:** |
| 21 | + |
| 22 | +1. Fork the repository. |
| 23 | +2. Clone the repository to your computer. |
| 24 | +3. Open the repository using Visual Studio code. |
| 25 | + |
| 26 | +When you open this repository with Visual Studio code you are asked to "Reopen in Container", this will start the build of the container. |
| 27 | + |
| 28 | +_If you don't see this notification, open the command palette and select `Remote-Containers: Reopen Folder in Container`._ |
| 29 | + |
| 30 | +### Tasks |
| 31 | + |
| 32 | +The devcontainer comes with some useful tasks to help you with development, you can start these tasks by opening the command palette and select `Tasks: Run Task` then select the task you want to run. |
| 33 | + |
| 34 | +When a task is currently running (like `Run Home Assistant on port 9123` for the docs), it can be restarted by opening the command palette and selecting `Tasks: Restart Running Task`, then select the task you want to restart. |
| 35 | + |
| 36 | +The available tasks are: |
| 37 | + |
| 38 | +Task | Description |
| 39 | +-- | -- |
| 40 | +Run Home Assistant on port 9123 | Launch Home Assistant with your custom component code and the configuration defined in `.devcontainer/configuration.yaml`. |
| 41 | +Run Home Assistant configuration against /config | Check the configuration. |
| 42 | +Upgrade Home Assistant to latest dev | Upgrade the Home Assistant core version in the container to the latest version of the `dev` branch. |
| 43 | +Install a specific version of Home Assistant | Install a specific version of Home Assistant core in the container. |
| 44 | + |
| 45 | +### Step by Step debugging |
| 46 | + |
| 47 | +With the development container, |
| 48 | +you can test your custom component in Home Assistant with step by step debugging. |
| 49 | + |
| 50 | +You need to modify the `configuration.yaml` file in `.devcontainer` folder |
| 51 | +by uncommenting the line: |
| 52 | + |
| 53 | +```yaml |
| 54 | +# debugpy: |
| 55 | +``` |
| 56 | + |
| 57 | +Then launch the task `Run Home Assistant on port 9123`, and launch the debbuger |
| 58 | +with the existing debugging configuration `Python: Attach Local`. |
| 59 | + |
| 60 | +For more information, look at [the Remote Python Debugger integration documentation](https://www.home-assistant.io/integrations/debugpy/). |
0 commit comments