Test against current Home Assistant on Python 3.14, add shared CI and security scans #1

Merged
tim merged 8 commits from chore/maintenance-2026-10 into main 2026-10-12 12:05:23 +00:00
Owner

Maintenance run. Eight commits.

Findings

  • The suite was not testing current Home Assistant. pyproject.toml pinned homeassistant==2025.12.4 and pytest==9.0.0, which conflict with the current test plugin (pytest-homeassistant-custom-component 0.13.372 pins homeassistant==2026.10.1, pytest==9.0.3, pytest-asyncio==1.4.0). The resolver was held on an old plugin, so tests ran against HA 2025.12.
  • With the pins removed, all 203 tests errored at setup until asyncio_mode = "auto" was set (the plugin's async autouse fixtures are only handled in auto mode).
  • After that: 203 passed on Python 3.14.8 with Home Assistant 2026.10.1.
  • requirements_dev.txt was a second dev dependency list with 2024-era floors, referenced only in the docs.
  • The new security scan found something (bandit B608, medium): the InfluxQL statistics query was one f-string. See the last commit.

Commits

  1. chore: ruff pre-commit hook v0.17.0 (hook id ruff-check).
  2. build: drop the HA and pytest pins (the plugin pins them), requires-python >=3.14, .tool-versions 3.14, tool floors, asyncio_mode = "auto", remove requirements_dev.txt.
  3. docs: Python 3.14+, install via pip install -e .[dev].
  4. style: ruff 0.17 formats Python code blocks in Markdown (DESIGN.md).
  5. ci: .forgejo/workflows/ci.yml and security.yml on the shared workflow-basics actions.
  6. build: raises the minimum Home Assistant to 2026.10.0 (manifest.json, hacs.json, README) and targets Python 3.14 in ruff. Only the latest HA is run, so no backwards compatibility.
  7. style: ruff format for py314: except (A, B): becomes except A, B: (PEP 758) in four modules. The ASTs are identical before and after.
  8. fix: the InfluxQL query is built from validated fragments instead of one f-string.

The security finding (commit 8)

The callers only ever pass "max"/"last" and "1h"/"15m", and the sensor id comes from the config entry, so this was not exploitable in practice. But query_sensor_statistics accepts arbitrary strings, and a double quote in a measurement name broke out of the quoted identifier.

Home Assistant's InfluxDB wrapper only exposes query(query, database), so bind parameters are not available. Instead each interpolated value comes from a function that returns a safe value or raises ValueError: _aggregation() (allowlist), _interval(), _quote_identifier() (escapes \ and "), _time_literal() (datetimes only), assembled by _build_statistics_query(). Invalid arguments are rejected before any query is sent. No # nosec is needed. 22 new tests, written first.

Not included

  • pip-audit is off in security.yml: the dev extra is the full HA test environment, not what ships. The only runtime requirement is influxdb>=5.3.1 (manifest).
  • Two test warnings remain (a never-awaited coroutine from a mocked hass in test_learning_engine, and influxdb's own utcfromtimestamp deprecation).
  • The old # noqa: BLE001 in config_flow.py is untouched.

Verified

  • 225 tests, ruff check, ruff format --check and bandit -ll pass on Python 3.14.8 in a clean container with no build tools.
  • The repo's own pre-commit hooks (including the local pytest) pass on a venv rebuilt with Python 3.14.6.

Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98

🤖 Generated with Claude Code

Maintenance run. Eight commits. ## Findings - **The suite was not testing current Home Assistant.** `pyproject.toml` pinned `homeassistant==2025.12.4` and `pytest==9.0.0`, which conflict with the current test plugin (`pytest-homeassistant-custom-component` 0.13.372 pins `homeassistant==2026.10.1`, `pytest==9.0.3`, `pytest-asyncio==1.4.0`). The resolver was held on an old plugin, so tests ran against HA 2025.12. - With the pins removed, **all 203 tests errored at setup** until `asyncio_mode = "auto"` was set (the plugin's async autouse fixtures are only handled in auto mode). - After that: **203 passed on Python 3.14.8 with Home Assistant 2026.10.1.** - `requirements_dev.txt` was a second dev dependency list with 2024-era floors, referenced only in the docs. - **The new security scan found something** (bandit B608, medium): the InfluxQL statistics query was one f-string. See the last commit. ## Commits 1. **chore**: ruff pre-commit hook v0.17.0 (hook id `ruff-check`). 2. **build**: drop the HA and pytest pins (the plugin pins them), `requires-python >=3.14`, `.tool-versions` 3.14, tool floors, `asyncio_mode = "auto"`, remove `requirements_dev.txt`. 3. **docs**: Python 3.14+, install via `pip install -e .[dev]`. 4. **style**: ruff 0.17 formats Python code blocks in Markdown (`DESIGN.md`). 5. **ci**: `.forgejo/workflows/ci.yml` and `security.yml` on the shared workflow-basics actions. 6. **build**: **raises the minimum Home Assistant to 2026.10.0** (`manifest.json`, `hacs.json`, README) and targets Python 3.14 in ruff. Only the latest HA is run, so no backwards compatibility. 7. **style**: ruff format for py314: `except (A, B):` becomes `except A, B:` (PEP 758) in four modules. The ASTs are identical before and after. 8. **fix**: the InfluxQL query is built from validated fragments instead of one f-string. ## The security finding (commit 8) The callers only ever pass `"max"`/`"last"` and `"1h"`/`"15m"`, and the sensor id comes from the config entry, so this was not exploitable in practice. But `query_sensor_statistics` accepts arbitrary strings, and a double quote in a measurement name broke out of the quoted identifier. Home Assistant's InfluxDB wrapper only exposes `query(query, database)`, so bind parameters are not available. Instead each interpolated value comes from a function that returns a safe value or raises `ValueError`: `_aggregation()` (allowlist), `_interval()`, `_quote_identifier()` (escapes `\` and `"`), `_time_literal()` (datetimes only), assembled by `_build_statistics_query()`. Invalid arguments are rejected before any query is sent. No `# nosec` is needed. 22 new tests, written first. ## Not included - `pip-audit` is off in `security.yml`: the dev extra is the full HA test environment, not what ships. The only runtime requirement is `influxdb>=5.3.1` (manifest). - Two test warnings remain (a never-awaited coroutine from a mocked `hass` in `test_learning_engine`, and `influxdb`'s own `utcfromtimestamp` deprecation). - The old `# noqa: BLE001` in `config_flow.py` is untouched. ## Verified - 225 tests, `ruff check`, `ruff format --check` and `bandit -ll` pass on Python 3.14.8 in a clean container with no build tools. - The repo's own pre-commit hooks (including the local pytest) pass on a venv rebuilt with Python 3.14.6. Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Also moves to the ruff-check hook id (ruff is a legacy alias).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98
- dev extra: drop the exact homeassistant==2025.12.4 and pytest==9.0.0
  pins. pytest-homeassistant-custom-component pins homeassistant, pytest
  and pytest-asyncio itself, so with the old pins the resolver was held
  on an old plugin and the suite ran against HA 2025.12. Now >=0.13.372
  resolves HA 2026.10.1 (requires Python >=3.14.2)
- requires-python >=3.14, .tool-versions python 3.14
- tool floors: ruff 0.17.0, mypy 2.4.0, bandit 1.9.4, pre-commit 4.6.2
- pytest asyncio_mode = auto: the plugin's async autouse fixtures are
  otherwise rejected by pytest 9 (203 setup errors in strict mode)
- remove requirements_dev.txt: a second dev dependency list, only
  referenced in docs, with 2024-era floors. pyproject's dev extra is the
  one the Taskfile installs

Ruff target-version stays py313 on purpose: py314 makes the formatter
emit PEP 758 'except A, B:', which is a SyntaxError on Python < 3.14
while manifest.json still declares support for HA 2024.3.

203 tests pass on Python 3.14.8 with Home Assistant 2026.10.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98
README and DEVELOPMENT.md require Python 3.14+. QUICKSTART.md installed
from the removed requirements_dev.txt; use pip install -e .[dev].
Includes the ruff 0.17 formatting of the code blocks in those files.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98
ruff 0.17 formats Python code blocks in Markdown, so the shared lint
step (ruff format --check .) would otherwise fail on this file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98
ci: lint, test and security scan on the shared workflow-basics actions
Some checks failed
CI / Lint and test (pull_request) Successful in 1m31s
Security / Security scan (pull_request) Failing after 10s
80f620d4e6
- ci.yml: python-test with the dev extra (ruff check, ruff format
  --check, pytest against the Home Assistant the plugin pins)
- security.yml: bandit on custom_components and gitleaks over history,
  on PRs, main and weekly. pip-audit is off: the dev extra is the whole
  HA test environment, not what ships

Uses tim/workflow-basics @main.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98
build: require Home Assistant 2026.10 and target Python 3.14
Some checks failed
CI / Lint and test (pull_request) Failing after 1m25s
Security / Security scan (pull_request) Failing after 11s
4ac133bd11
Only the latest Home Assistant is run, so drop the backwards
compatibility: manifest.json and hacs.json declare homeassistant
2026.10.0 (the release the tests run against, which needs Python
>=3.14.2), README matches, and ruff targets py314.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98
except (A, B): becomes except A, B: in four modules. Valid on the
Python 3.14 this integration now requires. The ASTs of all four files
are identical before and after.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98
fix: build InfluxQL from validated fragments instead of one f-string
All checks were successful
CI / Lint and test (pull_request) Successful in 1m36s
Security / Security scan (pull_request) Successful in 12s
b6929980e2
The shared security scan (bandit B608) flagged the statistics query as a
possible SQL injection. In practice the values came from trusted places
(the callers only pass "max"/"last" and "1h"/"15m", the sensor id from
the config entry), but the method accepts arbitrary strings and a double
quote in a measurement name broke out of the quoted identifier.

Home Assistant's InfluxDB wrapper only exposes query(query, database),
so bind parameters are not available. Instead every interpolated value
now comes from a function that returns a safe value or raises:

- _aggregation(): allowlist of InfluxQL aggregation functions
- _interval(): GROUP BY time() duration such as 15m, 1h
- _quote_identifier(): quotes and escapes backslash and double quote
- _time_literal(): only accepts a datetime
- _build_statistics_query() joins those fragments

Invalid aggregation or group_by raise ValueError before any query is
sent. No suppression comment is needed: nothing is left for the scanner
to flag. 22 new tests (written first), 225 pass.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jL41LP9srdcUDYggNpC98
tim merged commit f238d10ed7 into main 2026-10-12 12:05:23 +00:00
tim deleted branch chore/maintenance-2026-10 2026-10-12 12:05:23 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
tim/hass-smart-forecast-solar!1
No description provided.