Skip to content

Commit b03b542

Browse files
committed
improve devcontainer
1 parent b3c8177 commit b03b542

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
{
2-
"name": "dkarv-devcontainer",
2+
"name": "${localWorkspaceFolderBasename}-dev",
33
"build": {
44
"dockerfile": "../dev/Dockerfile"
55
},
66
"runArgs": [
77
"--name",
8-
"dkarv-devcontainer"
8+
"${localWorkspaceFolderBasename}-dev"
99
],
1010
"appPort": [
1111
8123
1212
],
13-
"postCreateCommand": "/workspaces/ha-lg-ess/dev/bootstrap.sh",
13+
"postCreateCommand": "dev/bootstrap.sh",
1414
"overrideCommand": false,
1515
"mounts": [
1616
"source=${localWorkspaceFolder}/dev/.config,target=/config,type=bind,consistency=cached",
1717
"source=${localWorkspaceFolder}/dev/configuration.yaml,target=/config/configuration.yaml,type=bind,consistency=cached",
1818
"source=${localWorkspaceFolder}/custom_components,target=/config/custom_components,type=bind,consistency=cached"
1919
],
20-
"features": {
21-
//"ghcr.io/devcontainers/features/python:1": "none"
22-
},
2320
"customizations": {
2421
"vscode": {
2522
"extensions": [

dev/bootstrap.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
#!/bin/bash
22

3-
pip install -r requirements.txt
3+
set -e
4+
45
# TODO find way to install dependencies from manifest.json directly
6+
# Create a local venv in the workspace and install requirements
7+
PYTHON="/usr/local/bin/python3.13"
8+
if [ ! -d "dev/.venv" ]; then
9+
$PYTHON -m venv dev/.venv
10+
fi
11+
. dev/.venv/bin/activate
12+
pip install --upgrade pip setuptools wheel
13+
pip install -r requirements.txt

dev/start.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,42 @@ trap 'echo "Received termination signal, stopping..."; stop_ha; exit 0' INT TERM
4444

4545
start_ha
4646

47-
inotifywait -m -r -e close_write,modify,create,delete --format '%w%f' "$WATCH_DIR" | while read -r file; do
47+
# Use a file descriptor reading from inotifywait so we can debounce properly.
48+
# Behavior: perform an immediate restart on the first event, then collect any
49+
# additional events that arrive within $DEBOUNCE seconds and perform one
50+
# additional restart if any were seen. This ensures we never miss updates but
51+
# do restarts at most every $DEBOUNCE seconds for a burst of changes.
52+
exec 3< <(inotifywait -m -r -e close_write,modify,create,delete --format '%w%f' "$WATCH_DIR")
53+
while IFS= read -r -u 3 file; do
4854
# ignore changes in Python bytecode caches
4955
case "$file" in
50-
*/__pycache__/*)
56+
*/__pycache__*)
5157
continue
5258
;;
5359
esac
5460
echo "Change detected: $file -- restarting Home Assistant"
5561
stop_ha
5662
start_ha
57-
sleep "$DEBOUNCE"
63+
64+
# Collect further events for up to $DEBOUNCE seconds. If we see any,
65+
# perform one additional restart after the quiet period.
66+
pending=0
67+
last_event="$file"
68+
while IFS= read -r -u 3 -t "$DEBOUNCE" next; do
69+
case "$next" in
70+
*/__pycache__*)
71+
continue
72+
;;
73+
esac
74+
echo "Queued change: $next"
75+
pending=1
76+
last_event="$next"
77+
done
78+
79+
if [ "$pending" -eq 1 ]; then
80+
echo "Processing pending change: $last_event -- restarting Home Assistant"
81+
stop_ha
82+
start_ha
83+
fi
5884
done
5985

0 commit comments

Comments
 (0)