Metadata-Version: 2.3
Name: wks-com
Version: 1.2.1
Summary: Communicate with your inverter (WKS EKO Circle).
Project-URL: Homepage, https://github.com/BoboTiG/python-wks-com
Project-URL: Changelog, https://github.com/BoboTiG/python-wks-com/blob/main/CHANGELOG.md
Project-URL: Source, https://github.com/BoboTiG/python-wks-com
Project-URL: Sponsor, https://github.com/sponsors/BoboTiG
Project-URL: Tracker, https://github.com/BoboTiG/python-wks-com/issues
Project-URL: Released Versions, https://github.com/BoboTiG/python-wks-com/releases
Author-email: Mickaël Schoentgen <contact@tiger-222.fr>
Maintainer-email: Mickaël Schoentgen <contact@tiger-222.fr>
License: MIT License
        Copyright (c) 2023-2024, Mickaël 'Tiger-222' Schoentgen
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
License-File: LICENSE.txt
Keywords: eko,inverter,rs232,serial,wks
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Unix
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Requires-Dist: pydantic<3,>=2.5.2
Requires-Dist: pyserial<4,>=3.5
Provides-Extra: dev
Requires-Dist: build==1.2.2.post1; extra == 'dev'
Requires-Dist: twine==5.1.1; extra == 'dev'
Provides-Extra: test
Requires-Dist: freezegun==1.5.1; extra == 'test'
Requires-Dist: mypy==1.13.0; extra == 'test'
Requires-Dist: pytest-cov==6.0.0; extra == 'test'
Requires-Dist: pytest==8.3.3; extra == 'test'
Requires-Dist: ruff==0.7.1; extra == 'test'
Description-Content-Type: text/markdown

# Python Inverter COM

[![PyPI Version](https://img.shields.io/pypi/v/wks-com.svg)](https://pypi.python.org/pypi/wks-com)
[![PyPI Status](https://img.shields.io/pypi/status/wks-com.svg)](https://pypi.python.org/pypi/wks-com)
[![PyPI Python Versions](https://img.shields.io/pypi/pyversions/wks-com.svg)](https://pypi.python.org/pypi/wks-com)
[![Tests](https://github.com/BoboTiG/python-wks-com/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/BoboTiG/python-wks-com/actions/workflows/tests.yml)
[![Github License](https://img.shields.io/github/license/BoboTiG/python-wks-com.svg)](https://github.com/BoboTiG/python-wks-com/blob/main/LICENSE)

Python module to communicate with WKS EKO Circle inverters.

## Installation

```bash
$ python -m pip install -U wks-com
```

## Module

You can use the module directly from your code:

```python
from wks_com import constants
from wks_com.inverter import Inverter


# Init the inverter (default port is /dev/ttyUSB0, several optional keyword-arguments are available)
# Example: inverter = Inverter("/dev/ttyAMA0", timeout=5.0)
inverter = Inverter()

# Send a command to the inverter
response = inverter.send("QID")

# The same command via an alias
response = inverter.send("serial-no")

# The same command using a constant
response = inverter.send(constants.CMD_SERIAL_NO)
```

## Program

The module comes with the `wks-read` program.
You can use it to send commands to inverters, and see what data you can get from.

The usage is as follows:

```bash
$ wks-read [--port SERIAL_PORT] [--debug] COMMAND_OR_ALIAS [COMMAND_OR_ALIAS...]
```

As an example, here is how to retrieve the inverter serial number:

```bash
$ wks-read QID
"96332309100452"

# The same command via an alias
$ wks-read serial-no
"96332309100452"
```

When enabling debug logs, it will likely show:

```log
$ wks-read --debug serial-no
DEBUG:wks_com.inverter:/dev/ttyUSB0 > SEND 'QIDÖê\r'
DEBUG:wks_com.inverter:/dev/ttyUSB0 > WRITTEN 6 chars (OK)
DEBUG:wks_com.inverter:/dev/ttyUSB0 < RAW b'(96332309100452?\xf3\r'
DEBUG:wks_com.inverter:/dev/ttyUSB0 < DECODED '96332309100452'
"96332309100452"
```

The default port is `/dev/ttyUSB0`, you can change that:

```log
$ wks-read --port /dev/ttyAMA0 serial-no
"96332309100452"
```

## Commands and Aliases

You can send any commands as defined in the official documentation, and even unknown commands.

There are also aliases you could use:

- `daily-load` for the `QLD` command (it will automatically fill the date using the current time);
- `daily-pv` for the `QED` command (it will automatically fill the date using the current time);
- `metrics` for the `QPGS0` command;
- `monthly-load` for the `QLM` command (it will automatically fill the date using the current time);
- `monthly-pv` for the `QEM` command (it will automatically fill the date using the current time);
- `ratings` for the `QPIRI` command;
- `serial-no` for the `QID` command;
- `status` for the `QPIGS` command;
- `time` for the `QT` command;
- `total-load` for the `QLT` command;
- `total-pv` for the `QET` command;
- `warnings` for the `QPIWS` command;
- `yearly-load` for the `QLY` command (it will automatically fill the date using the current time);
- `yearly-pv` for the `QEY` command (it will automatically fill the date using the current time);

When the inverter does not understand a command, it will respond with `NAK`.

## Development

Set up a virtual environment:

```bash
$ python -m venv venv
$ . venv/bin/activate
```

Install, or update, dependencies:

```bash
$ python -m pip install -U pip
$ python -m pip install -e '.[dev]'
```

Run tests:

```bash
$ python -Wd -m pytest --doctest-modules src
```

Run linters, and quality checkers:

```bash
$ ./checks.sh
```
