python-pironman 0.1.0__py3-none-any.whl → 0.2.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.
pironman/client.py CHANGED
@@ -118,3 +118,148 @@ class PironmanClient:
118
118
  """Return typed device identity and capability metadata."""
119
119
  data = await self.async_get_device_info()
120
120
  return PironmanDeviceInfo.from_api(data)
121
+
122
+ async def async_post(
123
+ self,
124
+ endpoint: str,
125
+ payload: dict[str, Any],
126
+ ) -> dict[str, Any]:
127
+ """Execute a supported write operation without automatic retries."""
128
+ supported = {
129
+ "set-fan-mode",
130
+ "set-fan-led",
131
+ "set-rgb-enable",
132
+ "set-rgb-color",
133
+ "set-rgb-brightness",
134
+ "set-rgb-style",
135
+ "set-rgb-speed",
136
+ "set-oled-enable",
137
+ "set-oled-rotation",
138
+ "set-oled-pages",
139
+ "set-oled-sleep-timeout",
140
+ }
141
+
142
+ if endpoint not in supported:
143
+ raise ValueError("Unsupported Pironman write endpoint")
144
+
145
+ try:
146
+ async with self._session.post(
147
+ self._base_url / endpoint,
148
+ json=payload,
149
+ timeout=self._timeout,
150
+ allow_redirects=False,
151
+ ) as response:
152
+ if not 200 <= response.status < 300:
153
+ raise PironmanAPIError(f"{endpoint}: HTTP {response.status}")
154
+
155
+ try:
156
+ result = await response.json()
157
+ except (ValueError, aiohttp.ContentTypeError) as err:
158
+ raise PironmanResponseError(f"{endpoint}: invalid JSON") from err
159
+
160
+ except TimeoutError as err:
161
+ raise PironmanTimeoutError(f"{endpoint}: request timed out") from err
162
+
163
+ except aiohttp.ClientError as err:
164
+ raise PironmanConnectionError(f"{endpoint}: connection failed") from err
165
+
166
+ if not isinstance(result, dict):
167
+ raise PironmanResponseError(f"{endpoint}: expected JSON object")
168
+
169
+ if result.get("status") is not True:
170
+ raise PironmanAPIError(f"{endpoint}: unsuccessful API status")
171
+
172
+ return cast(dict[str, Any], result)
173
+
174
+ async def async_set_fan_mode(self, mode: int) -> dict[str, Any]:
175
+ """Set the GPIO fan operating mode."""
176
+ if type(mode) is not int or mode not in range(5):
177
+ raise ValueError("Fan mode must be an integer from 0 to 4")
178
+
179
+ return await self.async_post("set-fan-mode", {"fan_mode": mode})
180
+
181
+ async def async_set_fan_led(self, mode: str) -> dict[str, Any]:
182
+ """Set the GPIO fan LED mode."""
183
+ if mode not in ("on", "off", "follow"):
184
+ raise ValueError("Unsupported fan LED mode")
185
+
186
+ return await self.async_post("set-fan-led", {"led": mode})
187
+
188
+ async def async_set_rgb_enabled(self, enabled: bool) -> dict[str, Any]:
189
+ """Enable or disable RGB lighting."""
190
+ if not isinstance(enabled, bool):
191
+ raise ValueError("RGB enabled must be boolean")
192
+
193
+ return await self.async_post("set-rgb-enable", {"enable": enabled})
194
+
195
+ async def async_set_rgb_color(self, color: str) -> dict[str, Any]:
196
+ """Set an RGB color in hexadecimal notation."""
197
+ if (
198
+ not isinstance(color, str)
199
+ or len(color) != 7
200
+ or not color.startswith("#")
201
+ or any(c not in "0123456789abcdefABCDEF" for c in color[1:])
202
+ ):
203
+ raise ValueError("RGB color must use #RRGGBB notation")
204
+
205
+ return await self.async_post("set-rgb-color", {"color": color.lower()})
206
+
207
+ async def async_set_rgb_brightness(self, brightness: int) -> dict[str, Any]:
208
+ """Set RGB brightness from 0 to 100."""
209
+ if type(brightness) is not int or not 0 <= brightness <= 100:
210
+ raise ValueError("Brightness must be an integer from 0 to 100")
211
+
212
+ return await self.async_post("set-rgb-brightness", {"brightness": brightness})
213
+
214
+ async def async_set_rgb_style(self, style: str) -> dict[str, Any]:
215
+ """Set the RGB animation style."""
216
+ if style not in (
217
+ "solid",
218
+ "breathing",
219
+ "flow",
220
+ "flow_reverse",
221
+ "rainbow",
222
+ "rainbow_reverse",
223
+ "hue_cycle",
224
+ ):
225
+ raise ValueError("Unsupported RGB style")
226
+
227
+ return await self.async_post("set-rgb-style", {"style": style})
228
+
229
+ async def async_set_rgb_speed(self, speed: int) -> dict[str, Any]:
230
+ """Set RGB effect speed from 0 to 100."""
231
+ if type(speed) is not int or not 0 <= speed <= 100:
232
+ raise ValueError("RGB speed must be an integer from 0 to 100")
233
+
234
+ return await self.async_post("set-rgb-speed", {"speed": speed})
235
+
236
+ async def async_set_oled_enabled(self, enabled: bool) -> dict[str, Any]:
237
+ """Enable or disable the OLED display."""
238
+ if not isinstance(enabled, bool):
239
+ raise ValueError("OLED enabled must be boolean")
240
+
241
+ return await self.async_post("set-oled-enable", {"enable": enabled})
242
+
243
+ async def async_set_oled_rotation(self, rotation: int) -> dict[str, Any]:
244
+ """Set OLED rotation to 0 or 180 degrees."""
245
+ if type(rotation) is not int or rotation not in (0, 180):
246
+ raise ValueError("OLED rotation must be 0 or 180")
247
+
248
+ return await self.async_post("set-oled-rotation", {"rotation": rotation})
249
+
250
+ async def async_set_oled_pages(self, pages: list[str]) -> dict[str, Any]:
251
+ """Set the OLED page sequence."""
252
+ if not isinstance(pages, list) or not pages:
253
+ raise ValueError("OLED pages must be a non-empty list")
254
+
255
+ if not all(page in ("mix", "performance", "ips", "disk") for page in pages):
256
+ raise ValueError("Unsupported OLED page")
257
+
258
+ return await self.async_post("set-oled-pages", {"pages": pages})
259
+
260
+ async def async_set_oled_sleep_timeout(self, timeout: int) -> dict[str, Any]:
261
+ """Set OLED sleep timeout in seconds."""
262
+ if type(timeout) is not int or timeout < 0:
263
+ raise ValueError("OLED timeout must be a non-negative integer")
264
+
265
+ return await self.async_post("set-oled-sleep-timeout", {"timeout": timeout})
@@ -0,0 +1,255 @@
1
+ Metadata-Version: 2.5
2
+ Name: python-pironman
3
+ Version: 0.2.0
4
+ Summary: Async Python client for the SunFounder Pironman REST API
5
+ Project-URL: Repository, https://github.com/ChristophKomenda/python-pironman
6
+ Project-URL: Issues, https://github.com/ChristophKomenda/python-pironman/issues
7
+ Author: Christoph Komenda
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.12
14
+ Requires-Dist: aiohttp<4,>=3.10
15
+ Requires-Dist: yarl<2,>=1.12
16
+ Provides-Extra: test
17
+ Requires-Dist: build; extra == 'test'
18
+ Requires-Dist: mypy; extra == 'test'
19
+ Requires-Dist: pytest; extra == 'test'
20
+ Requires-Dist: pytest-asyncio; extra == 'test'
21
+ Requires-Dist: pytest-cov; extra == 'test'
22
+ Requires-Dist: ruff; extra == 'test'
23
+ Requires-Dist: twine; extra == 'test'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Python Pironman
27
+
28
+ [![PyPI](https://img.shields.io/pypi/v/python-pironman)](https://pypi.org/project/python-pironman/)
29
+ [![Python](https://img.shields.io/pypi/pyversions/python-pironman)](https://pypi.org/project/python-pironman/)
30
+ [![Tests](https://github.com/ChristophKomenda/python-pironman/actions/workflows/tests.yml/badge.svg)](https://github.com/ChristophKomenda/python-pironman/actions/workflows/tests.yml)
31
+ [![License](https://img.shields.io/github/license/ChristophKomenda/python-pironman)](LICENSE)
32
+ [![GitHub Release](https://img.shields.io/github/v/release/ChristophKomenda/python-pironman)](https://github.com/ChristophKomenda/python-pironman/releases)
33
+
34
+ An independent asynchronous Python library for the local
35
+ SunFounder Pironman hardware REST API.
36
+
37
+ Designed for Home Assistant integrations, local monitoring
38
+ and independent Python applications.
39
+
40
+ ## Features
41
+
42
+ - Asynchronous HTTP communication using aiohttp.
43
+ - Local REST API access without cloud dependencies.
44
+ - Typed device identity and capability metadata.
45
+ - Automatic Pironman model detection.
46
+ - Optional vendor-provided persistent device identity.
47
+ - Structured API, connection and timeout exceptions.
48
+ - IPv4 and IPv6 support.
49
+ - Externally managed HTTP sessions.
50
+ - Hardware monitoring and explicit device controls.
51
+ - No Home Assistant dependency.
52
+
53
+ ## Installation
54
+
55
+ Requires Python 3.12 or newer.
56
+
57
+ Install from PyPI, preferably in a virtual environment:
58
+
59
+ python -m pip install python-pironman
60
+
61
+ Install a specific version:
62
+
63
+ python -m pip install python-pironman==0.2.0
64
+
65
+ - [PyPI package](https://pypi.org/project/python-pironman/)
66
+ - [Initial release v0.1.0](https://github.com/ChristophKomenda/python-pironman/releases/tag/v0.1.0)
67
+
68
+ ## Quick start
69
+
70
+ Create a Python script using the following example:
71
+
72
+ import asyncio
73
+ import aiohttp
74
+
75
+ from pironman import PironmanClient
76
+
77
+
78
+ async def main():
79
+ async with aiohttp.ClientSession() as session:
80
+ client = PironmanClient("192.0.2.10", session)
81
+
82
+ info = await client.async_get_device_metadata()
83
+ measurements = await client.async_get_data()
84
+
85
+ print(info.name)
86
+ print(info.model)
87
+ print(info.version)
88
+ print(measurements)
89
+
90
+
91
+ asyncio.run(main())
92
+
93
+ Replace the example address with the actual Pironman host.
94
+
95
+ The default REST API port is 34001.
96
+
97
+ The caller owns the aiohttp ClientSession.
98
+ The library never closes externally managed sessions.
99
+
100
+ ## Supported REST endpoints
101
+
102
+ | Method | Endpoint |
103
+ | --- | --- |
104
+ | GET | /api/v1.0/get-device-info |
105
+ | GET | /api/v1.0/get-data |
106
+ | GET | /api/v1.0/get-config |
107
+ | GET | /api/v1.0/get-ips |
108
+
109
+ The network endpoint may not be available on older
110
+ firmware versions.
111
+
112
+ GET methods do not modify hardware settings.
113
+ Explicit write methods are documented separately.
114
+
115
+ ## Hardware controls
116
+
117
+ Version 0.2.0 introduces explicit asynchronous write methods
118
+ for fan, RGB and OLED controls.
119
+
120
+ Examples of supported methods:
121
+
122
+ await client.async_set_rgb_brightness(50)
123
+ await client.async_set_oled_enabled(True)
124
+ await client.async_set_fan_mode(3)
125
+
126
+ These examples change hardware settings.
127
+
128
+ Always verify device capabilities before performing writes.
129
+
130
+ See [Write API](docs/write-api.md).
131
+
132
+ ## Device identity and capabilities
133
+
134
+ Typed device metadata is available through
135
+ async_get_device_metadata.
136
+
137
+ Recognized model identifiers include:
138
+
139
+ | Model | Recognition | Physical validation |
140
+ | --- | --- | --- |
141
+ | Pironman 5 | Supported | Not yet tested |
142
+ | Pironman 5 Mini | Supported | Not yet tested |
143
+ | Pironman 5 Max | Supported | Passed |
144
+ | Pironman 5 Pro Max | Supported | Not yet tested |
145
+
146
+ Model recognition does not establish hardware compatibility.
147
+
148
+ Capability checks distinguish supported, unsupported
149
+ and unknown peripherals.
150
+
151
+ Examples of vendor capability names include oled,
152
+ ws2812 and storage.
153
+
154
+ Persistent device UID support is optional.
155
+
156
+ Model identifiers are never used as physical device IDs.
157
+ No synthetic persistent hardware identifiers are generated.
158
+
159
+ See [Device identity](docs/device-identity.md).
160
+
161
+ ## Hardware validation
162
+
163
+ Version 0.1.0 was validated on two separate physical
164
+ Pironman 5 Max devices running API version 1.3.21.
165
+
166
+ | Validation | Device A | Device B |
167
+ | --- | --- | --- |
168
+ | Connection | Local | Remote LAN |
169
+ | Measurement fields | 36 | 47 |
170
+ | Read-only REST API | Passed | Passed |
171
+ | Model detection | Passed | Passed |
172
+ | OLED capability | Supported | Supported |
173
+ | WS2812 capability | Supported | Supported |
174
+ | Storage capability | Supported | Supported |
175
+
176
+ The published PyPI package was installed in a clean
177
+ Python environment and tested against both devices.
178
+
179
+ See [Hardware validation](docs/hardware-validation.md).
180
+
181
+ ## Quality and testing
182
+
183
+ The initial release includes:
184
+
185
+ - 85 automated tests.
186
+ - 100 percent statement coverage.
187
+ - Python 3.12, 3.13 and 3.14 CI testing.
188
+ - Strict mypy type checking.
189
+ - Ruff linting and formatting.
190
+ - Real local HTTP integration tests.
191
+ - Wheel and source distribution validation.
192
+ - Clean package installation testing.
193
+ - Automated PyPI Trusted Publishing.
194
+
195
+ Statement coverage does not guarantee complete
196
+ branch coverage or absence of defects.
197
+
198
+ ## Development
199
+
200
+ Clone the repository:
201
+
202
+ git clone https://github.com/ChristophKomenda/python-pironman.git
203
+ cd python-pironman
204
+
205
+ Create a development environment:
206
+
207
+ python -m venv .venv
208
+ source .venv/bin/activate
209
+ python -m pip install -e ".[test]"
210
+
211
+ Run the test suite:
212
+
213
+ pytest --cov=pironman --cov-report=term-missing
214
+
215
+ Read hardware data:
216
+
217
+ python examples/read_device.py 192.0.2.10
218
+
219
+ Read typed hardware metadata:
220
+
221
+ python examples/read_metadata.py 192.0.2.10
222
+
223
+ ## Documentation
224
+
225
+ - [Architecture](docs/architecture.md)
226
+ - [Device identity](docs/device-identity.md)
227
+ - [Hardware validation](docs/hardware-validation.md)
228
+ - [Release process](docs/releasing.md)
229
+ - [Contributing](CONTRIBUTING.md)
230
+ - [Security policy](SECURITY.md)
231
+
232
+ ## Ecosystem
233
+
234
+ - [Pironman Home Assistant HACS integration](https://github.com/ChristophKomenda/pironman5-homeassistant-container)
235
+ - [SunFounder Pironman software](https://github.com/sunfounder/pironman5)
236
+ - [Upstream device identity proposal](https://github.com/sunfounder/pironman5/pull/130)
237
+
238
+ The long-term goal is to support an official Home Assistant
239
+ Core integration through this standalone library.
240
+
241
+ This is an independently maintained project.
242
+ It is not an official SunFounder or Home Assistant product.
243
+
244
+ ## License
245
+
246
+ MIT
247
+
248
+ ### Version 0.2.0 validation
249
+
250
+ - All 15 implemented REST endpoints exercised on two
251
+ physical Pironman 5 Max devices.
252
+ - 126 passing automated tests.
253
+ - 100 percent statement coverage.
254
+ - 20 changed settings successfully restored.
255
+ - Fan mode validated using same-value writes.
@@ -1,11 +1,11 @@
1
1
  pironman/__init__.py,sha256=1hzotHm4HH1WmgwHFugCtmwlP9wXxAcctTLyxySF0Ns,483
2
- pironman/client.py,sha256=000SNhM9Znx0HFM7MO5MLiGsRedaAaOhV9qkB3DWWj8,4002
2
+ pironman/client.py,sha256=yq9Ofl9LVq5x5UdS0kbEF2mXYmw4EkcatqFHAA3-6jY,9802
3
3
  pironman/const.py,sha256=DOSh-q7xjA-0eIuSrM7l-EmVtsvXWV4HUO7kw8f4Q0Y,110
4
4
  pironman/device.py,sha256=1lvDbTV1vo2CUbASEv1cbi1vEpWseWP3aGLKMqGrL_w,1953
5
5
  pironman/exceptions.py,sha256=fhplb1NznlnUv3JJVrLp-h4-38xetE7hxz2-ks07u_U,492
6
6
  pironman/models.py,sha256=NQhquAnMej2oDqwa1aTodgRkPt5R9CEFGYBw_jV6u3U,2064
7
7
  pironman/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- python_pironman-0.1.0.dist-info/METADATA,sha256=2r2eUbeIrV34zWPsQwD-ENDMFV24cjTAy9CILfxLknE,3046
9
- python_pironman-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
10
- python_pironman-0.1.0.dist-info/licenses/LICENSE,sha256=3Cl9k97yBvPE1FEawGirCcRiCMCMp9OoVommYAl77u4,1074
11
- python_pironman-0.1.0.dist-info/RECORD,,
8
+ python_pironman-0.2.0.dist-info/METADATA,sha256=ZmuA6T7SWZ7j4HNfgIPANsbmQAjQDXJV5mDU2GVQoQM,7593
9
+ python_pironman-0.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
10
+ python_pironman-0.2.0.dist-info/licenses/LICENSE,sha256=3Cl9k97yBvPE1FEawGirCcRiCMCMp9OoVommYAl77u4,1074
11
+ python_pironman-0.2.0.dist-info/RECORD,,
@@ -1,101 +0,0 @@
1
- Metadata-Version: 2.5
2
- Name: python-pironman
3
- Version: 0.1.0
4
- Summary: Async Python client for the SunFounder Pironman REST API
5
- Project-URL: Repository, https://github.com/ChristophKomenda/python-pironman
6
- Project-URL: Issues, https://github.com/ChristophKomenda/python-pironman/issues
7
- Author: Christoph Komenda
8
- License-Expression: MIT
9
- License-File: LICENSE
10
- Classifier: Development Status :: 2 - Pre-Alpha
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Typing :: Typed
13
- Requires-Python: >=3.12
14
- Requires-Dist: aiohttp<4,>=3.10
15
- Requires-Dist: yarl<2,>=1.12
16
- Provides-Extra: test
17
- Requires-Dist: build; extra == 'test'
18
- Requires-Dist: mypy; extra == 'test'
19
- Requires-Dist: pytest; extra == 'test'
20
- Requires-Dist: pytest-asyncio; extra == 'test'
21
- Requires-Dist: pytest-cov; extra == 'test'
22
- Requires-Dist: ruff; extra == 'test'
23
- Requires-Dist: twine; extra == 'test'
24
- Description-Content-Type: text/markdown
25
-
26
- # Python Pironman
27
-
28
- An independent asynchronous Python library for the local
29
- SunFounder Pironman hardware REST API.
30
-
31
- ## Project goals
32
-
33
- - Asynchronous HTTP communication using aiohttp.
34
- - Typed device metadata and hardware capabilities.
35
- - Read-only monitoring as the initial implementation.
36
- - Support for externally managed HTTP sessions.
37
- - Consistent API error handling.
38
- - Automated tests and hardware validation.
39
- - Reusable by Home Assistant and other Python applications.
40
-
41
- ## Status
42
-
43
- Version 0.1.0 is prepared for initial publication on PyPI.
44
-
45
- Physical hardware validation has been completed on two Pironman 5 Max devices running API version 1.3.21.
46
-
47
- Recognition of other Pironman models does not establish verified hardware compatibility.
48
-
49
- This project is independently maintained and is not an
50
- official SunFounder or Home Assistant integration.
51
-
52
- ## Usage
53
-
54
- Install the development package in a virtual environment:
55
-
56
- pip install -e .
57
-
58
- Read basic device information:
59
-
60
- python examples/read_device.py 192.0.2.10
61
-
62
- Replace the example address with the actual Pironman host.
63
-
64
- The caller owns the aiohttp ClientSession.
65
- The library never closes externally managed sessions.
66
-
67
- ### Supported endpoints
68
-
69
- - GET /api/v1.0/get-device-info
70
- - GET /api/v1.0/get-data
71
- - GET /api/v1.0/get-config
72
- - GET /api/v1.0/get-ips
73
-
74
- The initial implementation is read-only.
75
- No Home Assistant dependency is required.
76
-
77
- The network endpoint is optional on older API versions.
78
- Persistent device identity remains pending upstream review.
79
-
80
- ## Device identity and capabilities
81
-
82
- Read typed device metadata using:
83
-
84
- python examples/read_metadata.py 192.0.2.10
85
-
86
- Persistent device UID support is optional.
87
-
88
- Model identifiers are never used as physical device IDs.
89
- Missing capability information is represented as unknown.
90
-
91
- See [Device identity](docs/device-identity.md).
92
-
93
- ## Related projects
94
-
95
- - [Pironman HACS integration](https://github.com/ChristophKomenda/pironman5-homeassistant-container)
96
- - [SunFounder Pironman software](https://github.com/sunfounder/pironman5)
97
- - [Upstream device identity proposal](https://github.com/sunfounder/pironman5/pull/130)
98
-
99
- ## License
100
-
101
- MIT