This project has an AI policy. Always read it and ensure all suggestions, code, and contributions comply. If any behavior seems to conflict with the policy, warn the user and ask for guidance.
Switcher WebAPI is an aiohttp web service wrapping aioswitcher for controlling Switcher smart devices via REST API.
All endpoint handlers follow this structure:
- Extract
device_type,ip,id, and optionallogin_keyfrom query params - Open
SwitcherApiasync context manager - Call the appropriate aioswitcher method
- Serialize and return the result as JSON
- All handlers must be
async defand returnweb.Response - Use
@routes.get/@routes.post/@routes.patch/@routes.deletedecorators - Endpoint path constants are defined at module level in
app/webapp.py - Uncaught exceptions are caught by
error_middlewareand translated into 500 responses;delete_scheduleis the only handler returning 404
- Use
uvfor everything — package management, virtual envs, running commands. Never usepiporvenvdirectly. pyproject.tomlis the single source of truth for dependencies, build config, and tool settings.- This project uses prek (pre-commit replacement). Install the hook with
uv run prek install. - Type annotations on all function signatures
- PEP 257 docstrings on all public modules, classes, and functions
- All request handlers must be
async
uv run ruff check
uv run ruff format --check
uv run ty check# run all tests
uv run pytest -v
# run a specific test
uv run pytest -v -k "test_name_goes_here"
# run tests with coverage
uv run pytest -v --cov --cov-report term-missing- Mock aioswitcher in all tests — never communicate with real devices
- Use
pytest-asyncioin auto mode (no@pytest.mark.asynciodecorators needed) - Use
pytest-aiohttpfor web client testing via theapi_clientfixture - Tests live in
app/tests/ - Minimum 85% coverage (configured in
pyproject.toml)
Multi-platform: amd64, arm/v7, arm64/v8.
podman buildx build \
--build-arg BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
--build-arg VCS_REF=$(git rev-parse --short HEAD) \
--build-arg VERSION=$(grep '^version' pyproject.toml | head -1 | cut -d'"' -f2) \
--platform linux/amd64,linux/arm/v7,linux/arm64/v8 \
--manifest switcher_webapi:<tag> .Key Files:
README.md— user-facing overview and quick startCONTRIBUTING.md— developer setup, workflow, IDE configuration, and commandsdocs/— MkDocs site with endpoint documentation
When to update docs:
- New endpoint added
- Endpoint behavior changed
- Configuration option changed
- Development workflow changed