Skip to content

Commit

Permalink
Use debugpy hass integration in devcontainer (blakeblackshear#302)
Browse files Browse the repository at this point in the history
* Use debugpy hass integration in devcontainer

* Add specific_configuration.yaml

* Always display reconfigure logs

* Fix package and logs debugpy

* Fix debugger hanging to connect

* Detect when HA debugger is up from logs
  • Loading branch information
felipecrs authored Jul 9, 2022
1 parent 65f6d8d commit 5115a63
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 50 deletions.
22 changes: 11 additions & 11 deletions .devcontainer/config/configuration.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
---
default_config:

logger:
default: error
logs:
custom_components.frigate: debug
homeassistant.components.mqtt: error

downloader:
download_dir: www

homeassistant:
name: Home
latitude: 0
Expand All @@ -26,11 +17,20 @@ homeassistant:
0.0.0.0/0: 1141ee80e0a647c1a4687d0b7631a019
allow_bypass_login: true
- type: homeassistant
packages:
specific: !include specific_configuration.yaml

demo:
logger:
default: error
logs:
custom_components.frigate: debug
homeassistant.components.mqtt: error

downloader:
download_dir: www

panel_iframe:
frigate:
title: "Frigate"
url: "http://localhost:45000"
url: "http://localhost:5000"
icon: "mdi:cctv"
5 changes: 5 additions & 0 deletions .devcontainer/config/specific_configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
debugpy:

logger:
logs:
homeassistant.components.debugpy: warning
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
"http://frigate:5000/api/config/schema": "/frigate.yml"
},
"files.associations": {
"configuration.yaml": "home-assistant"
"**/config/*configuration.yaml": "home-assistant"
},
"vscode-home-assistant.hostUrl": "http://hass:8123",
"vscode-home-assistant.longLivedAccessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhOTZjZTdhYTg0YzU0ODcxYWZhNTJmYmU4OWFmMjg3OSIsImlhdCI6MTY1NDgwNzk2MiwiZXhwIjoxOTcwMTY3OTYyfQ.0JUxrtqWWj-FwkAujcQCc5aRq9sf5_uR_sCI2eWcmIE",
"[home-assistant]": {
"editor.defaultFormatter": "keesschollaart.vscode-home-assistant"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand Down
17 changes: 17 additions & 0 deletions .devcontainer/follow_ha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -euo pipefail

# This ensures the container is up and, it
# won't do anything if it is already up.
docker compose up --detach hass

# Use docker logs instead of docker compose logs because the latter
# never exits, even after container is stopped.
container_id=$(docker compose ps hass --quiet)

# Only get the logs since the last time the container was started, so
# that we don't confuse VS Code's problem matcher.
start_time=$(docker inspect --format '{{.State.StartedAt}}' "${container_id}")

exec docker logs --follow "${container_id}" --since "${start_time}"
25 changes: 0 additions & 25 deletions .devcontainer/home_assistant_run.sh

This file was deleted.

12 changes: 12 additions & 0 deletions .devcontainer/wait_port.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Taken from https://stackoverflow.com/a/48646792/12156188

set -euo pipefail

echo -n "Waiting for Home Assistant Debugger to launch on 5678" >&2

sleep 5
echo

echo "Home Assistant Debugger launched" >&2
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"justMyCode": true,
"preLaunchTask": "Fetch Home Assistant Logs",
"preLaunchTask": "Home Assistant",
// This ensures that the restart button works
"postDebugTask": "Restart Home Assistant"
}
Expand Down
27 changes: 19 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@
{
"label": "Restart Home Assistant",
"type": "shell",
"command": "docker compose restart hass && sleep 5",
"command": "docker compose restart hass",
"problemMatcher": [],
"isBackground": false,
"presentation": {
"reveal": "silent",
"close": true,
"reveal": "always",
"close": true
}
},
{
"label": "Reconfigure Home Assistant",
"type": "shell",
"command": "docker compose up --detach --force-recreate hass",
"problemMatcher": [],
"isBackground": false,
"presentation": {
"reveal": "always",
"close": true
}
},
{
"label": "Fetch Home Assistant Logs",
"label": "Home Assistant",
"type": "shell",
"command": "docker compose logs --follow --no-log-prefix hass",
"command": ".devcontainer/follow_ha.sh",
"problemMatcher": {
"pattern": [
{
Expand All @@ -27,13 +38,13 @@
],
"background": {
"activeOnStart": true,
"beginsPattern": "this line will never be found",
"endsPattern": "."
"beginsPattern": "^this line shall never match$",
"endsPattern": "Listening for remote debug connection on"
}
},
"isBackground": true,
"presentation": {
"reveal": "always",
"reveal": "always"
}
}
]
Expand Down
6 changes: 2 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ version: "3"

services:
dev:
build: .devcontainer
user: vscode
init: true
build: .devcontainer
env_file:
- .env
volumes:
Expand All @@ -14,14 +14,12 @@ services:
hass:
image: "homeassistant/home-assistant:${HA_VERSION:-stable}"
restart: unless-stopped
environment:
- PYTHON_DEBUG=true
volumes:
- /etc/localtime:/etc/localtime:ro
- .devcontainer/home_assistant_run.sh:/etc/services.d/home-assistant/run:ro
- .devcontainer/preconfig.sh:/etc/cont-init.d/preconfig.sh:ro
- .devcontainer/preconfig:/preconfig.d/01-integration:ro
- .devcontainer/config/configuration.yaml:/config/configuration.yaml:ro
- .devcontainer/config/specific_configuration.yaml:/config/specific_configuration.yaml:ro
- .devcontainer/config/www:/config/www
- ./custom_components:/config/custom_components:ro
frigate:
Expand Down

0 comments on commit 5115a63

Please sign in to comment.