pyhelty 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyhelty/__init__.py ADDED
@@ -0,0 +1,27 @@
1
+ """Async client library for Helty Flow VMC units with the smart Wi-Fi interface."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .client import HeltyClient
6
+ from .const import DEFAULT_PORT, DEFAULT_TIMEOUT, FanMode
7
+ from .exceptions import (
8
+ HeltyCommandError,
9
+ HeltyConnectionError,
10
+ HeltyError,
11
+ HeltyResponseError,
12
+ )
13
+ from .models import HeltyData
14
+
15
+ __all__ = [
16
+ "DEFAULT_PORT",
17
+ "DEFAULT_TIMEOUT",
18
+ "FanMode",
19
+ "HeltyClient",
20
+ "HeltyCommandError",
21
+ "HeltyConnectionError",
22
+ "HeltyData",
23
+ "HeltyError",
24
+ "HeltyResponseError",
25
+ ]
26
+
27
+ __version__ = "0.1.0"
pyhelty/client.py ADDED
@@ -0,0 +1,186 @@
1
+ """Async client for Helty Flow VMC units."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import logging
7
+
8
+ from .const import (
9
+ CMD_LED_OFF,
10
+ CMD_LED_ON,
11
+ CMD_NAME,
12
+ CMD_RESET_FILTER,
13
+ CMD_SENSORS,
14
+ CMD_STATUS,
15
+ DEFAULT_PORT,
16
+ DEFAULT_RETRIES,
17
+ DEFAULT_RETRY_DELAY,
18
+ DEFAULT_TIMEOUT,
19
+ LED_ON_VALUE,
20
+ PREFIX_NAME,
21
+ PREFIX_SENSORS,
22
+ PREFIX_STATUS,
23
+ RESPONSE_OK,
24
+ SENSOR_SCALE,
25
+ SIGNED_16_MODULUS,
26
+ SIGNED_16_THRESHOLD,
27
+ FanMode,
28
+ )
29
+ from .exceptions import (
30
+ HeltyCommandError,
31
+ HeltyConnectionError,
32
+ HeltyResponseError,
33
+ )
34
+ from .models import HeltyData
35
+
36
+ _LOGGER = logging.getLogger(__name__)
37
+
38
+ _READ_LIMIT = 4096
39
+
40
+
41
+ class HeltyClient:
42
+ """Talks to a single Helty Flow unit over its TCP interface.
43
+
44
+ The unit serves one command per TCP connection and then closes it, so each
45
+ call opens a fresh connection. An internal lock serialises commands because
46
+ the unit does not reliably handle concurrent connections.
47
+ """
48
+
49
+ def __init__(
50
+ self,
51
+ host: str,
52
+ port: int = DEFAULT_PORT,
53
+ *,
54
+ timeout: float = DEFAULT_TIMEOUT,
55
+ retries: int = DEFAULT_RETRIES,
56
+ retry_delay: float = DEFAULT_RETRY_DELAY,
57
+ ) -> None:
58
+ self._host = host
59
+ self._port = port
60
+ self._timeout = timeout
61
+ self._retries = retries
62
+ self._retry_delay = retry_delay
63
+ self._lock = asyncio.Lock()
64
+
65
+ @property
66
+ def host(self) -> str:
67
+ return self._host
68
+
69
+ @property
70
+ def port(self) -> int:
71
+ return self._port
72
+
73
+ async def _execute_once(self, command: bytes) -> str:
74
+ """Open a connection, send one command and return the stripped reply."""
75
+ async with asyncio.timeout(self._timeout):
76
+ reader, writer = await asyncio.open_connection(self._host, self._port)
77
+ try:
78
+ writer.write(command)
79
+ await writer.drain()
80
+ payload = await reader.read(_READ_LIMIT)
81
+ finally:
82
+ writer.close()
83
+ await writer.wait_closed()
84
+ return payload.decode("ascii", errors="replace").strip()
85
+
86
+ async def _execute(self, command: bytes) -> str:
87
+ """Send one command, retrying transient failures and empty replies.
88
+
89
+ The unit serves a single command per connection and intermittently
90
+ accepts a connection but returns an empty payload (especially right
91
+ after an idle period or on rapid reconnection), so an empty reply is
92
+ treated as a retryable, transient condition.
93
+ """
94
+ last_error: Exception | None = None
95
+ async with self._lock:
96
+ for attempt in range(self._retries + 1):
97
+ if attempt:
98
+ await asyncio.sleep(self._retry_delay)
99
+ try:
100
+ reply = await self._execute_once(command)
101
+ except (TimeoutError, OSError) as err:
102
+ last_error = err
103
+ _LOGGER.debug(
104
+ "Helty %s:%s command %r failed (attempt %d/%d): %s",
105
+ self._host, self._port, command, attempt + 1, self._retries + 1, err,
106
+ )
107
+ continue
108
+ if reply:
109
+ return reply
110
+ last_error = HeltyConnectionError("empty reply")
111
+ _LOGGER.debug(
112
+ "Helty %s:%s returned empty reply to %r (attempt %d/%d)",
113
+ self._host, self._port, command, attempt + 1, self._retries + 1,
114
+ )
115
+ raise HeltyConnectionError(
116
+ f"Failed to communicate with Helty at {self._host}:{self._port}: {last_error}"
117
+ )
118
+
119
+ @staticmethod
120
+ def _parse_fields(reply: str, prefix: str) -> tuple[int, ...]:
121
+ """Validate the reply prefix and parse the trailing CSV integer fields."""
122
+ parts = reply.split(",")
123
+ if not parts or parts[0] != prefix:
124
+ raise HeltyResponseError(f"Expected {prefix!r} reply, got {reply!r}")
125
+ try:
126
+ return tuple(int(value) for value in parts[1:])
127
+ except ValueError as err:
128
+ raise HeltyResponseError(f"Non-integer field in {reply!r}") from err
129
+
130
+ @staticmethod
131
+ def _to_temperature(raw: int) -> float:
132
+ """Scale a raw tenths-of-degree value, treating it as signed 16-bit."""
133
+ if raw >= SIGNED_16_THRESHOLD:
134
+ raw -= SIGNED_16_MODULUS
135
+ return raw / SENSOR_SCALE
136
+
137
+ async def async_get_name(self) -> str:
138
+ """Return the user-assigned device name (also used as a stable id)."""
139
+ reply = await self._execute(CMD_NAME)
140
+ if not reply.startswith(PREFIX_NAME):
141
+ raise HeltyResponseError(f"Expected {PREFIX_NAME!r} reply, got {reply!r}")
142
+ return reply[len(PREFIX_NAME) :].strip()
143
+
144
+ async def async_get_data(self) -> HeltyData:
145
+ """Fetch name, sensors and status in a single coordinated read."""
146
+ name = await self.async_get_name()
147
+ sensors = self._parse_fields(await self._execute(CMD_SENSORS), PREFIX_SENSORS)
148
+ status = self._parse_fields(await self._execute(CMD_STATUS), PREFIX_STATUS)
149
+
150
+ if len(sensors) < 3:
151
+ raise HeltyResponseError(f"Too few sensor fields: {sensors!r}")
152
+ if len(status) < 2:
153
+ raise HeltyResponseError(f"Too few status fields: {status!r}")
154
+
155
+ try:
156
+ fan_mode = FanMode(status[0])
157
+ except ValueError as err:
158
+ raise HeltyResponseError(f"Unknown fan mode {status[0]}") from err
159
+
160
+ return HeltyData(
161
+ name=name,
162
+ fan_mode=fan_mode,
163
+ leds_on=status[1] == LED_ON_VALUE,
164
+ indoor_temperature=self._to_temperature(sensors[0]),
165
+ outdoor_temperature=self._to_temperature(sensors[1]),
166
+ indoor_humidity=sensors[2] / SENSOR_SCALE,
167
+ raw_sensors=sensors,
168
+ raw_status=status,
169
+ )
170
+
171
+ async def _write(self, command: bytes) -> None:
172
+ reply = await self._execute(command)
173
+ if reply != RESPONSE_OK:
174
+ raise HeltyCommandError(f"Command {command!r} not acknowledged, got {reply!r}")
175
+
176
+ async def async_set_fan_mode(self, mode: FanMode) -> None:
177
+ """Select a fan speed or preset program."""
178
+ await self._write(mode.command)
179
+
180
+ async def async_set_led(self, on: bool) -> None:
181
+ """Turn the front LED panel on or off."""
182
+ await self._write(CMD_LED_ON if on else CMD_LED_OFF)
183
+
184
+ async def async_reset_filter(self) -> None:
185
+ """Reset the filter-life counter."""
186
+ await self._write(CMD_RESET_FILTER)
pyhelty/const.py ADDED
@@ -0,0 +1,90 @@
1
+ """Protocol constants for the Helty Flow VMC TCP interface.
2
+
3
+ The protocol is reverse-engineered (no official specification). Commands are
4
+ plain ASCII byte strings sent over a TCP socket; the unit replies with an ASCII
5
+ payload and then closes the connection. One command is served per connection.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from enum import IntEnum
11
+
12
+ #: Default TCP port exposed by the Helty smart Wi-Fi interface.
13
+ DEFAULT_PORT = 5001
14
+
15
+ #: Default per-command timeout, in seconds.
16
+ DEFAULT_TIMEOUT = 10.0
17
+
18
+ #: Default number of retries on a transient failure or empty reply.
19
+ DEFAULT_RETRIES = 3
20
+
21
+ #: Default delay between retries, in seconds.
22
+ DEFAULT_RETRY_DELAY = 0.5
23
+
24
+ # --- Read commands ---------------------------------------------------------
25
+ #: Query the device name. Reply: ``VMNM <name>``.
26
+ CMD_NAME = b"VMNM?"
27
+ #: Query live sensor values. Reply: ``VMGI,<f1>,<f2>,...`` (15 fields).
28
+ CMD_SENSORS = b"VMGI?"
29
+ #: Query operating status/config. Reply: ``VMGO,<f1>,<f2>,...`` (15 fields).
30
+ CMD_STATUS = b"VMGH?"
31
+
32
+ # --- Reply prefixes --------------------------------------------------------
33
+ PREFIX_NAME = "VMNM"
34
+ PREFIX_SENSORS = "VMGI"
35
+ PREFIX_STATUS = "VMGO"
36
+
37
+ # --- Write commands --------------------------------------------------------
38
+ #: Turn the front LED panel on / off.
39
+ CMD_LED_ON = b"VMWH0100010"
40
+ CMD_LED_OFF = b"VMWH0100000"
41
+ #: Reset the filter-life counter.
42
+ CMD_RESET_FILTER = b"VMWH0417744"
43
+
44
+ #: Reply returned by the unit on a successful write command.
45
+ RESPONSE_OK = "OK"
46
+
47
+ #: Sensor scaling: raw integers are tenths of a unit (e.g. ``281`` -> ``28.1``).
48
+ SENSOR_SCALE = 10
49
+
50
+ #: Raw values at or above this are interpreted as signed 16-bit (negative temps).
51
+ SIGNED_16_THRESHOLD = 32768
52
+ SIGNED_16_MODULUS = 65536
53
+
54
+
55
+ class FanMode(IntEnum):
56
+ """Operating mode reported by status field 1 and set via ``VMWH000000<n>``."""
57
+
58
+ OFF = 0
59
+ LOW = 1
60
+ MEDIUM = 2
61
+ HIGH = 3
62
+ MAX = 4
63
+ BOOST = 5 # AirGuard "HyperVentilation"
64
+ NIGHT = 6
65
+ FREE_COOLING = 7
66
+
67
+ @property
68
+ def command(self) -> bytes:
69
+ """The ``VMWH`` write command that selects this mode."""
70
+ return f"VMWH000000{self.value}".encode("ascii")
71
+
72
+
73
+ #: Modes that represent a discrete fan speed (as opposed to a preset program).
74
+ SPEED_MODES: tuple[FanMode, ...] = (
75
+ FanMode.OFF,
76
+ FanMode.LOW,
77
+ FanMode.MEDIUM,
78
+ FanMode.HIGH,
79
+ FanMode.MAX,
80
+ )
81
+
82
+ #: Modes that represent a preset program.
83
+ PRESET_MODES: tuple[FanMode, ...] = (
84
+ FanMode.BOOST,
85
+ FanMode.NIGHT,
86
+ FanMode.FREE_COOLING,
87
+ )
88
+
89
+ #: Raw value of status field 2 (LED) meaning "on".
90
+ LED_ON_VALUE = 10
pyhelty/exceptions.py ADDED
@@ -0,0 +1,19 @@
1
+ """Exceptions raised by :mod:`pyhelty`."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ class HeltyError(Exception):
7
+ """Base class for all pyhelty errors."""
8
+
9
+
10
+ class HeltyConnectionError(HeltyError):
11
+ """Raised when the unit cannot be reached or times out."""
12
+
13
+
14
+ class HeltyResponseError(HeltyError):
15
+ """Raised when the unit returns a malformed or unexpected response."""
16
+
17
+
18
+ class HeltyCommandError(HeltyError):
19
+ """Raised when a write command is not acknowledged with ``OK``."""
pyhelty/models.py ADDED
@@ -0,0 +1,33 @@
1
+ """Data models for :mod:`pyhelty`."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from .const import FanMode
8
+
9
+
10
+ @dataclass(frozen=True, slots=True)
11
+ class HeltyData:
12
+ """A snapshot of the unit's sensors and operating status.
13
+
14
+ ``raw_sensors`` and ``raw_status`` hold the full integer field lists from
15
+ the ``VMGI``/``VMGO`` replies so that callers can decode additional,
16
+ not-yet-identified fields without a library change.
17
+ """
18
+
19
+ name: str
20
+ fan_mode: FanMode
21
+ leds_on: bool
22
+ indoor_temperature: float | None
23
+ outdoor_temperature: float | None
24
+ indoor_humidity: float | None
25
+ raw_sensors: tuple[int, ...]
26
+ raw_status: tuple[int, ...]
27
+
28
+ @property
29
+ def is_preset(self) -> bool:
30
+ """True when the current mode is a preset program rather than a speed."""
31
+ from .const import PRESET_MODES
32
+
33
+ return self.fan_mode in PRESET_MODES
pyhelty/py.typed ADDED
File without changes
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyhelty
3
+ Version: 0.1.0
4
+ Summary: Async client library for Helty Flow VMC (mechanical ventilation) units with the smart Wi-Fi interface
5
+ Project-URL: Homepage, https://github.com/ebaschiera/pyhelty
6
+ Project-URL: Source, https://github.com/ebaschiera/pyhelty
7
+ Project-URL: Issues, https://github.com/ebaschiera/pyhelty/issues
8
+ Author-email: Ermanno Baschiera <ebaschiera@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: asyncio,helty,home-assistant,mvhr,ventilation,vmc
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Home Automation
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Provides-Extra: dev
24
+ Requires-Dist: mypy>=1.11; extra == 'dev'
25
+ Requires-Dist: ruff>=0.6; extra == 'dev'
26
+ Provides-Extra: test
27
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
28
+ Requires-Dist: pytest-cov>=5.0; extra == 'test'
29
+ Requires-Dist: pytest>=8.0; extra == 'test'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # pyhelty
33
+
34
+ Async Python client for **Helty Flow** VMC (mechanical ventilation / MVHR) units
35
+ equipped with the smart Wi-Fi interface, such as the *Flow Plus*.
36
+
37
+ It speaks the unit's reverse-engineered TCP protocol (default port **5001**) and
38
+ exposes a small, fully typed `asyncio` API. It is the device-communication layer
39
+ behind the Home Assistant `helty` integration; it has **no** Home Assistant
40
+ dependency and can be used standalone.
41
+
42
+ > The protocol has no official specification. Behaviour is reverse-engineered
43
+ > from a real Helty FlowPlus; your mileage may vary on other models.
44
+
45
+ ## Install
46
+
47
+ ```bash
48
+ pip install pyhelty
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ ```python
54
+ import asyncio
55
+ from pyhelty import HeltyClient, FanMode
56
+
57
+ async def main() -> None:
58
+ client = HeltyClient("192.168.1.50") # port defaults to 5001
59
+
60
+ data = await client.async_get_data()
61
+ print(data.name, data.fan_mode, data.indoor_temperature, data.indoor_humidity)
62
+
63
+ await client.async_set_fan_mode(FanMode.NIGHT)
64
+ await client.async_set_led(False)
65
+
66
+ asyncio.run(main())
67
+ ```
68
+
69
+ ## API
70
+
71
+ - `HeltyClient(host, port=5001, *, timeout=10.0)`
72
+ - `async_get_name() -> str` — the user-assigned name (also used as a stable id)
73
+ - `async_get_data() -> HeltyData` — name, fan mode, LED state, indoor/outdoor
74
+ temperature, indoor humidity, plus the raw `VMGI`/`VMGO` integer fields for
75
+ fields not yet decoded
76
+ - `async_set_fan_mode(mode: FanMode)` — `OFF, LOW, MEDIUM, HIGH, MAX, BOOST,
77
+ NIGHT, FREE_COOLING`
78
+ - `async_set_led(on: bool)`
79
+ - `async_reset_filter()`
80
+
81
+ Errors derive from `HeltyError`: `HeltyConnectionError`, `HeltyResponseError`,
82
+ `HeltyCommandError`.
83
+
84
+ ## Protocol notes
85
+
86
+ | Command | Purpose | Reply |
87
+ |---|---|---|
88
+ | `VMNM?` | device name | `VMNM <name>` |
89
+ | `VMGI?` | sensors (15 fields, tenths) | `VMGI,<indoor_t>,<outdoor_t>,<indoor_rh>,...` |
90
+ | `VMGH?` | status (15 fields) | `VMGO,<fan_mode>,<led>,...` |
91
+ | `VMWH000000<n>` | set fan mode `n` (0-7) | `OK` |
92
+ | `VMWH0100010` / `VMWH0100000` | LED on / off | `OK` |
93
+ | `VMWH0417744` | reset filter counter | `OK` |
94
+
95
+ The unit serves one command per TCP connection and then closes it; the client
96
+ serialises commands with a lock.
97
+
98
+ ## Development
99
+
100
+ ```bash
101
+ pip install -e ".[test,dev]"
102
+ pytest
103
+ ruff check .
104
+ mypy src
105
+ ```
106
+
107
+ ## License
108
+
109
+ MIT
@@ -0,0 +1,10 @@
1
+ pyhelty/__init__.py,sha256=P0EoaBRd5gU-e7zKso5N5km1tGnQ3XNwoA1PeQh5Sag,587
2
+ pyhelty/client.py,sha256=v1DMmKwTADOSmW_vqxrkqsozLDUP_PET8x5KUgAoWzA,6605
3
+ pyhelty/const.py,sha256=3f_PpIdnkuf4-iPkmJ55FXg7QgahdHysrFtxIrDUt2U,2576
4
+ pyhelty/exceptions.py,sha256=s4TdAvlIV6i7TOfinV9vawioNvtbPuUxwLU5E-hAjNk,485
5
+ pyhelty/models.py,sha256=kc4YmXPF0wX-uxzKm3wzkqTokx8RSoJwfwLyI7ZVlZE,915
6
+ pyhelty/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ pyhelty-0.1.0.dist-info/METADATA,sha256=rTm853IDzQUKXc54_Wbi6lqmwxhq7MoxvRblWhKpDmw,3519
8
+ pyhelty-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
9
+ pyhelty-0.1.0.dist-info/licenses/LICENSE,sha256=32Lok91VHOSzOcH_3yzT7o-OybwTYMAxHqyBzZZNh_8,1074
10
+ pyhelty-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ermanno Baschiera
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.