Skip to content

Commit

Permalink
Merge pull request #37 from KThaulow/thaulow/debug-mode-update
Browse files Browse the repository at this point in the history
Added debug mode to enable use of breakpoints when debugging
  • Loading branch information
toringer authored Apr 29, 2024
2 parents 092660e + 1cc3c68 commit 76b4594
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions .devcontainer/hass/.gitignore

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ venv
.coverage
.idea
issues
config/*
!config/configuration.yaml
27 changes: 26 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -13,7 +38,7 @@
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/workspaces/home-assistant-heru/.devcontainer/hass"
"remoteRoot": "."
}
]
},
Expand Down
File renamed without changes.
19 changes: 14 additions & 5 deletions scripts/develop
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#!/usr/bin/env bash

set -e
cd "$(dirname "$0")/../.devcontainer"

# Copy config and custom_components
cp 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 <root>/custom_components/heru
## while at the same time have Home Assistant configuration inside <root>/config
## without resulting to symlinks.
export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components"

# Start Home Assistant
hass -c hass --debug
hass --config "${PWD}/config" --debug

0 comments on commit 76b4594

Please sign in to comment.