Metadata-Version: 2.5
Name: eletechsup-modbus-library
Version: 0.3.0
Summary: Async Modbus RTU library for Eletechsup relay, IO, PWM and measurement modules
Project-URL: Documentation, https://github.com/sergeyastakhov/eletechsup-modbus-library#readme
Project-URL: Source, https://github.com/sergeyastakhov/eletechsup-modbus-library
Project-URL: Issues, https://github.com/sergeyastakhov/eletechsup-modbus-library/issues
Project-URL: Changelog, https://github.com/sergeyastakhov/eletechsup-modbus-library/blob/main/CHANGELOG.md
Author: Sergey Astakhov
License-Expression: MIT
License-File: LICENSE
Keywords: asyncio,eletechsup,home-assistant,home-automation,modbus,modbus-connection,modbus-rtu,rs485
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: Topic :: System :: Hardware
Classifier: Typing :: Typed
Requires-Python: >=3.14
Requires-Dist: modbus-connection<5,>=4.12.4
Provides-Extra: test
Requires-Dist: mypy>=1.19; extra == 'test'
Requires-Dist: pytest-asyncio>=1.2; extra == 'test'
Requires-Dist: pytest-cov>=7; extra == 'test'
Requires-Dist: pytest>=9; extra == 'test'
Requires-Dist: ruff>=0.14; extra == 'test'
Description-Content-Type: text/markdown

# eletechsup-modbus-library

Async Modbus RTU protocol library for Eletechsup modules. It owns the register map, the value
decoding and the write rules; it does not own the transport and does not depend on Home Assistant.

The first supported family is **10IOAXX** — industrial IO modules with N opto-isolated inputs and N
relays on RS485. A family is described once: the register-map layout, the link parameters, the
correction kind and the service block live in a `DeviceFamily`, while each model's profile points at
it and declares only what differs — channel counts, product IDs, analog channels and hardware
variants. A caller that builds a form before reading a device asks `family_for("10ioaxx")` for the
baud rates and the address range.

## Installation

```bash
pip install eletechsup-modbus-library
```

Python 3.14 or newer is required. The library builds on
[`modbus-connection`](https://pypi.org/project/modbus-connection/) and passes its tests on the
in-memory backend shipped with it.

## Usage

The caller owns the Modbus unit — a serial port, a TCP gateway, or the Home Assistant `modbus`
integration. The library never opens or closes a connection.

```python
from eletechsup_modbus_library import EletechsupDevice, Parity, RelationMode, require_profile

device = EletechsupDevice(unit, require_profile("10IOA04"))

await device.async_update_state()
first_relay = device.digital_output(0)

await device.async_set_digital_output(0, on=True)
await device.async_set_relation(RelationMode.INTERLOCKING_PAIR)

await device.async_set_auto_report(0)  # 0 disables the unsolicited reports
await device.async_set_return_time(20)  # answer delay, in the family's steps
await device.async_write_link_settings(baudrate=19200, parity=Parity.EVEN)
await device.async_write_digital_outputs_mask(0b1001)  # whole mask, verified by a read
await device.async_read_raw()  # raw registers for diagnostics, cache untouched
```

Writing the bus address is part of the same object, but only when the family allows it:
`async_write_bus_address()` raises `UnsupportedOperationError` on 10IOAXX, where switches set the
address, and `ValueOutOfRangeError` for an address outside the family's range.

Reading is split on purpose: `async_update_state()` is two single-register reads of the output and
input masks, `async_update_settings()` is one request for the settings block. A slow or unreachable
device therefore never hides the state that was read successfully.

Writing is verified. Every settings write is followed by a read-back, and a device that acknowledges
a write but keeps another value raises `ValueNotStoredError` instead of pretending success. The only
exception is the factory reset: after it the device changes speed, parity and address, so a read-back
would fail for reasons that are not an error.

## Supported devices

| Model | Inputs | Relays | Product ID |
|---|---|---|---|
| 10IOA01 | 1 | 1 | 1001 |
| 10IOA02 | 2 | 2 | 1002 |
| 10IOA04 | 4 | 4 | 1004 |
| 10IOA08 | 8 | 8 | 1008 |
| 10IOA12 | 12 | 12 | 1012 |

Catalogue articles such as `10IOA0112VR` differ in power supply and enclosure only; the protocol is
the same, so profiles use the base model name.

## Dependencies

The lower bound is `modbus-connection>=4.12.4`, which is exactly what the `modbus` integration of
Home Assistant 2026.10.4 pins (`modbus-connection[tmodbus]==4.12.4`). That is also the target Home
Assistant: it is the newest release `pytest-homeassistant-custom-component` supports today, and
raising the target would break the integration's test stack until the plugin catches up. Newer
releases stay compatible — 2026.11.0 pins 4.12.7, 2026.11.3 pins 4.12.8, both inside the range —
while 2026.10.0 pins 4.12.3 and is not supported: installing there would force an upgrade of a
dependency Home Assistant pins exactly (2026.10.1–2026.10.4 pin 4.12.4, so they are fine). CI runs the suite twice: against the floor, read from
`pyproject.toml`, and against the latest release.

## Protocol notes

- Defaults: 9600 baud, 8 data bits, no parity, 1 stop bit. The address range and its writability are
  declared by the family: 10IOAXX uses 1–63 and switches, so `async_write_bus_address()` refuses before
  a frame.
- Outputs are read from the holding register `0x0080` and written as single coils; inputs are read
  from `0x0090`. A short input pulse can fall between two polls — the device does not latch it.
- Changing baud rate or parity is stored immediately but takes effect only after a power cycle.
- The factory reset (`0x00FB`) is available as a method but is not exposed by the integration.

Device facts, the register map and the differences between firmware versions are documented in
[the library documentation](https://github.com/sergeyastakhov/eletechsup-modbus-library/blob/main/docs/10ioaxx/DEVICE-FACTS.md).
The cross-family picture is in
[the family overview](https://github.com/sergeyastakhov/eletechsup-modbus-library/blob/main/docs/FAMILIES.md).

## Development

```bash
python -m pytest --cov=eletechsup_modbus_library
ruff format --check .
ruff check .
mypy src
```

Pytest plugins come from their entry points. If `PYTEST_DISABLE_PLUGIN_AUTOLOAD` is set in the
environment, pass them explicitly: `python -m pytest -p pytest_asyncio.plugin -p pytest_cov.plugin
-p modbus_connection.pytest_plugin`.

The transport is mocked on its boundary with the in-memory backend, so the tests need neither
hardware nor a serial port. The change's `tasks.md` names the requirement behind each test group;
scenarios that only a real device can show — reset behaviour, baud rate taking effect after a power
cycle, the input-to-output link — are marked there as live checks.

## License

MIT — see [LICENSE](https://github.com/sergeyastakhov/eletechsup-modbus-library/blob/main/LICENSE).
