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 venv (
.venv/bin/binaries for tooling) - Type annotations on all function signatures
- PEP 257 docstrings on all public modules, classes, and functions
- All request handlers must be
async - Ruff for linting and formatting (not flake8/black/isort)
- Configuration lives in
pyproject.toml - Line length: 88 characters
- 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
- Dockerfile must run as a non-root user
- Conventional commit format for PR titles (
feat:,fix:,docs:,chore:,refactor:,test:) - Address CodeRabbit and Sourcery review comments before merging
When reviewing changes:
- Code Quality: no duplicated code, proper error handling, correct async/await patterns
- Security: no exposed secrets, input validation on endpoint parameters
- Conventions: ruff linting configured in
pyproject.toml, tests mock aioswitcher
Key Files:
README.md— user-facing overview and quick startCONTRIBUTING.md— developer setup, workflow, and IDE configurationdocs/— MkDocs site with endpoint documentation
When to update docs:
- New endpoint added
- Endpoint behavior changed
- Configuration option changed
- Development workflow changed