Skip to content

Commit 8ae9978

Browse files
committed
chore: refactor code structure for improved readability and maintainability
1 parent b43e945 commit 8ae9978

93 files changed

Lines changed: 3533 additions & 1248 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.devcontainer/.bashrc‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Show MOTD only once per container session
2+
SESSION_MARKER="/tmp/.motd_shown_$(cat /proc/sys/kernel/random/boot_id 2>/dev/null || echo 'session')"
3+
4+
if [ ! -f "$SESSION_MARKER" ]; then
5+
# First terminal in this container session
6+
touch "$SESSION_MARKER"
7+
8+
# Find workspace directory
9+
WORKSPACE_DIR=""
10+
if [ -n "$VSCODE_GIT_IPC_HANDLE" ] || [ -n "$CODESPACES" ]; then
11+
# We're in VS Code/Codespaces - find workspace
12+
for dir in /workspaces/* /workspace; do
13+
if [ -d "$dir" ]; then
14+
WORKSPACE_DIR="$dir"
15+
break
16+
fi
17+
done
18+
fi
19+
20+
# Show MOTD if script exists
21+
if [ -n "$WORKSPACE_DIR" ] && [ -f "$WORKSPACE_DIR/.devcontainer/motd" ]; then
22+
"$WORKSPACE_DIR/.devcontainer/motd" 2>/dev/null || true
23+
fi
24+
fi
25+
26+
# Find workspace directory for aliases
27+
WORKSPACE_ROOT=""
28+
for dir in /workspaces/* /workspace; do
29+
if [ -d "$dir" ]; then
30+
WORKSPACE_ROOT="$dir"
31+
break
32+
fi
33+
done
34+
35+
# Home Assistant development aliases (work from anywhere!)
36+
if [ -n "$WORKSPACE_ROOT" ]; then
37+
alias ha-develop="$WORKSPACE_ROOT/script/develop"
38+
alias ha-test="$WORKSPACE_ROOT/script/test"
39+
alias ha-lint="$WORKSPACE_ROOT/script/lint"
40+
alias ha-lint-check="$WORKSPACE_ROOT/script/lint-check"
41+
alias ha-check="$WORKSPACE_ROOT/script/check"
42+
alias ha-clean="$WORKSPACE_ROOT/script/clean"
43+
alias ha-type-check="$WORKSPACE_ROOT/script/type-check"
44+
alias ha-help="$WORKSPACE_ROOT/script/help"
45+
46+
# Shorthand for common tasks
47+
alias ha-t="$WORKSPACE_ROOT/script/test"
48+
alias ha-l="$WORKSPACE_ROOT/script/lint"
49+
alias ha-d="$WORKSPACE_ROOT/script/develop"
50+
fi
51+
52+
# Change to workspace directory if we're in /home/vscode
53+
if [ "$PWD" = "$HOME" ] && [ -d "/workspaces" ]; then
54+
cd /workspaces/* 2>/dev/null || true
55+
fi

‎.devcontainer/.zshrc‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Show MOTD only once per container session
2+
SESSION_MARKER="/tmp/.motd_shown_$(cat /proc/sys/kernel/random/boot_id 2>/dev/null || echo 'session')"
3+
4+
if [ ! -f "$SESSION_MARKER" ]; then
5+
# First terminal in this container session
6+
touch "$SESSION_MARKER"
7+
8+
# Find workspace directory
9+
WORKSPACE_DIR=""
10+
if [ -n "$VSCODE_GIT_IPC_HANDLE" ] || [ -n "$CODESPACES" ]; then
11+
# We're in VS Code/Codespaces - find workspace
12+
for dir in /workspaces/* /workspace; do
13+
if [ -d "$dir" ]; then
14+
WORKSPACE_DIR="$dir"
15+
break
16+
fi
17+
done
18+
fi
19+
20+
# Show MOTD if script exists
21+
if [ -n "$WORKSPACE_DIR" ] && [ -f "$WORKSPACE_DIR/.devcontainer/motd" ]; then
22+
"$WORKSPACE_DIR/.devcontainer/motd" 2>/dev/null || true
23+
fi
24+
fi
25+
26+
# Find workspace directory for aliases
27+
WORKSPACE_ROOT=""
28+
for dir in /workspaces/* /workspace; do
29+
if [ -d "$dir" ]; then
30+
WORKSPACE_ROOT="$dir"
31+
break
32+
fi
33+
done
34+
35+
# Home Assistant development aliases (work from anywhere!)
36+
if [ -n "$WORKSPACE_ROOT" ]; then
37+
alias ha-develop="$WORKSPACE_ROOT/script/develop"
38+
alias ha-test="$WORKSPACE_ROOT/script/test"
39+
alias ha-lint="$WORKSPACE_ROOT/script/lint"
40+
alias ha-lint-check="$WORKSPACE_ROOT/script/lint-check"
41+
alias ha-check="$WORKSPACE_ROOT/script/check"
42+
alias ha-clean="$WORKSPACE_ROOT/script/clean"
43+
alias ha-type-check="$WORKSPACE_ROOT/script/type-check"
44+
alias ha-help="$WORKSPACE_ROOT/script/help"
45+
46+
# Shorthand for common tasks
47+
alias ha-t="$WORKSPACE_ROOT/script/test"
48+
alias ha-l="$WORKSPACE_ROOT/script/lint"
49+
alias ha-d="$WORKSPACE_ROOT/script/develop"
50+
fi
51+
52+
# Change to workspace directory if we're in /home/vscode
53+
if [ "$PWD" = "$HOME" ] && [ -d "/workspaces" ]; then
54+
cd /workspaces/* 2>/dev/null || true
55+
fi

‎.devcontainer/Dockerfile‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
11
FROM mcr.microsoft.com/devcontainers/python:dev-3.14-bookworm
22

3-
# Install uv (official binary via install script)
4-
RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
5-
&& mv /root/.local/bin/uv /usr/local/bin/uv \
6-
&& mv /root/.local/bin/uvx /usr/local/bin/uvx
7-
8-
RUN rm -f /etc/apt/sources.list.d/yarn.list \
9-
&& rm -f /usr/share/keyrings/yarn-archive-keyring.gpg
10-
113
RUN apt-get update
12-
RUN apt-get install -y --no-install-recommends \
13-
libudev-dev \
14-
libavformat-dev \
15-
libavcodec-dev \
16-
libavdevice-dev \
17-
libavutil-dev \
18-
libswscale-dev \
19-
libswresample-dev \
20-
libavfilter-dev \
21-
libpcap-dev \
22-
libturbojpeg0 \
23-
libyaml-dev \
24-
libxml2 \
25-
git \
26-
cmake
4+
RUN apt-get install -y autoconf automake libtool build-essential pkg-config
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"recommendations": [],
3+
"unwantedRecommendations": ["ms-python.pylint"]
4+
}

‎.devcontainer/devcontainer.json‎

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
21
{
3-
//"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
2+
"name": "HA ha_integration_domain Dev Container",
43
"build": {
5-
"dockerfile": "Dockerfile"
4+
"dockerfile": "Dockerfile",
5+
"context": "."
6+
},
7+
"postCreateCommand": "bash .devcontainer/setup-shell.sh && bash .devcontainer/setup-git.sh && script/setup/setup",
8+
"postAttachCommand": "bash .devcontainer/post-attach.sh",
9+
"containerEnv": {
10+
// Home Assistant version to install in the devcontainer.
11+
// Uncomment and set a specific version if needed (e.g., "2025.12.3").
12+
// If not set, defaults to version from hacs.json.
13+
// "HA_VERSION": "2025.12.3",
14+
// Install HACS in the Home Assistant installation
15+
"HA_INSTALL_HACS": "1",
16+
// Enable asyncio debug mode for easier debugging of async code
17+
"PYTHONASYNCIODEBUG": "1",
18+
// Ensure Python output is sent straight to terminal (e.g. for logging)
19+
"PYTHONUNBUFFERED": "1",
20+
// Prevent Python from writing .pyc files to disk
21+
"PYTHONDONTWRITEBYTECODE": "1",
22+
// Optionally update apt package lists after container creation
23+
"APT_UPDATE": "0"
624
},
7-
"name": "tapo integration development",
8-
"appPort": ["9123:8123"],
9-
"containerUser": "root",
10-
"postCreateCommand": "uv sync --group dev",
11-
"containerEnv": { "DEVCONTAINER": "1" },
12-
"capAdd": ["CAP_NET_RAW", "CAP_NET_BROADCAST", "CAP_NET_BIND_SERVICE"],
13-
"runArgs": ["--network=bridge"],
1425
"features": {
1526
"ghcr.io/devcontainers/features/node:1": {
1627
"version": "lts"
@@ -20,6 +31,13 @@
2031
"packages": ["ffmpeg", "libturbojpeg0", "libpcap-dev"]
2132
}
2233
},
34+
"forwardPorts": [8123],
35+
"portsAttributes": {
36+
"8123": {
37+
"label": "Home Assistant",
38+
"onAutoForward": "notify"
39+
}
40+
},
2341
"customizations": {
2442
"vscode": {
2543
"extensions": [
@@ -34,22 +52,43 @@
3452
"ms-vscode-remote.remote-containers",
3553
"redhat.vscode-yaml"
3654
],
55+
// Please keep this file in sync with settings in .vscode/settings.default.jsonc
3756
"settings": {
38-
"files.eol": "\n",
57+
"chat.promptFiles": true,
3958
"editor.tabSize": 4,
40-
"terminal.integrated.shell.linux": "/bin/bash",
41-
"python.defaultInterpreterPath": "${containerWorkspaceFolder}/.venv/bin/python",
42-
"python.analysis.autoSearchPaths": false,
43-
"python.linting.pylintEnabled": true,
44-
"python.linting.enabled": true,
4559
"editor.formatOnPaste": false,
4660
"editor.formatOnSave": true,
47-
"editor.formatOnType": true,
61+
"editor.formatOnType": false,
62+
"files.eol": "\n",
4863
"files.trimTrailingWhitespace": true,
49-
"python.testing.pytestArgs": ["tests", "--no-cov"],
50-
"python.testing.unittestEnabled": false,
51-
"python.testing.pytestEnabled": true,
52-
"python.testing.pytestPath": "${containerWorkspaceFolder}/.venv/bin/pytest",
64+
"files.associations": {
65+
"**/translations/*.json": "jsontranslation"
66+
},
67+
"markdown.validate.enabled": false,
68+
"markdown.validate.fileLinks.enabled": "ignore",
69+
"markdown.validate.fragmentLinks.enabled": "ignore",
70+
"python.analysis.autoImportCompletions": true,
71+
"python.analysis.diagnosticMode": "workspace",
72+
"python.defaultInterpreterPath": "/home/vscode/.local/ha-venv/bin/python",
73+
"python.linting.pylintEnabled": false,
74+
"python.terminal.activateEnvironment": true,
75+
"python.terminal.activateEnvInCurrentTerminal": true,
76+
"python.testing.pytestArgs": ["--no-cov"],
77+
"terminal.integrated.profiles.linux": {
78+
"zsh": {
79+
"path": "/usr/bin/zsh"
80+
}
81+
},
82+
"terminal.integrated.defaultProfile.linux": "zsh",
83+
"yaml.customTags": [
84+
"!secret scalar",
85+
"!include scalar",
86+
"!include_dir_list scalar",
87+
"!include_dir_merge_list scalar",
88+
"!include_dir_named scalar",
89+
"!include_dir_merge_named scalar",
90+
"!input scalar"
91+
],
5392
"[python]": {
5493
"editor.defaultFormatter": "charliermarsh.ruff",
5594
"editor.codeActionsOnSave": {
@@ -72,8 +111,32 @@
72111
"[jsontranslation]": {
73112
"editor.defaultFormatter": "esbenp.prettier-vscode",
74113
"editor.formatOnSave": false
75-
}
114+
},
115+
"json.schemas": [
116+
{
117+
"fileMatch": ["custom_components/*/manifest.json"],
118+
"url": "${containerWorkspaceFolder}/schemas/json/manifest_schema.json"
119+
},
120+
{
121+
"fileMatch": ["custom_components/*/translations/*.json"],
122+
"url": "${containerWorkspaceFolder}/schemas/json/translation_schema.json"
123+
},
124+
{
125+
"fileMatch": ["hacs.json"],
126+
"url": "${containerWorkspaceFolder}/schemas/json/hacs_schema.json"
127+
},
128+
{
129+
"fileMatch": ["custom_components/*/icons.json"],
130+
"url": "${containerWorkspaceFolder}/schemas/json/icons_schema.json"
131+
}
132+
]
76133
}
77134
}
78-
}
135+
},
136+
"mounts": [
137+
// Mount host gitconfig for local development (ignored in Codespaces)
138+
// In Codespaces, GitHub automatically configures Git with your account
139+
"source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig.host,type=bind,consistency=cached,readonly"
140+
],
141+
"remoteUser": "vscode"
79142
}

‎.devcontainer/motd‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# .devcontainer/motd: Display Message of the Day for development environment
4+
#
5+
# Displays welcome message with project info and available scripts.
6+
# Called automatically by shell configuration on first terminal.
7+
#
8+
# Usage:
9+
# ./script/motd
10+
#
11+
# Examples:
12+
# ./script/motd
13+
14+
set -euo pipefail
15+
16+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
17+
cd "$SCRIPT_DIR/.."
18+
19+
# shellcheck source=script/.lib/output.sh
20+
source "$SCRIPT_DIR/../script/.lib/output.sh"
21+
22+
REPO_NAME=$(basename "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null || basename "$(pwd)")
23+
24+
echo ""
25+
printf "%b Welcome to the %s development environment!%b\n" "$BOLD$BLUE$ROCKET" "$REPO_NAME" "$NC"
26+
echo ""
27+
printf "%b%b Project:%b %s\n" "$DIM" "$PACKAGE" "$NC" "$(pwd)"
28+
printf "%b%b Git branch:%b %s\n" "$DIM" "$ARROW" "$NC" "$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'Not a git repo')"
29+
printf "%b%b Python:%b %s\n" "$DIM" "$WRENCH" "$NC" "$(python3 --version 2>/dev/null || echo 'Not available')"
30+
echo ""
31+
32+
"$SCRIPT_DIR/../script/help"
33+
34+
echo ""
35+
printf "%b%b Tip:%b Run %bscript/develop%b to start Home Assistant with your custom integration.\n" "$CYAN" "$INFO" "$NC" "$BOLD" "$NC"
36+
printf " Access it at %bhttp://localhost:8123%b\n" "$CYAN" "$NC"
37+
echo ""

0 commit comments

Comments
 (0)