From 6285c488bb3fd14f75aaafda06e0e212cfe9f845 Mon Sep 17 00:00:00 2001 From: Kristian Thaulow Date: Sat, 27 Apr 2024 19:04:38 +0000 Subject: [PATCH 1/2] Added debug mode to enable use of breakpoints when debugging. Added debug mode to launch configuration and moved configruation.yaml to be used by the homeassistant requirement. Modified develop script to be able to be used by the existing run task. --- .gitignore | 2 ++ .vscode/launch.json | 25 ++++++++++++++++++++ {.devcontainer => config}/configuration.yaml | 0 scripts/develop | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-) rename {.devcontainer => config}/configuration.yaml (100%) diff --git a/.gitignore b/.gitignore index dd11681..986ea99 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ venv .coverage .idea issues +config/* +!config/configuration.yaml diff --git a/.vscode/launch.json b/.vscode/launch.json index 00aba4f..2683996 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,6 +2,31 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "Home Assistant: Debug", + "type": "debugpy", + "request": "launch", + "module": "homeassistant", + "justMyCode": false, + "args": [ + "--debug", + "-c", + "config" + ] + }, + { + "name": "Home Assistant: Debug (skip pip)", + "type": "debugpy", + "request": "launch", + "module": "homeassistant", + "justMyCode": false, + "args": [ + "--debug", + "-c", + "config", + "--skip-pip" + ] + }, { // Example of attaching to local debug server "name": "Python: Attach Local", diff --git a/.devcontainer/configuration.yaml b/config/configuration.yaml similarity index 100% rename from .devcontainer/configuration.yaml rename to config/configuration.yaml diff --git a/scripts/develop b/scripts/develop index 6a3fc9a..a73840c 100755 --- a/scripts/develop +++ b/scripts/develop @@ -4,7 +4,7 @@ set -e cd "$(dirname "$0")/../.devcontainer" # Copy config and custom_components -cp configuration.yaml hass +cp ../config/configuration.yaml hass cp -r ../custom_components/ hass # Start Home Assistant From 1cc3c686a37b64c5b6267a08cebf9d604456b0b5 Mon Sep 17 00:00:00 2001 From: Kristian Thaulow Date: Sun, 28 Apr 2024 11:51:24 +0000 Subject: [PATCH 2/2] Moved "Run Task" hass directory to shared config directory location and updated develop script and documentatation --- .devcontainer/README.md | 6 +++--- .devcontainer/hass/.gitignore | 2 -- .vscode/launch.json | 2 +- scripts/develop | 19 ++++++++++++++----- 4 files changed, 18 insertions(+), 11 deletions(-) delete mode 100644 .devcontainer/hass/.gitignore diff --git a/.devcontainer/README.md b/.devcontainer/README.md index 129dfaa..75097b1 100644 --- a/.devcontainer/README.md +++ b/.devcontainer/README.md @@ -2,7 +2,7 @@ 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. -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. +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 `config/configuration.yaml` file. **Prerequisites** @@ -37,14 +37,14 @@ The available tasks are: Task | Description -- | -- -Run Home Assistant on port 8123 | Launch Home Assistant with your custom component code and the configuration defined in `.devcontainer/configuration.yaml`. +Run Home Assistant on port 8123 | Launch Home Assistant with your custom component code and the configuration defined in `config/configuration.yaml`. ### Step by Step debugging With the development container, you can test your custom component in Home Assistant with step by step debugging. -You need to modify the `configuration.yaml` file in `.devcontainer` folder +You need to modify the `configuration.yaml` file in `config` folder by uncommenting the line: ```yaml diff --git a/.devcontainer/hass/.gitignore b/.devcontainer/hass/.gitignore deleted file mode 100644 index c96a04f..0000000 --- a/.devcontainer/hass/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 2683996..a8eae12 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -38,7 +38,7 @@ "pathMappings": [ { "localRoot": "${workspaceFolder}", - "remoteRoot": "/workspaces/home-assistant-heru/.devcontainer/hass" + "remoteRoot": "." } ] }, diff --git a/scripts/develop b/scripts/develop index a73840c..d53d28b 100755 --- a/scripts/develop +++ b/scripts/develop @@ -1,11 +1,20 @@ #!/usr/bin/env bash set -e -cd "$(dirname "$0")/../.devcontainer" -# Copy config and custom_components -cp ../config/configuration.yaml hass -cp -r ../custom_components/ hass +cd "$(dirname "$0")/.." + +# Create config dir if not present +if [[ ! -d "${PWD}/config" ]]; then + mkdir -p "${PWD}/config" + hass --config "${PWD}/config" --script ensure_config +fi + +# Set the path to custom_components +## This let's us have the structure we want /custom_components/heru +## while at the same time have Home Assistant configuration inside /config +## without resulting to symlinks. +export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components" # Start Home Assistant -hass -c hass --debug \ No newline at end of file +hass --config "${PWD}/config" --debug \ No newline at end of file