Metadata-Version: 2.5
Name: openems-client
Version: 0.1.0
Summary: Async client for OpenEMS / FENECON FEMS energy management systems
Project-URL: Homepage, https://github.com/Lamarqe/openems-client
Project-URL: Issues, https://github.com/Lamarqe/openems-client/issues
Author: Lamarqe
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Home Automation
Classifier: Typing :: Typed
Requires-Python: >=3.14
Requires-Dist: aiohttp>=3.9
Requires-Dist: jinja2>=3.1
Requires-Dist: jsonrpc-websocket>=4.1.0
Requires-Dist: yarl>=1.9
Description-Content-Type: text/markdown

# openems-client

Async Python client for [OpenEMS](https://openems.io) and FENECON FEMS energy management systems.

It talks to an OpenEMS edge, an OpenEMS backend or the FENECON portal over the
JSON-RPC websocket API, reads the edge configuration (components and channels),
and keeps a live object model of the edge that is updated by `currentData`
push messages. Writing component properties uses JSON-RPC or the REST API.

This library mainly serves the Home Assistant OpenEMS integration, but it does
not depend on Home Assistant.

## Installation

```bash
pip install openems-client
```

Requires Python 3.14 or newer.

## Usage

```python
import asyncio

from openems_client.const import CONN_TYPE_DIRECT_EDGE
from openems_client.entry_data import OpenEMSConfigReader, OpenEMSWebSocketConnection
from openems_client.openems import OpenEMSBackend


async def main() -> None:
    connection = OpenEMSWebSocketConnection(
        {
            "type": CONN_TYPE_DIRECT_EDGE,
            "host": "192.168.1.10",
            "url": None,
            "username": "guest",
            "password": "user",
        }
    )
    await connection.connect_to_server()
    login_response = await connection.login_to_server()

    reader = OpenEMSConfigReader(connection)
    edges = await reader.read_edges()
    edge_id = edges["edges"][0]["id"]
    reader.set_edge_id(edge_id)
    components = await reader.read_edge_components()

    multi_edge = OpenEMSConfigReader.parse_login_response(login_response)
    backend = OpenEMSBackend(connection, edge_id, multi_edge, components)
    backend.start()
    ...
    await backend.stop()


asyncio.run(main())
```

### Connection types

| Constant | Target | Default URL |
| --- | --- | --- |
| `CONN_TYPE_DIRECT_EDGE` | OpenEMS edge | `ws://<host>:8085/` |
| `CONN_TYPE_LOCAL_FEMS` | Local FEMS UI websocket | `ws://<host>:80/websocket` |
| `CONN_TYPE_LOCAL_OPENEMS` | Local OpenEMS backend | `ws://<host>:8082/` |
| `CONN_TYPE_WEB_FENECON` | FENECON portal | `wss://portal.fenecon.de/openems-backend-ui2` |
| `CONN_TYPE_CUSTOM_URL` | Any websocket URL | as given in `url` |

## Development

```bash
uv sync
uv run ruff format --check .
uv run ruff check .
uv run mypy
uv run pytest
```

## License

Apache License 2.0, see [LICENSE](LICENSE).
