|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +`halpid` is a power monitor and watchdog daemon for the HALPI2 Raspberry Pi Compute Module 5 based boat computer. The daemon provides blackout reporting, watchdog functionality, RTC sleep mode, and USB port power cycling capabilities. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +This project uses `uv` for dependency management and a custom `./run` script for common tasks: |
| 12 | + |
| 13 | +### Essential Commands |
| 14 | +- `./run install` - Install project dependencies and create virtual environment |
| 15 | +- `./run lint` - Run linting (ruff check/format + mypy type checking) |
| 16 | +- `./run format` - Auto-format code with ruff |
| 17 | +- `./run mypy` - Run type checking only |
| 18 | +- `./run clean` - Remove temporary files and caches |
| 19 | + |
| 20 | +### Testing |
| 21 | +- `uv run pytest` - Run all tests (uses pytest configuration from pyproject.toml) |
| 22 | +- `uv run pytest tests/test_example/test_hello.py` - Run specific test file |
| 23 | +- `uv run pytest -k test_name` - Run specific test by name |
| 24 | + |
| 25 | +### Package Management |
| 26 | +- `uv sync` - Install dependencies from lock file |
| 27 | +- `uv lock` - Update lock file |
| 28 | +- `./run update-dev-deps` - Update development dependencies |
| 29 | + |
| 30 | +### Debian Packaging |
| 31 | +- `./run build-debian` - Build Debian package |
| 32 | +- `./run debtools-build` - Build using Docker container |
| 33 | + |
| 34 | +## Architecture |
| 35 | + |
| 36 | +### Core Components |
| 37 | + |
| 38 | +**Entry Points** (`src/halpi/__main__.py`): |
| 39 | +- `halpi` - CLI command interface |
| 40 | +- `halpid` - Daemon service |
| 41 | + |
| 42 | +**Main Modules**: |
| 43 | +- `daemon.py` - Main daemon service with asyncio event loop, HTTP server, and I2C device communication |
| 44 | +- `cli.py` - Typer-based CLI interface that communicates with daemon via Unix socket HTTP API |
| 45 | +- `i2c.py` - I2C device communication layer for HALPI2 hardware |
| 46 | +- `server.py` - HTTP server providing REST API for device status and control |
| 47 | +- `state_machine.py` - Power management state machine handling blackout detection and shutdown logic |
| 48 | + |
| 49 | +**Configuration**: |
| 50 | +- Default config location: `/etc/halpid/halpid.conf` |
| 51 | +- YAML format with dash-to-underscore key conversion |
| 52 | +- Configurable blackout timing, voltage limits, and poweroff commands |
| 53 | + |
| 54 | +### Communication Architecture |
| 55 | +- Daemon runs HTTP server on Unix socket (`/run/halpid/halpid.sock`) |
| 56 | +- CLI communicates with daemon via aiohttp UnixConnector |
| 57 | +- I2C communication with HALPI2 controller on bus 1, address 0x48 |
| 58 | +- State machine handles power management events and triggers system shutdown |
| 59 | + |
| 60 | +### Hardware Integration |
| 61 | +- Uses `smbus2` for I2C communication with HALPI2 controller |
| 62 | +- Monitors input voltage, supercap voltage, and power state |
| 63 | +- Provides watchdog functionality (10-second timeout) |
| 64 | +- Supports RTC-based wake scheduling and USB port power cycling |
| 65 | + |
| 66 | +## Code Quality Tools |
| 67 | + |
| 68 | +**Linting**: Ruff (pyflakes, pycodestyle, isort rules) with 88-character line length |
| 69 | +**Type Checking**: MyPy with strict settings enabled |
| 70 | +**Testing**: Pytest with coverage reporting |
| 71 | +**Formatting**: Ruff formatter (replaces Black) |
| 72 | + |
| 73 | +The project targets Python 3.11+ and follows modern Python practices with full type annotations. |
0 commit comments