Metadata-Version: 2.4
Name: solar-assistant-costs-bridge
Version: 0.1.0
Summary: Bridge para capturar Totales de SolarAssistant y publicarlos por HTTP.
Author-email: Guillermo Teijeiro <gteijeiro29@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/gteijeiro/solar-assistant-costs-bridge
Project-URL: Repository, https://github.com/gteijeiro/solar-assistant-costs-bridge
Project-URL: Issues, https://github.com/gteijeiro/solar-assistant-costs-bridge/issues
Keywords: solarassistant,energy,bridge,websocket,phoenix-liveview
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Home Automation
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Server
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: websockets<17,>=16
Dynamic: license-file

# Solar Assistant Costs Bridge

Bridge en Python para:

- autenticarse contra SolarAssistant,
- conectarse al websocket de Phoenix LiveView de la solapa `Totales`,
- mantener un estado actualizado y persistido,
- publicar ese estado por HTTP para que otra aplicacion lo consulte.

## Estructura

- `src/sa_totals_bridge`: codigo fuente
- `requirements.txt`: dependencias
- `data/`: base SQLite local generada en ejecucion

## Instalacion

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install .
```

Tambien puedes instalarlo directamente desde GitHub:

```bash
pipx install "git+https://github.com/gteijeiro/solar-assistant-costs-bridge.git"
```

## Ejecucion

```bash
export SA_BASE_URL="http://SOLAR_ASSISTANT_HOST_O_IP"
export SA_PASSWORD="TU_PASSWORD_DE_SOLAR_ASSISTANT"
sa-totals-bridge
```

La API queda por defecto en:

- `http://127.0.0.1:8765`
- `http://<tu-ip-local>:8765`

## Endpoints

- `GET /health`
- `GET /state`
- `GET /totals/daily`
- `GET /totals/daily/points`
- `GET /totals/monthly`
- `GET /totals/monthly/points`
- `GET /openapi.json`
- `GET /docs`

Los endpoints de `points` devuelven una sola lista concatenada de todos los periodos cargados. Si necesitas un periodo puntual, puedes usar `?period_key=...`.

## Variables disponibles

- `SA_BASE_URL`
- `SA_PASSWORD`
- `SA_BIND_HOST`
- `SA_BIND_PORT`
- `SA_DB_PATH`
- `SA_LOG_LEVEL`
- `SA_RECONNECT_DELAY`
- `SA_HEARTBEAT_INTERVAL`
- `SA_CONNECT_TIMEOUT`
- `SA_DAILY_HISTORY_PERIODS`
- `SA_MONTHLY_HISTORY_PERIODS`

## Recomendacion de seguridad

- No guardes `SA_PASSWORD` en archivos versionados.
- No subas la base `data/solar_assistant_totals.sqlite3` a GitHub.
- Si usas `.env`, mantenlo fuera del repositorio.

## Notas

- El collector hace una busqueda hacia atras con `prev-daily` y `prev-monthly`, y luego vuelve al periodo actual con `next-daily` y `next-monthly`.
- Por defecto intenta traer `12` periodos diarios anteriores y `5` periodos mensuales anteriores.
- Swagger UI esta en `/docs` y carga assets desde CDN.

## Build y publicacion

Build local:

```bash
python -m pip install --upgrade build
python -m build
```

El repo incluye workflows de GitHub Actions para:

- CI en `push` y `pull_request`,
- publicacion manual a TestPyPI con `workflow_dispatch`,
- publicacion a PyPI al crear un tag `v*`.
