eg4-python


Nameeg4-python JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryPython client for EG4 solar inverter monitoring with async/sync support
upload_time2025-07-15 21:22:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseApache-2.0
keywords eg4 solar inverter monitoring api async home-assistant
VCS
bugtrack_url
requirements aiohttp pytest pytest-asyncio python-dotenv
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# EG4 Inverter Python Client

![Python](https://img.shields.io/badge/Python-3.8%2B-blue.svg)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)

**`eg4_python`** is a Python library that provides both **async** and **sync** methods to interact with the **EG4 Inverter** cloud API. It handles login, data retrieval, and session management efficiently — ideal for integration with **Home Assistant**, MCP, automation platforms, or custom monitoring solutions.

## Caveats

---

## Features
✅ Asynchronous and synchronous support (via `asyncio` and sync wrappers)  
✅ Automatic re-authentication on session expiry (401 errors)  
✅ Modular structure for future expandability  
✅ Supports DISCOVERING multiple inverters from a single account

---

## Installation

### Using PyPI (Recommended)
```bash
pip install eg4_python
```

### Development Version (Editable Mode)
```bash
git clone https://github.com/yourusername/eg4_python.git
cd eg4_python
pip install -e .[dev]  # For development and testing
```

---

## Usage

### Example Code
You can look at the "test" function in client.py

```python
import asyncio
from eg4_python import EG4InverterAPI

async def main():
    api = EG4InverterAPI(username="username", password="password", base_url="https://monitor.eg4electronics.com")
    await api.login(ignore_ssl=True)

    # Display Inverters
    for index, inverter in enumerate(api.get_inverters()):
        print(f"Inverter {index}: {inverter}")

    print("Selecting Inverter 0")
    api.set_selected_inverter(inverterIndex=0)

    # Fetch Runtime Data
    runtime_data = await api.get_inverter_runtime_async()
    print("Runtime Data:", runtime_data)

    # Fetch Energy Data
    energy_data = await api.get_inverter_energy_async()
    print("Energy Data:", energy_data)

    # Fetch Battery Data
    battery_data = await api.get_inverter_battery_async()
    print("Battery Data:", battery_data)
    await api.close()

asyncio.run(main())
```

---

## Configuration

### Environment Variables (Recommended for Secrets)
Create a `.env` file:
```
USERNAME=your_username
PASSWORD=your_password
SERIAL_NUMBER=
PLANT_ID=
BASE_URL=https://monitor.eg4electronics.com
```

### Example `.env` Loading in Code
```python
import os
from dotenv import load_dotenv

load_dotenv()
USERNAME = os.getenv("USERNAME")
PASSWORD = os.getenv("PASSWORD")
```

---

## API Methods

### **Authentication & Session Management**
- `async def login()` – Handles login and saves the JSESSIONID cookie.  Accepts ignore_ssl=[true|false]
- `async def close()` – Gracefully closes the HTTP session.

### **Setup**
- `get_inverters()` - list the inverters associated with the account, after login
- `set_selected_inverter(inverterIndex=index)` - Selects an inverter from the list of inverters
- `set_selected_inverter(plantId=plantId, serialNum=serialNum)`  - Explicitly sets the selected inverter

### **Data Retrieval**
- `async def get_inverter_runtime_async()` – Retrieves inverter runtime data.
- `async def get_inverter_energy_async()` – Retrieves inverter energy data.
- `async def get_inverter_battery_async()` – Retrieves battery data, including individual battery units.

### **Parameters read/write**
- `async def read_settings_async()` – reads parameters.
- `async def write_settings_async()` – writes a parameter value.

### **Sync Methods (Wrappers)**
- `get_inverter_runtime()`
- `get_inverter_energy()`
- `get_inverter_battery()`
- `read_settings()`
- `write_settings()`

---

## Running Tests
Ensure you have development dependencies installed:
```bash
pip install -e .[dev]
```

Then run the test suite:
```bash
pytest tests/
```

---

## Roadmap
- ✅ Initial EG4 API implementation
- ✅ Async/Sync support
- ✅ Setting inverter values
- 🔜 ...Full Home Assistant Integration
- 🔜 ...You tell me

---

## License
This project is licensed under the **APACHE License**.
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)


---

## Contributing
Contributions are welcome! Please open issues, suggest improvements, or submit pull requests.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/awesome-feature`)
3. Commit your changes (`git commit -m 'Add an awesome feature'`)
4. Push to the branch (`git push origin feature/awesome-feature`)
5. Open a Pull Request

---

## Author
**Garreth Jeremiah**  
[GitHub Profile](https://github.com/twistedroutes)

---

## Acknowledgments
Special thanks to DAB Ultimate beer!


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "eg4-python",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "eg4, solar, inverter, monitoring, api, async, home-assistant",
    "author": null,
    "author_email": "Matt Dreyer <matt_dreyer@hotmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fb/63/3f8712c339e3eb66eae9bea0b3e787bf1670c1202cde6f8d2da5fb5523c2/eg4_python-0.1.2.tar.gz",
    "platform": null,
    "description": "\r\n# EG4 Inverter Python Client\r\n\r\n![Python](https://img.shields.io/badge/Python-3.8%2B-blue.svg)\r\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)\r\n\r\n**`eg4_python`** is a Python library that provides both **async** and **sync** methods to interact with the **EG4 Inverter** cloud API. It handles login, data retrieval, and session management efficiently \u2014 ideal for integration with **Home Assistant**, MCP, automation platforms, or custom monitoring solutions.\r\n\r\n## Caveats\r\n\r\n---\r\n\r\n## Features\r\n\u2705 Asynchronous and synchronous support (via `asyncio` and sync wrappers)  \r\n\u2705 Automatic re-authentication on session expiry (401 errors)  \r\n\u2705 Modular structure for future expandability  \r\n\u2705 Supports DISCOVERING multiple inverters from a single account\r\n\r\n---\r\n\r\n## Installation\r\n\r\n### Using PyPI (Recommended)\r\n```bash\r\npip install eg4_python\r\n```\r\n\r\n### Development Version (Editable Mode)\r\n```bash\r\ngit clone https://github.com/yourusername/eg4_python.git\r\ncd eg4_python\r\npip install -e .[dev]  # For development and testing\r\n```\r\n\r\n---\r\n\r\n## Usage\r\n\r\n### Example Code\r\nYou can look at the \"test\" function in client.py\r\n\r\n```python\r\nimport asyncio\r\nfrom eg4_python import EG4InverterAPI\r\n\r\nasync def main():\r\n    api = EG4InverterAPI(username=\"username\", password=\"password\", base_url=\"https://monitor.eg4electronics.com\")\r\n    await api.login(ignore_ssl=True)\r\n\r\n    # Display Inverters\r\n    for index, inverter in enumerate(api.get_inverters()):\r\n        print(f\"Inverter {index}: {inverter}\")\r\n\r\n    print(\"Selecting Inverter 0\")\r\n    api.set_selected_inverter(inverterIndex=0)\r\n\r\n    # Fetch Runtime Data\r\n    runtime_data = await api.get_inverter_runtime_async()\r\n    print(\"Runtime Data:\", runtime_data)\r\n\r\n    # Fetch Energy Data\r\n    energy_data = await api.get_inverter_energy_async()\r\n    print(\"Energy Data:\", energy_data)\r\n\r\n    # Fetch Battery Data\r\n    battery_data = await api.get_inverter_battery_async()\r\n    print(\"Battery Data:\", battery_data)\r\n    await api.close()\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n---\r\n\r\n## Configuration\r\n\r\n### Environment Variables (Recommended for Secrets)\r\nCreate a `.env` file:\r\n```\r\nUSERNAME=your_username\r\nPASSWORD=your_password\r\nSERIAL_NUMBER=\r\nPLANT_ID=\r\nBASE_URL=https://monitor.eg4electronics.com\r\n```\r\n\r\n### Example `.env` Loading in Code\r\n```python\r\nimport os\r\nfrom dotenv import load_dotenv\r\n\r\nload_dotenv()\r\nUSERNAME = os.getenv(\"USERNAME\")\r\nPASSWORD = os.getenv(\"PASSWORD\")\r\n```\r\n\r\n---\r\n\r\n## API Methods\r\n\r\n### **Authentication & Session Management**\r\n- `async def login()` \u2013 Handles login and saves the JSESSIONID cookie.  Accepts ignore_ssl=[true|false]\r\n- `async def close()` \u2013 Gracefully closes the HTTP session.\r\n\r\n### **Setup**\r\n- `get_inverters()` - list the inverters associated with the account, after login\r\n- `set_selected_inverter(inverterIndex=index)` - Selects an inverter from the list of inverters\r\n- `set_selected_inverter(plantId=plantId, serialNum=serialNum)`  - Explicitly sets the selected inverter\r\n\r\n### **Data Retrieval**\r\n- `async def get_inverter_runtime_async()` \u2013 Retrieves inverter runtime data.\r\n- `async def get_inverter_energy_async()` \u2013 Retrieves inverter energy data.\r\n- `async def get_inverter_battery_async()` \u2013 Retrieves battery data, including individual battery units.\r\n\r\n### **Parameters read/write**\r\n- `async def read_settings_async()` \u2013 reads parameters.\r\n- `async def write_settings_async()` \u2013 writes a parameter value.\r\n\r\n### **Sync Methods (Wrappers)**\r\n- `get_inverter_runtime()`\r\n- `get_inverter_energy()`\r\n- `get_inverter_battery()`\r\n- `read_settings()`\r\n- `write_settings()`\r\n\r\n---\r\n\r\n## Running Tests\r\nEnsure you have development dependencies installed:\r\n```bash\r\npip install -e .[dev]\r\n```\r\n\r\nThen run the test suite:\r\n```bash\r\npytest tests/\r\n```\r\n\r\n---\r\n\r\n## Roadmap\r\n- \u2705 Initial EG4 API implementation\r\n- \u2705 Async/Sync support\r\n- \u2705 Setting inverter values\r\n- \ud83d\udd1c ...Full Home Assistant Integration\r\n- \ud83d\udd1c ...You tell me\r\n\r\n---\r\n\r\n## License\r\nThis project is licensed under the **APACHE License**.\r\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)\r\n\r\n\r\n---\r\n\r\n## Contributing\r\nContributions are welcome! Please open issues, suggest improvements, or submit pull requests.\r\n\r\n1. Fork the repository\r\n2. Create your feature branch (`git checkout -b feature/awesome-feature`)\r\n3. Commit your changes (`git commit -m 'Add an awesome feature'`)\r\n4. Push to the branch (`git push origin feature/awesome-feature`)\r\n5. Open a Pull Request\r\n\r\n---\r\n\r\n## Author\r\n**Garreth Jeremiah**  \r\n[GitHub Profile](https://github.com/twistedroutes)\r\n\r\n---\r\n\r\n## Acknowledgments\r\nSpecial thanks to DAB Ultimate beer!\r\n\r\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Python client for EG4 solar inverter monitoring with async/sync support",
    "version": "0.1.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/matt-dreyer/eg4_python/issues",
        "Documentation": "https://github.com/matt-dreyer/eg4_python",
        "Homepage": "https://github.com/matt-dreyer/eg4_python",
        "Repository": "https://github.com/matt-dreyer/eg4_python"
    },
    "split_keywords": [
        "eg4",
        " solar",
        " inverter",
        " monitoring",
        " api",
        " async",
        " home-assistant"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "eb515cc2320854e8e348de5328ce32b30ffb775519e73c83f6ae038d9b91c556",
                "md5": "4009e007bf6a0bc36278ab0469faabda",
                "sha256": "631559e1045581761008f5184409f69d788fa5a2fde0d51569b6cf3b5cf37ba9"
            },
            "downloads": -1,
            "filename": "eg4_python-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4009e007bf6a0bc36278ab0469faabda",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 16365,
            "upload_time": "2025-07-15T21:22:48",
            "upload_time_iso_8601": "2025-07-15T21:22:48.434387Z",
            "url": "https://files.pythonhosted.org/packages/eb/51/5cc2320854e8e348de5328ce32b30ffb775519e73c83f6ae038d9b91c556/eg4_python-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "fb633f8712c339e3eb66eae9bea0b3e787bf1670c1202cde6f8d2da5fb5523c2",
                "md5": "f7addc2d6e909e32796b4c4bb1250126",
                "sha256": "50326fa09b3c6ee11b0daf06af0de5ab1b794a2504dc11ecf052321785f67ad0"
            },
            "downloads": -1,
            "filename": "eg4_python-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "f7addc2d6e909e32796b4c4bb1250126",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 18343,
            "upload_time": "2025-07-15T21:22:49",
            "upload_time_iso_8601": "2025-07-15T21:22:49.812830Z",
            "url": "https://files.pythonhosted.org/packages/fb/63/3f8712c339e3eb66eae9bea0b3e787bf1670c1202cde6f8d2da5fb5523c2/eg4_python-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-15 21:22:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "matt-dreyer",
    "github_project": "eg4_python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": [
                [
                    ">=",
                    "3.8.5"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    ">=",
                    "7.4.0"
                ]
            ]
        },
        {
            "name": "pytest-asyncio",
            "specs": [
                [
                    ">=",
                    "0.21.1"
                ]
            ]
        },
        {
            "name": "python-dotenv",
            "specs": [
                [
                    ">=",
                    "1.0.0"
                ]
            ]
        }
    ],
    "lcname": "eg4-python"
}
        
Elapsed time: 1.69127s