Metadata-Version: 2.5
Name: aiowinet
Version: 0.1.0
Summary: Async client for pellet stoves with a WiNET Control Wi-Fi module
Project-URL: Homepage, https://github.com/docteurzoidberg/aiowinet
Project-URL: Changelog, https://github.com/docteurzoidberg/aiowinet/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/docteurzoidberg/aiowinet/issues
Author: DrZoid, Voluzi
License-Expression: MIT
License-File: LICENSE
Keywords: asyncio,home assistant,micronova,pellet stove,winet
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Home Automation
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: aiohttp<4,>=3.9
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: mypy>=1.13; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.9; extra == 'dev'
Description-Content-Type: text/markdown

# aiowinet

[![PyPI version](https://img.shields.io/pypi/v/aiowinet)](https://pypi.org/project/aiowinet/)
[![Python versions](https://img.shields.io/badge/Python-3.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-3776AB)](https://pypi.org/project/aiowinet/)
[![Latest GitHub release](https://img.shields.io/github/v/release/docteurzoidberg/aiowinet)](https://github.com/docteurzoidberg/aiowinet/releases/latest)
[![CI](https://github.com/docteurzoidberg/aiowinet/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/docteurzoidberg/aiowinet/actions/workflows/ci.yml)
[![MIT license](https://img.shields.io/badge/license-MIT-blue)](LICENSE)

A typed asyncio client for reading and controlling Wi-Fi pellet stoves over
the local Micronova-style HTTP register interface of WiNET-style modules. It
speaks three of the module's answer formats ("dialects"): RAM/EEPROM
addresses (`ram_eep`), parameter lists (`params`) and register lists
(`registers`, experimental); see [which profile for which stove](#profiles).
What is known about the local REST `/api` of some firmwares is documented in
`aiowinet.dialects.rest_api`. Read a complete stove state, write
individual settings, or use the higher level power and fan controls.


## Origin

aiowinet started as a fork of [aiopelletstove](https://github.com/voluzi/aiopelletstove) by Voluzi (MIT), which
spoke the RAM/EEPROM dialect of Micronova boards. It adds the other answer formats of WiNET Control modules, stove
profiles, discovery and the module identifier. The `ram_eep_micronova` profile keeps the aiopelletstove 1.x map.

## Install

```sh
python -m pip install aiowinet
```

## Quick start

Set `PELLET_STOVE_HOST` to your stove's local hostname or address before
running the example.

```python
import asyncio
import os

from aiowinet import PelletStove, StoveState


async def read_stove() -> StoveState:
    async with PelletStove(os.environ["PELLET_STOVE_HOST"]) as stove:
        return await stove.async_get_state()


state = asyncio.run(read_stove())
print(f"Room temperature: {state.air_temperature:.1f} °C")
print(f"Power state: {state.power_state.label}")
```

## API

| API | Purpose |
| --- | --- |
| `PelletStove(host, *, session=None, timeout=5.0, dialect=None, profile=None, power_guard=900.0)` | Create a client for a hostname or address with optional port. The answer format (dialect) and the register map (profile) are recognised on the first read; force them with `dialect="ram_eep"`, `profile="params_model1"` or your own `Profile`. `power_guard` is explained under `async_set_power`. |
| `module_model`, `module_name`, `module_signal` | Module model number, name and Wi-Fi level (0–4) sent along with the last register answer, or `None` when the module does not send them (the `params` dialect does). |
| `dialect`, `profile` | Name of the dialect the stove speaks (`"ram_eep"`, `"params"` or `"registers"`), and the `Profile` it is read with, or `None` before the first read. |
| `async_set_target_temperature(value)`, `async_set_power_level(level)` | Set the room set point (whole degrees in `ram_eep`, half degrees in `params`) or the power level, and return the readback. |
| `async_set_room_fan(percent)` | Set the room fan from 50 to 100 % in steps of 5 (`params_model1`). |
| `async_set_fan_level(level)` | Set the room fan level from 1 to 6 (`thermorossi`). |
| `async_get_state(include_diagnostics=True)` | Read common status and preferences into an immutable `StoveState`. Set `include_diagnostics=False` to skip alarm and usage counters; those fields will be `None`. |
| `async_read(register)`, `async_read_many(registers)` | Read and decode registers. Batch reads issue one request per register category. |
| `async_write(register, value)` | Validate and write a register, then return the decoded readback. |
| `async_set_power(on)` | Send the absolute on or off command of boards that have one (Thermorossi: refused only in alarms and unknown statuses; a new command replaces a pending one). Otherwise, toggle only when the reported state requires it and return a `PowerCommandOutcome` (`toggled`, `unchanged`, `blocked` or `pending`, plus the state read under the request lock). Unknown states and `TOGGLE_BLOCKED_STATES` (final cleaning, standby, alarms) block toggles. The stove typically reports the new power state a minute or more after a toggle and keeps the old state until then, and a second toggle would cancel the first: until a read confirms the command, `async_set_power` returns `pending` and sends nothing. Lighting or running confirms "on"; final cleaning or off confirms "off" (every shutdown ends with final cleaning); an alarm ends the attempt. The guard is dropped after `power_guard` seconds without confirmation. `PelletStovePowerOutcomeUnknownError` means the toggle was sent without a readable acknowledgement; the guard stays in place. |
| `async_clear_alarm()` | Clear an alarm as the stove's panel does, by turning it off: the alarm is cleared, the stove runs its final cleaning, then is off and can be lit again. Sends nothing outside alarm states (`blocked`); guarded like a shutdown (`pending` until final cleaning or off). `params_model1` and `thermorossi` profiles; how to clear an alarm in `ram_eep` is not established yet. |
| `pending_power`, `clear_pending_power()` | The requested state of an unconfirmed power command (`True`, `False` or `None`), and a way to forget it after checking the stove. |
| `async_toggle_power()` | Send the raw toggle command, bypassing every guard. Prefer `async_set_power` when you know the desired state. |
| `async_set_fan_regulation(channel, value)` | Set `fan2` or `fan3` to `off`, `1`–`5`, or `auto` while preserving the other channel. RAM/EEPROM dialect only. |
| `async_get_module_info()` | Read the Wi-Fi module's own status (`/ajax/get-status`) into a `ModuleInfo`: firmware version, whether a firmware update is available, Wi-Fi level (0–4) and RSSI. A separate request, never mixed with register reads. Network details of the answer (addresses, network name) are not kept. |
| `async_close()` | Close the client-owned session. The async context manager also closes it. |

Register definitions and encoding helpers live in
[`aiowinet.registers`](src/aiowinet/registers.py).
The caller remains responsible for an injected `aiohttp.ClientSession`.
Each client sends one request at a time, with an idle gap of at least 100 ms
after a read and 150 ms after a write or power toggle. Polling cannot interrupt
a command's sequence of requests. Use one client per stove to share the queue.

Each profile has its own status table (`StoveStatus`); every code maps to an
`Activity`, and `is_on`, `is_off` and `is_alarm` follow from it. Unknown codes
retain their integer value with a label of `unknown_<code>`, `is_known=False`
and the `unknown` activity. Active heating and ashpan cleaning are both `on`.
An alarm is neither on nor off: the stove stopped and waits for the user.
`StoveState` fields a profile does not provide are `None` (see
[Profiles](#profiles)). In the `ram_eep_micronova` profile, off and unknown
states zero stale power, flue temperature, and fan speed; a fan channel with an
unsupported code is `None`, and the client refuses a write that would
overwrite an unknown setting on the other channel.

## Discovery

A WiNET module answers the UDP datagram `###discover` (port 1025) with its
address and a stable identifier, `WINET-` followed by 8 hexadecimal digits. The
identifier does not change with the IP address or the module name, so it can
identify a stove, and find it again after its address changed:

```python
from aiowinet import async_discover, async_get_module_id

modules = await async_discover()  # broadcast, listens 2 s
# [DiscoveredModule(host='192.168.1.40', module_id='WINET-0A1B2C3D')]
module_id = await async_get_module_id("192.168.1.40")  # one module
```

`async_get_module_id` sends the datagram again when no answer comes (UDP may
lose it), then raises `PelletStoveConnectionError`.

## Profiles

A dialect is the shape of the module's answers; a **profile** says what the
registers mean for one kind of stove board: which register holds what, at
which scale, which status table and which alarms apply. Profiles are data
(`Profile`), listed by name in `PROFILES`. The client recognises the dialect
and chooses the profile on its first read; `stove.profile` tells which one.

### Which profile for which stove

| Profile | Dialect | Stoves | Module firmware | Status |
| --- | --- | --- | --- | --- |
| `params_model1` | `params` | **Invicta** (Fontica 8, verified). Other projects report the same answers on Ravelli, Piazzetta and Stufe a Pellet Italia stoves, and on Thermorossi stoves with firmware 0.43 or 0.79 | 0.42 verified; 0.17, 0.43, 0.51, 0.79 reported (on 0.79 the module sends its own scales with the values: they are applied) | **verified** on an Invicta Fontica 8, firmware 0.42 |
| `thermorossi` | `registers` | **Thermorossi** (thermorossi-ha; the IDRA 21 hydro and Slimquadro 9 Evo share the main registers) | 0.73, 0.81 reported | **experimental**: map from other projects, not confirmed through this library yet |
| `ram_eep_micronova` | `ram_eep` | Micronova boards answering with RAM/EEPROM addresses (reported: Duepi EVO, Bestove) | not documented | the aiopelletstove 1.x map |

What each profile provides:

| | `params_model1` | `thermorossi` | `ram_eep_micronova` |
| --- | --- | --- | --- |
| Room temperature, set point, power level | ✓ (half degrees) | ✓ (quarter degrees; no room probe: `None`; power written 1–5, since 0 stops some boards) | ✓ |
| Status table | Micronova (`PowerState`) | Thermorossi (`ThermorossiStatus`) | Micronova (`PowerState`) |
| On and off | toggle, guarded | absolute write of register 1 | toggle, guarded |
| Alarms | 8 named alarms, in alarm states | 17 named alarms, in every status | last alarm code (diagnostics) |
| Clear an alarm (`async_clear_alarm`) | ✓ (the toggle) | ✓ (turning off) | not established |
| Other | room fan 50–100 %, stand-by, buzzer | fan level 1–6, flue temperature, low pellets | flue temperature, current power, fan speed, fans 2 and 3, counters |

A stove "reported" in the table was seen by another project with the same
answers; the library has not been tried on it. If the stove you use is
missing, or a value looks wrong, please open an issue with the answers of
your module (`key=020` for each category).

Each board numbers its statuses its own way: a profile's status table
(`StoveStatus`, `PowerState` for Micronova boards) gives each code a label and
an `Activity` (off, starting, on, shutting down, standby, alarm, unknown), and
the power commands reason on activities only. To try a stove the library does
not know yet, build a `Profile` (for instance with `dataclasses.replace` on a
close one) and pass it as `profile=`; once it works, please propose it
upstream.

## Testing your code

`aiowinet.testing` serves fake modules over real HTTP on a local port,
so integration tests run the real client stack without a stove:

```python
from aiowinet import PelletStove
from aiowinet.testing import FakeParamsStove


async def test_reads_the_stove() -> None:
    async with FakeParamsStove() as fake, PelletStove(fake.host) as stove:
        fake.power_state = 4
        state = await stove.async_get_state()
        assert state.power_state.is_on
```

`FakeParamsStove`, `FakeRamEepStove` and `FakeRegistersStove` record the
requests they receive and
can reproduce quirks of real modules: stray data after the JSON body
(`trailing_data`), an answer for another category (`wrong_category`), stale
values (`freeze()`), slow answers (`delay`), HTTP errors (`status`) and
rejected commands (`toggle_body`).
The fakes also answer discovery on 127.0.0.1, port `fake.discovery_port`,
with `fake.module_id`; `discovery_answers = False` makes them silent.

## Errors

| Error | Meaning |
| --- | --- |
| `PelletStoveError` | Base class for client and protocol errors |
| `PelletStoveConnectionError` | Transport failure or timeout: the stove could not be reached |
| `PelletStoveResponseError` | HTTP error status, or malformed, incomplete, or rejected response |
| `PelletStoveRejectedError` | Explicit rejection by the stove; a `PelletStoveResponseError` |
| `PelletStovePowerOutcomeUnknownError` | A power toggle was sent but its acknowledgement was lost or unreadable |
| `PelletStoveReadOnlyError` | Attempted write to a read-only register |
| `PelletStoveUnsupportedDialectError` | The stove answers in a format this version cannot read; a `PelletStoveResponseError` |
| `PelletStoveUnsupportedError` | The operation does not exist in the stove's dialect |
| `PelletStoveValueError` | Invalid host or unsupported or out-of-range input; also a `ValueError` |

## Compatibility

Requires Python **3.11 or later** and `aiohttp>=3.9,<4`. CI tests Python 3.11,
3.12, 3.13, and 3.14. The package includes type information.

The stove's Wi-Fi module and firmware must expose the local HTTP form API
and one of the register layouts defined in this package. The `params` map is
the one of module model 1, verified on an Invicta Fontica 8 with module
firmware 0.42; its status category is read last, because these modules seem
to refresh from the stove only the categories they are asked for often. Compatibility
depends on the register layout; the package does not verify models by name.
Requests use plain HTTP with no login handshake or internal retries. A
timeout applies to each request, so operations spanning several categories
can take longer than one timeout.

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for development and test instructions,
[CHANGELOG.md](CHANGELOG.md) for release notes, and [SECURITY.md](SECURITY.md)
for private vulnerability reporting.

## License

[MIT](LICENSE).
