pyopenhwmon 0.1.0__tar.gz
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.
- pyopenhwmon-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +35 -0
- pyopenhwmon-0.1.0/.github/ISSUE_TEMPLATE/config.yml +5 -0
- pyopenhwmon-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +23 -0
- pyopenhwmon-0.1.0/.github/workflows/ci.yml +43 -0
- pyopenhwmon-0.1.0/.github/workflows/publish.yml +32 -0
- pyopenhwmon-0.1.0/.gitignore +32 -0
- pyopenhwmon-0.1.0/.pre-commit-config.yaml +16 -0
- pyopenhwmon-0.1.0/LICENSE.md +21 -0
- pyopenhwmon-0.1.0/PKG-INFO +256 -0
- pyopenhwmon-0.1.0/README.md +222 -0
- pyopenhwmon-0.1.0/pyopenhwmon/__init__.py +35 -0
- pyopenhwmon-0.1.0/pyopenhwmon/client.py +161 -0
- pyopenhwmon-0.1.0/pyopenhwmon/exceptions.py +68 -0
- pyopenhwmon-0.1.0/pyopenhwmon/models.py +65 -0
- pyopenhwmon-0.1.0/pyopenhwmon/parsing.py +170 -0
- pyopenhwmon-0.1.0/pyopenhwmon/py.typed +0 -0
- pyopenhwmon-0.1.0/pyproject.toml +100 -0
- pyopenhwmon-0.1.0/tests/__init__.py +1 -0
- pyopenhwmon-0.1.0/tests/conftest.py +75 -0
- pyopenhwmon-0.1.0/tests/fixtures/data.json +173 -0
- pyopenhwmon-0.1.0/tests/test_client.py +284 -0
- pyopenhwmon-0.1.0/tests/test_exceptions.py +71 -0
- pyopenhwmon-0.1.0/tests/test_models.py +76 -0
- pyopenhwmon-0.1.0/tests/test_parsing.py +270 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Bug report
|
|
2
|
+
description: Report a problem with pyopenhwmon
|
|
3
|
+
title: "[bug]: "
|
|
4
|
+
labels: ["bug"]
|
|
5
|
+
body:
|
|
6
|
+
- type: markdown
|
|
7
|
+
attributes:
|
|
8
|
+
value: |
|
|
9
|
+
Thanks for taking the time to fill out this bug report!
|
|
10
|
+
- type: textarea
|
|
11
|
+
id: description
|
|
12
|
+
attributes:
|
|
13
|
+
label: Description
|
|
14
|
+
description: A clear and concise description of the bug.
|
|
15
|
+
placeholder: What happened?
|
|
16
|
+
validations:
|
|
17
|
+
required: true
|
|
18
|
+
- type: textarea
|
|
19
|
+
id: reproduction
|
|
20
|
+
attributes:
|
|
21
|
+
label: Reproduction steps
|
|
22
|
+
description: Steps to reproduce the behavior.
|
|
23
|
+
placeholder: |
|
|
24
|
+
1. ...
|
|
25
|
+
2. ...
|
|
26
|
+
validations:
|
|
27
|
+
required: true
|
|
28
|
+
- type: textarea
|
|
29
|
+
id: environment
|
|
30
|
+
attributes:
|
|
31
|
+
label: Environment
|
|
32
|
+
description: Python version, pyopenhwmon version, and OHM server version.
|
|
33
|
+
placeholder: Python 3.13, pyopenhwmon 0.1.0, OHM 1.8
|
|
34
|
+
validations:
|
|
35
|
+
required: false
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Feature request
|
|
2
|
+
description: Suggest an idea or improvement for pyopenhwmon
|
|
3
|
+
title: "[feature]: "
|
|
4
|
+
labels: ["enhancement"]
|
|
5
|
+
body:
|
|
6
|
+
- type: markdown
|
|
7
|
+
attributes:
|
|
8
|
+
value: |
|
|
9
|
+
Thanks for suggesting an improvement!
|
|
10
|
+
- type: textarea
|
|
11
|
+
id: description
|
|
12
|
+
attributes:
|
|
13
|
+
label: Description
|
|
14
|
+
description: A clear and concise description of the feature.
|
|
15
|
+
validations:
|
|
16
|
+
required: true
|
|
17
|
+
- type: textarea
|
|
18
|
+
id: motivation
|
|
19
|
+
attributes:
|
|
20
|
+
label: Motivation
|
|
21
|
+
description: Why is this feature useful? How would you use it?
|
|
22
|
+
validations:
|
|
23
|
+
required: false
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
lint-and-test:
|
|
14
|
+
name: Python ${{ matrix.python-version }}
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
python-version: ["3.13", "3.14"]
|
|
20
|
+
steps:
|
|
21
|
+
- name: Check out repository
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
25
|
+
uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: ${{ matrix.python-version }}
|
|
28
|
+
cache: pip
|
|
29
|
+
|
|
30
|
+
- name: Install package and dev dependencies
|
|
31
|
+
run: python -m pip install -e ".[dev]"
|
|
32
|
+
|
|
33
|
+
- name: Lint (ruff check)
|
|
34
|
+
run: ruff check .
|
|
35
|
+
|
|
36
|
+
- name: Check formatting (ruff format)
|
|
37
|
+
run: ruff format --check .
|
|
38
|
+
|
|
39
|
+
- name: Type check (mypy --strict)
|
|
40
|
+
run: mypy
|
|
41
|
+
|
|
42
|
+
- name: Run tests (pytest, 100% coverage required)
|
|
43
|
+
run: pytest
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
name: Build and publish to PyPI
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write
|
|
14
|
+
contents: read
|
|
15
|
+
steps:
|
|
16
|
+
- name: Check out repository
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.13"
|
|
23
|
+
cache: pip
|
|
24
|
+
|
|
25
|
+
- name: Install build
|
|
26
|
+
run: python -m pip install build
|
|
27
|
+
|
|
28
|
+
- name: Build sdist and wheel
|
|
29
|
+
run: python -m build
|
|
30
|
+
|
|
31
|
+
- name: Publish to PyPI (trusted publishing)
|
|
32
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Notes (planning documents, not part of the package)
|
|
2
|
+
notes/
|
|
3
|
+
|
|
4
|
+
# Python
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*$py.class
|
|
8
|
+
*.egg-info/
|
|
9
|
+
.eggs/
|
|
10
|
+
build/
|
|
11
|
+
dist/
|
|
12
|
+
wheels/
|
|
13
|
+
|
|
14
|
+
# Virtual environments
|
|
15
|
+
.venv/
|
|
16
|
+
venv/
|
|
17
|
+
env/
|
|
18
|
+
|
|
19
|
+
# Testing / tooling caches
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.coverage
|
|
22
|
+
.coverage.*
|
|
23
|
+
htmlcov/
|
|
24
|
+
coverage.xml
|
|
25
|
+
.mypy_cache/
|
|
26
|
+
.ruff_cache/
|
|
27
|
+
|
|
28
|
+
# Editors / OS
|
|
29
|
+
.vscode/
|
|
30
|
+
.idea/
|
|
31
|
+
.DS_Store
|
|
32
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.17.6
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff
|
|
6
|
+
args: [--fix]
|
|
7
|
+
- id: ruff-format
|
|
8
|
+
|
|
9
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
10
|
+
rev: v1.14.1
|
|
11
|
+
hooks:
|
|
12
|
+
- id: mypy
|
|
13
|
+
files: ^(pyopenhwmon|tests)/
|
|
14
|
+
additional_dependencies:
|
|
15
|
+
- aiohttp>=3.14
|
|
16
|
+
- yarl
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MichaelMKKelly
|
|
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.
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pyopenhwmon
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async Python client for the Open Hardware Monitor (OHM) remote server
|
|
5
|
+
Project-URL: Homepage, https://github.com/MichaelMKKelly/pyopenhwmon
|
|
6
|
+
Project-URL: Repository, https://github.com/MichaelMKKelly/pyopenhwmon
|
|
7
|
+
Project-URL: Issues, https://github.com/MichaelMKKelly/pyopenhwmon/issues
|
|
8
|
+
Author: MichaelMKKelly
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE.md
|
|
11
|
+
Keywords: aiohttp,async,monitoring,ohm,open-hardware-monitor,sensors
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Home Automation
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.13
|
|
21
|
+
Requires-Dist: aiohttp>=3.14
|
|
22
|
+
Requires-Dist: yarl
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
29
|
+
Provides-Extra: test
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'test'
|
|
31
|
+
Requires-Dist: pytest-cov>=5; extra == 'test'
|
|
32
|
+
Requires-Dist: pytest>=8; extra == 'test'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# pyopenhwmon
|
|
36
|
+
|
|
37
|
+
An async, fully-typed Python client for the **Open Hardware Monitor (OHM)**
|
|
38
|
+
remote server. It fetches and parses the `/data.json` payload into immutable,
|
|
39
|
+
easy-to-work-with data models.
|
|
40
|
+
|
|
41
|
+
`pyopenhwmon` is purpose-built for the [Home Assistant Open Hardware Monitor
|
|
42
|
+
integration](https://www.home-assistant.io/integrations/openhardwaremonitor/)
|
|
43
|
+
and is also suitable for standalone use.
|
|
44
|
+
|
|
45
|
+
> **Scope:** This library targets **Open Hardware Monitor (OHM)** only.
|
|
46
|
+
> Libre Hardware Monitor (LHM) is a different application with a different API
|
|
47
|
+
> and is covered by a separate integration/library.
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- **Async** end-to-end, built on `aiohttp`.
|
|
52
|
+
- **Fully typed** with a `py.typed` marker; passes `mypy --strict`.
|
|
53
|
+
- **Immutable data models** (`frozen` dataclasses) that mirror the API without
|
|
54
|
+
over-interpreting it.
|
|
55
|
+
- **IPv6-safe** URL construction via `yarl`.
|
|
56
|
+
- **Tolerant parsing** — one malformed node never crashes an entire update.
|
|
57
|
+
- **Clear exception hierarchy** with a `transient` flag for retry decisions.
|
|
58
|
+
- **No hidden retries** — rate-limit `Retry-After` is surfaced to the caller.
|
|
59
|
+
- Accepts a **caller-provided `aiohttp.ClientSession`** (never closed by the
|
|
60
|
+
client) or manages its own.
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install pyopenhwmon
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Requires Python **3.13** or newer.
|
|
69
|
+
|
|
70
|
+
## Quick start (standalone)
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import asyncio
|
|
74
|
+
|
|
75
|
+
from pyopenhwmon import OHMClient
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async def main() -> None:
|
|
79
|
+
async with OHMClient("192.168.1.50") as client:
|
|
80
|
+
if not await client.ping():
|
|
81
|
+
print("OHM server not reachable")
|
|
82
|
+
return
|
|
83
|
+
data = await client.get_data()
|
|
84
|
+
for sensor in data.sensors:
|
|
85
|
+
print(sensor.unique_id, sensor.value, sensor.unit)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
asyncio.run(main())
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Using your own session
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import aiohttp
|
|
95
|
+
from pyopenhwmon import OHMClient
|
|
96
|
+
|
|
97
|
+
async with aiohttp.ClientSession() as session:
|
|
98
|
+
client = OHMClient("192.168.1.50", session=session)
|
|
99
|
+
data = await client.get_data()
|
|
100
|
+
# `session` is closed by the caller, not by `client`.
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Home Assistant
|
|
104
|
+
|
|
105
|
+
The Home Assistant integration uses this library as its data layer. A typical
|
|
106
|
+
`DataUpdateCoordinator` fetch:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from pyopenhwmon import OHMClient, OHMError
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
async def async_update_data():
|
|
113
|
+
try:
|
|
114
|
+
return await client.get_data()
|
|
115
|
+
except OHMError as err:
|
|
116
|
+
if err.transient:
|
|
117
|
+
raise UpdateFailed(...) from err
|
|
118
|
+
raise ConfigEntryError(...) from err
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The `transient` flag lets the coordinator distinguish retryable failures
|
|
122
|
+
(connection errors, timeouts, rate limits) from permanent ones (HTTP 404,
|
|
123
|
+
malformed data).
|
|
124
|
+
|
|
125
|
+
## API
|
|
126
|
+
|
|
127
|
+
### `OHMClient`
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
OHMClient(
|
|
131
|
+
host: str,
|
|
132
|
+
port: int = 8085,
|
|
133
|
+
*,
|
|
134
|
+
session: aiohttp.ClientSession | None = None,
|
|
135
|
+
scheme: str = "http",
|
|
136
|
+
timeout: float = 10.0,
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
| Member | Description |
|
|
141
|
+
| --- | --- |
|
|
142
|
+
| `await get_data() -> OHMData` | Fetch and parse the full data tree. |
|
|
143
|
+
| `await ping() -> bool` | Lightweight connectivity check (`True` on HTTP 200). |
|
|
144
|
+
| `await close() -> None` | Close the session if the client created it. |
|
|
145
|
+
| `url -> yarl.URL` | The absolute `/data.json` URL. |
|
|
146
|
+
|
|
147
|
+
`OHMClient` is an async context manager (`async with`).
|
|
148
|
+
|
|
149
|
+
### Data models
|
|
150
|
+
|
|
151
|
+
- `OHMData` — a full snapshot: `root_name`, `computers`, `sensors`.
|
|
152
|
+
- `Computer` — a computer node: `name`, `sensors`.
|
|
153
|
+
- `Sensor` — a single reading: `name`, `value`, `min`, `max`, `unit`,
|
|
154
|
+
`raw_value`, `computer`, `path`, `unique_id`.
|
|
155
|
+
|
|
156
|
+
All models are frozen dataclasses exposing `to_dict()` for diagnostics.
|
|
157
|
+
|
|
158
|
+
`Sensor.unique_id` is a stable, human-readable identifier built from the name
|
|
159
|
+
path, e.g. `TEST-PC/Intel Core i7-7700/Temperatures/CPU Core #1`.
|
|
160
|
+
|
|
161
|
+
### Exceptions
|
|
162
|
+
|
|
163
|
+
| Exception | Transient | Meaning |
|
|
164
|
+
| --- | --- | --- |
|
|
165
|
+
| `OHMError` | — | Base class. |
|
|
166
|
+
| `OHMConnectionError` | yes | DNS / refused / reset. |
|
|
167
|
+
| `OHMTimeoutError` | yes | Connect or read timeout. |
|
|
168
|
+
| `OHMHTTPError` | no | Unexpected 4xx/5xx status. |
|
|
169
|
+
| `OHMNotFoundError` | no | HTTP 404 (API disabled / wrong port). |
|
|
170
|
+
| `OHMRateLimitError` | yes | HTTP 429; exposes `retry_after`. |
|
|
171
|
+
| `OHMDataError` | no | Malformed payload. |
|
|
172
|
+
|
|
173
|
+
## The OHM `/data.json` payload
|
|
174
|
+
|
|
175
|
+
OHM serves a JSON tree at `GET /data.json` (no authentication, default port
|
|
176
|
+
`8085`). **Every node** carries the keys `id`, `Text`, `Children`, `Min`,
|
|
177
|
+
`Value`, `Max`, and `ImageURL`.
|
|
178
|
+
|
|
179
|
+
- The **root** node is hardcoded with `Text: "Sensor"` and the literal header
|
|
180
|
+
strings `Min: "Min"`, `Value: "Value"`, `Max: "Max"`.
|
|
181
|
+
- **Branch** nodes (computer / hardware / category) carry empty strings `""`
|
|
182
|
+
for `Min`/`Value`/`Max`.
|
|
183
|
+
- **Sensor leaves** carry real reading strings such as `"31.0 °C"`, or `"-"`
|
|
184
|
+
when there is no reading.
|
|
185
|
+
- There is **no `Type` field** in the payload.
|
|
186
|
+
- A node is a usable sensor iff it has no children and its `Value` contains a
|
|
187
|
+
space (i.e. looks like `<number> <unit>`).
|
|
188
|
+
- Locale decimal commas occur (e.g. `"29,0 °C"`).
|
|
189
|
+
|
|
190
|
+
Example (trimmed):
|
|
191
|
+
|
|
192
|
+
```json
|
|
193
|
+
{
|
|
194
|
+
"id": 0,
|
|
195
|
+
"Text": "Sensor",
|
|
196
|
+
"Children": [
|
|
197
|
+
{
|
|
198
|
+
"id": 1,
|
|
199
|
+
"Text": "TEST-PC",
|
|
200
|
+
"Children": [
|
|
201
|
+
{
|
|
202
|
+
"id": 2,
|
|
203
|
+
"Text": "Intel Core i7-7700",
|
|
204
|
+
"Children": [
|
|
205
|
+
{
|
|
206
|
+
"id": 3,
|
|
207
|
+
"Text": "Temperatures",
|
|
208
|
+
"Children": [
|
|
209
|
+
{
|
|
210
|
+
"id": 4,
|
|
211
|
+
"Text": "CPU Core #1",
|
|
212
|
+
"Children": [],
|
|
213
|
+
"Min": "0.0 °C",
|
|
214
|
+
"Value": "31.0 °C",
|
|
215
|
+
"Max": "100.0 °C",
|
|
216
|
+
"ImageURL": "images/transparent.png"
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
"Min": "",
|
|
220
|
+
"Value": "",
|
|
221
|
+
"Max": "",
|
|
222
|
+
"ImageURL": "images_icon/temperature.png"
|
|
223
|
+
}
|
|
224
|
+
],
|
|
225
|
+
"Min": "",
|
|
226
|
+
"Value": "",
|
|
227
|
+
"Max": "",
|
|
228
|
+
"ImageURL": "images_icon/cpu.png"
|
|
229
|
+
}
|
|
230
|
+
],
|
|
231
|
+
"Min": "",
|
|
232
|
+
"Value": "",
|
|
233
|
+
"Max": "",
|
|
234
|
+
"ImageURL": "images_icon/computer.png"
|
|
235
|
+
}
|
|
236
|
+
],
|
|
237
|
+
"Min": "Min",
|
|
238
|
+
"Value": "Value",
|
|
239
|
+
"Max": "Max",
|
|
240
|
+
"ImageURL": ""
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Development
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
python -m venv .venv
|
|
248
|
+
.venv/bin/pip install -e ".[dev]"
|
|
249
|
+
.venv/bin/pytest # runs the suite with 100% coverage gate
|
|
250
|
+
.venv/bin/ruff check .
|
|
251
|
+
.venv/bin/mypy
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
[MIT](LICENSE.md)
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# pyopenhwmon
|
|
2
|
+
|
|
3
|
+
An async, fully-typed Python client for the **Open Hardware Monitor (OHM)**
|
|
4
|
+
remote server. It fetches and parses the `/data.json` payload into immutable,
|
|
5
|
+
easy-to-work-with data models.
|
|
6
|
+
|
|
7
|
+
`pyopenhwmon` is purpose-built for the [Home Assistant Open Hardware Monitor
|
|
8
|
+
integration](https://www.home-assistant.io/integrations/openhardwaremonitor/)
|
|
9
|
+
and is also suitable for standalone use.
|
|
10
|
+
|
|
11
|
+
> **Scope:** This library targets **Open Hardware Monitor (OHM)** only.
|
|
12
|
+
> Libre Hardware Monitor (LHM) is a different application with a different API
|
|
13
|
+
> and is covered by a separate integration/library.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **Async** end-to-end, built on `aiohttp`.
|
|
18
|
+
- **Fully typed** with a `py.typed` marker; passes `mypy --strict`.
|
|
19
|
+
- **Immutable data models** (`frozen` dataclasses) that mirror the API without
|
|
20
|
+
over-interpreting it.
|
|
21
|
+
- **IPv6-safe** URL construction via `yarl`.
|
|
22
|
+
- **Tolerant parsing** — one malformed node never crashes an entire update.
|
|
23
|
+
- **Clear exception hierarchy** with a `transient` flag for retry decisions.
|
|
24
|
+
- **No hidden retries** — rate-limit `Retry-After` is surfaced to the caller.
|
|
25
|
+
- Accepts a **caller-provided `aiohttp.ClientSession`** (never closed by the
|
|
26
|
+
client) or manages its own.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install pyopenhwmon
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Requires Python **3.13** or newer.
|
|
35
|
+
|
|
36
|
+
## Quick start (standalone)
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
import asyncio
|
|
40
|
+
|
|
41
|
+
from pyopenhwmon import OHMClient
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def main() -> None:
|
|
45
|
+
async with OHMClient("192.168.1.50") as client:
|
|
46
|
+
if not await client.ping():
|
|
47
|
+
print("OHM server not reachable")
|
|
48
|
+
return
|
|
49
|
+
data = await client.get_data()
|
|
50
|
+
for sensor in data.sensors:
|
|
51
|
+
print(sensor.unique_id, sensor.value, sensor.unit)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
asyncio.run(main())
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Using your own session
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import aiohttp
|
|
61
|
+
from pyopenhwmon import OHMClient
|
|
62
|
+
|
|
63
|
+
async with aiohttp.ClientSession() as session:
|
|
64
|
+
client = OHMClient("192.168.1.50", session=session)
|
|
65
|
+
data = await client.get_data()
|
|
66
|
+
# `session` is closed by the caller, not by `client`.
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Home Assistant
|
|
70
|
+
|
|
71
|
+
The Home Assistant integration uses this library as its data layer. A typical
|
|
72
|
+
`DataUpdateCoordinator` fetch:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from pyopenhwmon import OHMClient, OHMError
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async def async_update_data():
|
|
79
|
+
try:
|
|
80
|
+
return await client.get_data()
|
|
81
|
+
except OHMError as err:
|
|
82
|
+
if err.transient:
|
|
83
|
+
raise UpdateFailed(...) from err
|
|
84
|
+
raise ConfigEntryError(...) from err
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The `transient` flag lets the coordinator distinguish retryable failures
|
|
88
|
+
(connection errors, timeouts, rate limits) from permanent ones (HTTP 404,
|
|
89
|
+
malformed data).
|
|
90
|
+
|
|
91
|
+
## API
|
|
92
|
+
|
|
93
|
+
### `OHMClient`
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
OHMClient(
|
|
97
|
+
host: str,
|
|
98
|
+
port: int = 8085,
|
|
99
|
+
*,
|
|
100
|
+
session: aiohttp.ClientSession | None = None,
|
|
101
|
+
scheme: str = "http",
|
|
102
|
+
timeout: float = 10.0,
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
| Member | Description |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| `await get_data() -> OHMData` | Fetch and parse the full data tree. |
|
|
109
|
+
| `await ping() -> bool` | Lightweight connectivity check (`True` on HTTP 200). |
|
|
110
|
+
| `await close() -> None` | Close the session if the client created it. |
|
|
111
|
+
| `url -> yarl.URL` | The absolute `/data.json` URL. |
|
|
112
|
+
|
|
113
|
+
`OHMClient` is an async context manager (`async with`).
|
|
114
|
+
|
|
115
|
+
### Data models
|
|
116
|
+
|
|
117
|
+
- `OHMData` — a full snapshot: `root_name`, `computers`, `sensors`.
|
|
118
|
+
- `Computer` — a computer node: `name`, `sensors`.
|
|
119
|
+
- `Sensor` — a single reading: `name`, `value`, `min`, `max`, `unit`,
|
|
120
|
+
`raw_value`, `computer`, `path`, `unique_id`.
|
|
121
|
+
|
|
122
|
+
All models are frozen dataclasses exposing `to_dict()` for diagnostics.
|
|
123
|
+
|
|
124
|
+
`Sensor.unique_id` is a stable, human-readable identifier built from the name
|
|
125
|
+
path, e.g. `TEST-PC/Intel Core i7-7700/Temperatures/CPU Core #1`.
|
|
126
|
+
|
|
127
|
+
### Exceptions
|
|
128
|
+
|
|
129
|
+
| Exception | Transient | Meaning |
|
|
130
|
+
| --- | --- | --- |
|
|
131
|
+
| `OHMError` | — | Base class. |
|
|
132
|
+
| `OHMConnectionError` | yes | DNS / refused / reset. |
|
|
133
|
+
| `OHMTimeoutError` | yes | Connect or read timeout. |
|
|
134
|
+
| `OHMHTTPError` | no | Unexpected 4xx/5xx status. |
|
|
135
|
+
| `OHMNotFoundError` | no | HTTP 404 (API disabled / wrong port). |
|
|
136
|
+
| `OHMRateLimitError` | yes | HTTP 429; exposes `retry_after`. |
|
|
137
|
+
| `OHMDataError` | no | Malformed payload. |
|
|
138
|
+
|
|
139
|
+
## The OHM `/data.json` payload
|
|
140
|
+
|
|
141
|
+
OHM serves a JSON tree at `GET /data.json` (no authentication, default port
|
|
142
|
+
`8085`). **Every node** carries the keys `id`, `Text`, `Children`, `Min`,
|
|
143
|
+
`Value`, `Max`, and `ImageURL`.
|
|
144
|
+
|
|
145
|
+
- The **root** node is hardcoded with `Text: "Sensor"` and the literal header
|
|
146
|
+
strings `Min: "Min"`, `Value: "Value"`, `Max: "Max"`.
|
|
147
|
+
- **Branch** nodes (computer / hardware / category) carry empty strings `""`
|
|
148
|
+
for `Min`/`Value`/`Max`.
|
|
149
|
+
- **Sensor leaves** carry real reading strings such as `"31.0 °C"`, or `"-"`
|
|
150
|
+
when there is no reading.
|
|
151
|
+
- There is **no `Type` field** in the payload.
|
|
152
|
+
- A node is a usable sensor iff it has no children and its `Value` contains a
|
|
153
|
+
space (i.e. looks like `<number> <unit>`).
|
|
154
|
+
- Locale decimal commas occur (e.g. `"29,0 °C"`).
|
|
155
|
+
|
|
156
|
+
Example (trimmed):
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"id": 0,
|
|
161
|
+
"Text": "Sensor",
|
|
162
|
+
"Children": [
|
|
163
|
+
{
|
|
164
|
+
"id": 1,
|
|
165
|
+
"Text": "TEST-PC",
|
|
166
|
+
"Children": [
|
|
167
|
+
{
|
|
168
|
+
"id": 2,
|
|
169
|
+
"Text": "Intel Core i7-7700",
|
|
170
|
+
"Children": [
|
|
171
|
+
{
|
|
172
|
+
"id": 3,
|
|
173
|
+
"Text": "Temperatures",
|
|
174
|
+
"Children": [
|
|
175
|
+
{
|
|
176
|
+
"id": 4,
|
|
177
|
+
"Text": "CPU Core #1",
|
|
178
|
+
"Children": [],
|
|
179
|
+
"Min": "0.0 °C",
|
|
180
|
+
"Value": "31.0 °C",
|
|
181
|
+
"Max": "100.0 °C",
|
|
182
|
+
"ImageURL": "images/transparent.png"
|
|
183
|
+
}
|
|
184
|
+
],
|
|
185
|
+
"Min": "",
|
|
186
|
+
"Value": "",
|
|
187
|
+
"Max": "",
|
|
188
|
+
"ImageURL": "images_icon/temperature.png"
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
"Min": "",
|
|
192
|
+
"Value": "",
|
|
193
|
+
"Max": "",
|
|
194
|
+
"ImageURL": "images_icon/cpu.png"
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"Min": "",
|
|
198
|
+
"Value": "",
|
|
199
|
+
"Max": "",
|
|
200
|
+
"ImageURL": "images_icon/computer.png"
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
"Min": "Min",
|
|
204
|
+
"Value": "Value",
|
|
205
|
+
"Max": "Max",
|
|
206
|
+
"ImageURL": ""
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Development
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
python -m venv .venv
|
|
214
|
+
.venv/bin/pip install -e ".[dev]"
|
|
215
|
+
.venv/bin/pytest # runs the suite with 100% coverage gate
|
|
216
|
+
.venv/bin/ruff check .
|
|
217
|
+
.venv/bin/mypy
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
[MIT](LICENSE.md)
|