diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..e2991f2 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,76 @@ +{ + "name": "Home Assistant Dev", + "context": "..", + "dockerFile": "../Dockerfile.dev", + "postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && script/setup", + "postStawsrtCommand": "script/bootstrap", + "containerEnv": { + "PYTHONASYNCIODEBUG": "1" + }, + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {} + }, + // Port 5683 udp is used by Shelly integration + "appPort": ["8123:8123", "5683:5683/udp"], + "runArgs": [ + "-e", + "GIT_EDITOR=code --wait", + "--security-opt", + "label=disable" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-python.black-formatter", + "charliermarsh.ruff", + "ms-python.pylint", + "ms-python.vscode-pylance", + "redhat.vscode-yaml", + "esbenp.prettier-vscode", + "GitHub.vscode-pull-request-github", + "GitHub.copilot" + ], + // Please keep this file in sync with settings in home-assistant/.vscode/settings.default.jsonc + "settings": { + "python.experiments.optOutFrom": ["pythonTestAdapter"], + "python.defaultInterpreterPath": "/home/vscode/.local/ha-venv/bin/python", + "python.pythonPath": "/home/vscode/.local/ha-venv/bin/python", + "python.terminal.activateEnvInCurrentTerminal": true, + "python.testing.pytestArgs": ["--no-cov"], + "pylint.importStrategy": "fromEnvironment", + // Pyright type checking is not compatible with mypy which Home Assistant uses for type checking + "python.analysis.typeCheckingMode": "off", + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "files.trimTrailingWhitespace": true, + "terminal.integrated.profiles.linux": { + "zsh": { + "path": "/usr/bin/zsh" + } + }, + "terminal.integrated.defaultProfile.linux": "zsh", + "yaml.customTags": [ + "!input scalar", + "!secret scalar", + "!include_dir_named scalar", + "!include_dir_list scalar", + "!include_dir_merge_list scalar", + "!include_dir_merge_named scalar" + ], + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff" + }, + "[json][jsonc][yaml]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "json.schemas": [ + { + "fileMatch": ["homeassistant/components/*/manifest.json"], + "url": "${containerWorkspaceFolder}/script/json_schemas/manifest_schema.json" + } + ] + } + } + } +} diff --git a/.gitignore b/.gitignore index 10d9a66..c25dcb5 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ + + +config \ No newline at end of file diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..f3d529a --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.14 diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..221d726 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,17 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Run Home Assistant Core", + "type": "shell", + "command": "${command:python.interpreterPath} -m homeassistant -c ./config", + "group": "test", + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [], + "dependsOn": ["Compile English translations"] + } + ] +} diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..1b39c46 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,58 @@ +FROM mcr.microsoft.com/vscode/devcontainers/base:debian + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN \ + apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + # Additional library needed by some tests and accordingly by VScode Tests Discovery + bluez \ + ffmpeg \ + libudev-dev \ + libavformat-dev \ + libavcodec-dev \ + libavdevice-dev \ + libavutil-dev \ + libswscale-dev \ + libswresample-dev \ + libavfilter-dev \ + libpcap-dev \ + libturbojpeg0 \ + libyaml-dev \ + libxml2 \ + git \ + cmake \ + autoconf \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Add go2rtc binary +COPY --from=ghcr.io/alexxit/go2rtc:latest /usr/local/bin/go2rtc /bin/go2rtc + +WORKDIR /usr/src + +COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv + +USER vscode + +ENV VIRTUAL_ENV="/home/vscode/.local/ha-venv" +RUN --mount=type=bind,source=.python-version,target=.python-version \ + uv python install \ + && uv venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# Setup hass-release +RUN git clone --depth 1 https://github.com/home-assistant/hass-release ~/hass-release \ + && uv pip install -e ~/hass-release/ + +# Install Python dependencies from requirements +RUN --mount=type=bind,source=requirements.txt,target=requirements.txt \ + uv pip install -r requirements.txt + +# Claude Code native install +RUN curl -fsSL https://claude.ai/install.sh | bash + +WORKDIR /workspaces + +# Set the default shell to bash instead of sh +ENV SHELL=/bin/bash diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2d3debe --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +# Home Assistant Core +colorlog>=6.8.2 +homeassistant==2026.1.3 +pip>=21.3.1 +ruff>=0.0.261 +pre-commit>=3.0.0 +flake8>=6.1.0 +isort>=5.12.0 +black>=24.3.0 +xmltodict>=0.13.0 +charset_normalizer>=3.2.0 +pycountry>=23.12.11 \ No newline at end of file diff --git a/script/bootstrap b/script/bootstrap new file mode 100644 index 0000000..9f78fdb --- /dev/null +++ b/script/bootstrap @@ -0,0 +1,14 @@ +#!/bin/sh +# Resolve all dependencies that the application requires to run. + +# Stop on errors +set -e + +cd "$(realpath "$(dirname "$0")/..")" + +echo "Installing development dependencies..." +uv pip install \ + -e . \ + -r requirements.txt \ + --upgrade \ + --config-settings editable_mode=compat diff --git a/script/setup b/script/setup new file mode 100644 index 0000000..37e76cf --- /dev/null +++ b/script/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Setups the repository. + +# Stop on errors +set -e + +cd "$(dirname "$0")/.." + +mkdir -p config + +if [ ! -n "$VIRTUAL_ENV" ]; then + if [ -x "$(command -v uv)" ]; then + uv venv .venv + else + python3 -m venv .venv + fi + source .venv/bin/activate +fi + +if ! [ -x "$(command -v uv)" ]; then + python3 -m pip install uv +fi + +hass --script ensure_config -c config + +if ! grep -R "logger" config/configuration.yaml >> /dev/null; then +echo " +logger: + default: info + logs: + homeassistant.components.cloud: debug +" >> config/configuration.yaml +fi