-
-
Notifications
You must be signed in to change notification settings - Fork 6
quality checks
This document describes the static quality tools available in HSEM and how to run them locally.
| Tool | Purpose | Config |
|---|---|---|
| Pyright | Type checking (CI-friendly Pylance equivalent) | pyrightconfig.json |
| Vulture | Dead-code and unused-symbol detection | vulture_whitelist.py |
| mypy | Legacy type checking | pyproject.toml [tool.mypy] |
| ruff | Linting and formatting | pyproject.toml [tool.ruff] |
| black | Code formatting | tox.ini [testenv:lint] |
| isort | Import sorting | tox.ini [testenv:lint] |
tox -e lintpython -m pyrightThis reads pyrightconfig.json and checks custom_components/hsem and tests/.
python -m vulture custom_components/hsem tests vulture_whitelist.py --min-confidence 80The vulture_whitelist.py file suppresses false positives for Home Assistant lifecycle
methods (e.g. async_setup_entry, config flow steps) that Vulture would otherwise flag as
unused because they are called dynamically by HA.
tox -e qualitypytest tests/pyrightconfig.json is set to typeCheckingMode: "basic" — a safe starting point for an
HA integration that uses many dynamic patterns. Do not upgrade to strict mode without
first resolving the known false-positive list.
| Rule | Level | Reason |
|---|---|---|
reportMissingTypeStubs |
none | HA stubs are incomplete |
reportUnknownMemberType |
none | HA uses Any extensively |
reportUnknownVariableType |
none | HA uses Any extensively |
reportUnknownArgumentType |
none | HA uses Any extensively |
reportTypedDictNotRequiredAccess |
none | HA flow results use TypedDict with all-optional keys |
Most remaining warnings fall into two categories that are HA framework limitations, not bugs in HSEM:
-
CoordinatorEntitygeneric invariance (~38 warnings incustom_sensors/*.py): All HSEM sensors inherit fromCoordinatorEntity[HSEMDataUpdateCoordinator]but HA's genericCoordinatorEntity[DataUpdateCoordinator[dict[str, Any]]]is invariant. These are safe at runtime; the correct fix is to wait for HA to widen the generic. -
Test mock patterns (~100 warnings in
tests/): Tests use partial mocks,MagicMock, and stub objects that don't have full type annotations. These are safe and intentional.
vulture_whitelist.py documents all HA dynamic entry points. Before deleting any function
that Vulture flags, check whether it belongs to one of these categories:
- HA integration lifecycle:
async_setup_entry,async_unload_entry,async_migrate_entry - Config/options flow steps:
async_step_user,async_step_init, etc. - Diagnostics:
async_get_config_entry_diagnostics - Platform setup:
async_setup_entryinsensor.py,select.py,switch.py,time.py - Entity properties used by HA:
device_info,native_value,is_on, etc.
If in doubt, add to the whitelist rather than deleting.
Pyright and Vulture run in CI as the quality job in .github/workflows/lint-and-test.yml.
Both are currently set to continue-on-error: true (staged rollout) to avoid blocking
PRs until the warning baseline is fully resolved.
Next steps to harden CI:
- Resolve the remaining
CoordinatorEntityinvariance warnings (requires HA framework fix or a type-ignore comment on eachsuper().__init__()call). - Set
continue-on-error: falsein the CI workflow once the warning count is zero. - Add
tox -e qualityto the local pre-commit checklist.
- Home — User-facing overview: features, FAQ, working modes, battery schedules, excess export, consumption sensors
- Battery Charging Economics — How to calculate the minimum charging price for a battery schedule
- Architecture Overview — System context, layered architecture, module map, planning pipeline
- Planner Specification — Normative — all planner invariants, rules, and constraints
- Planner Technical Guide — How the planner works with worked examples
- Cost Function Math — Complete mathematical formulation of the 8-term cost function
- Energy Accounting — Physical energy flow model, SoC simulation, efficiency math
- Candidate Generation — How candidates are generated, assumptions, partial-SoC
- MILP Optimization — Full LP formulation, variable layout, constraints, and solver pipeline
- Consumption Prediction — Weighted-average model, IQR outlier detection, spike suppression
- Safety Modes — Degraded mode, read-only gate, write-verify applier, runtime resolver
- Price Scaling — EDS price scaling, eds_share conversion factor
- Services Reference — All 4 HSEM services with examples
- Sensors Reference — Complete entity reference: all sensor, select, switch, number, and time entities
- Dashboard Setup — Step-by-step ApexCharts dashboard with full YAML, layout reference, and troubleshooting
- Config Flow Reference — Every config/options flow step and field
- EV Charge Plan Setup — EV planned load configuration guide
- EV Surplus Charging Automation — Wire your physical EV charger (go-e, Easee, Zaptec) to follow HSEM surplus recommendations
- EV Optimal Charging Template — Legacy Home Assistant template sensor for cost-optimal EV charging
- Forecast Accuracy Tracking — Forecast vs actual tracking system
- Huawei Entities — Canonical HA entity ID reference
- Troubleshooting Guide — Diagnose and fix common problems: missing data, wrong prices, write failures, battery behaviour
- Quality Checks — Static quality tools and CI configuration