Providing some updated steps for June 2024 ![]()
Mostly the same but a few hints to help get others started. With the introduction of uv the process has become much quicker - but make sure you remember to use uv pip install and not pip install within the dev environment now
If you are working on a HACS component, or require external libraries then you should start with pulling those components down to your file system somewhere. Note where as you will need to input below.
To get the DEV container working the simplest way to get thing is to follow steps 1-5 from: Set up development environment | Home Assistant Developer Docs
Once the container is build open devcontainer.json and replace
"postCreateCommand": "script/setup",
with
"postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && script/setup",
You then want to add a mounts section to the json. Where doesnt matter, as long as it is at the top level of the json. You do not require all the configurations below, delete the ones you dont need. ${localEnv:HOME} should be your home directory C:\Users\%UserName% but you can also manually enter any path on your file system
"mounts": [
// Custom configuration directory
"source=${localEnv:HOME}/path/to/config,target=${containerWorkspaceFolder}/config,type=bind",
// Custom component
"source=${localEnv:HOME}/path/to/custom_repo/custom_components/component_name,target=${containerWorkspaceFolder}/config/custom_components/component_name,type=bind",
//Custom library
"source=${localEnv:HOME}/path/to/custom_repo/custom_libraries/library_name,target=${containerWorkspaceFolder}/config/custom_libraries/library_name,type=bind",
],
Rebuild the container
If you dont rebuild none of the above will make any difference.
Once rebuilt you should now be able to see the libraries within your VSCode session in the path you defined under mounts
The next thing that is common is utilising custom libraries. I get this working by adding tasks to the tasks.json located within the .vscode directory
You might also get some info here on how to target remote libraries, but i prefer to map locally Integration manifest | Home Assistant Developer Docs
I use variations of the below and run this Task instead of Run Home Assistant Core
{
"label": "Run Home Assistant Core (custom)",
"type": "shell",
"command": "uv pip uninstall <libraryname> && uv pip install -e ./config/custom_libraries/<libraryname> && hass -c ./config",
"group": "test",
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [],
"dependsOn": ["Compile English translations"]
},