um-smart-hub
Python library and hub CLI for the
UM Smart USB Hub.
Requires Python 3.14+; uses httpx2 and Typer.
CLI
From this directory, run uv run hub .... To install the CLI from PyPI:
uv tool install um-smart-hub
To install from a local checkout instead, use uv tool install ..
hub on 1 # turn port 1 on
hub off 1 # turn port 1 off
hub toggle 1 # read the current power state and flip it once
hub toggle 1 5 # flip immediately, then every 5 seconds until Ctrl+C
hub --host http://192.168.2.124 on 1
hub info # hub identity, supplies, sensors and hardware health
hub status # all six ports
hub status 6 # one port's details and next scheduled action
hub identify 6 # flash the port's LED without changing power
hub watch # refresh all port statuses every second
hub watch 6 --interval 0.5 # monitor one port until Ctrl+C
hub info --json
hub status 6 --json
hub watch 6 --json # one JSON snapshot per line
The default address is http://usb-hub.local. Override it with --host (before
any command) or HUB_HOST. If mDNS doesn't resolve from WSL, use the IP address.
Looping mode prints a start message rather than each transition. Ctrl+C stops
without switching the port off or restoring its original state.
info and status emit human-readable tables by default. watch refreshes a
table in an interactive terminal, or prints successive tables when redirected.
--json uses the library's normalized, unit-labelled fields, not raw firmware
field names: info and single-port status emit an object; all-port status
emits an array. Each watch --json line is one object (selected port) or array
(all ports). Diagnostics and the Ctrl+C message go to stderr, keeping stdout
machine-readable.
Python library
Install into another uv project:
uv add um-smart-hub
For local development, use uv add /absolute/path/to/hub instead.
from smart_hub import Hub
hub = Hub() # defaults to http://usb-hub.local
# hub = Hub("http://192.168.2.124")
hub.on(6)
hub.off(6)
enabled = hub.toggle(6) # a synchronous, single flip; returns the new bool state
on, off, and single-flip toggle are blocking calls returning the confirmed
power state. Synchronous operations close their HTTP clients; Hub itself
needs no explicit cleanup or context manager.
Information, status and identification
from smart_hub import Hub, HubInfo, PortStatus
hub = Hub()
info: HubInfo = hub.info()
ports: list[PortStatus] = hub.ports()
port: PortStatus = hub.status(6)
print(info.firmware, info.temperature_c, info.main_5v)
print(port.enabled, port.occupied, port.current_ma, port.next_action)
hub.identify(6) # flashes the LED; does not change power
HubInfo, PortStatus and ScheduledAction are frozen dataclasses. They are
snapshots, not live views; fetch again to refresh them. Use
dataclasses.asdict(snapshot) for a JSON-compatible dictionary.
enabledmeans the firmware's switch state, not proof that a 5 V supply or current is present. CheckHubInfo.main_5vseparately.- Absent port monitors yield
Noneforvoltage_v,current_maandpower_mw. Real zero readings remain0.0. - Invalid environment readings yield
Nonefortemperature_candhumidity_percent; an unsynced clock yieldsNonefortime_iso. power_modeis available fromstatus(port), but isNoneinports()and all-port watches because the bulk endpoint doesn't supply it.next_actionis aScheduledActionorNone. It exposesdelay_seconds,enabled(the action's target state),local_timeandentry_index.schedule_countcounts active entries; full schedule editing isn't included.
Asynchronous monitoring
watch(port=None, interval=1.0) is an asynchronous iterator. It fetches
immediately, waits between polls, and yields a fresh PortStatus for one port or
a list[PortStatus] for all ports. It never changes power.
import asyncio
from contextlib import aclosing
from smart_hub import Hub
async def monitor():
hub = Hub()
async with aclosing(hub.watch(6, interval=0.5)) as snapshots:
async for port in snapshots:
print(port.voltage_v, port.current_ma, port.fault)
# Break when your application is finished monitoring.
asyncio.run(monitor())
The iterator holds one async HTTP client. Cancellation closes it and propagates
normally. Use aclosing as above when you may break out early, so the client is
closed immediately. Polling errors propagate; there are no automatic retries.
Watch intervals must be finite and strictly positive.
Asynchronous toggling
Supplying an interval to toggle returns a coroutine instead. It uses an asynchronous HTTP
client and asyncio.sleep, so it doesn't block other asyncio tasks:
import asyncio
from smart_hub import Hub
async def main():
hub = Hub()
await hub.toggle(6, 2) # flip immediately, then every 2 seconds indefinitely
asyncio.run(main())
Inside an existing async application, cancel the task when finished:
from contextlib import suppress
task = asyncio.create_task(hub.toggle(6, 2))
# ... other application work ...
task.cancel()
with suppress(asyncio.CancelledError):
await task
Cancellation propagates normally and doesn't send a final power command. If a request is interrupted in flight, it may already have reached the hub.
Ports are numbered 1–6. Toggle intervals must be finite and non-negative; zero
means no intentional delay. Invalid arguments raise ValueError; HTTP failures
propagate as httpx2.HTTPError. Power writes check the hub's reported state,
raising RuntimeError if it doesn't match; identify checks the acknowledgement.
CLI errors exit with code 1. Existing hub schedules remain active and can
independently change port power.
API choice
hub.on(6) keeps a small, direct API. hub[6].on() would be useful if a retained
port object exposed several operations or measurements, but isn't implemented:
maintaining two equivalent interfaces isn't worthwhile for the current scope.
Development
uv sync --locked
uv run --locked ruff check .
uv run --locked ruff format --check .
uv run --locked ty check
uv run --locked python -m unittest discover -s tests -v
uv build
Ruff and ty are uv development dependencies. Ruff checks lint, import ordering, Python modernization, and formatting; ty checks the library, CLI, and tests using Python 3.14. To apply Ruff's safe fixes and formatting locally:
uv run ruff check --fix .
uv run ruff format .
.github/workflows/ci.yml runs lint, formatting, types, and regression checks on
pull requests and pushes to main. The release workflow calls the same CI
workflow before building distributions, so publishing cannot bypass those
checks. No pre-commit hook is required.
Distribution name: um-smart-hub; import package: smart_hub; CLI command: hub.
The CLI delegates all hub controls to the library.
Releases and PyPI publishing
.github/workflows/release.yml runs when a v* tag is pushed. It first calls
the shared CI workflow to run Ruff, ty, and the regression suite on Python 3.14
with locked dependencies. It then checks that the tag exactly matches v plus
[project].version, builds a wheel and source distribution, and checks their
metadata with Twine. A separate job publishes those artifacts to PyPI using
Trusted Publishing. Only after publishing succeeds does it create a GitHub
release with generated notes and attach the same distributions.
Publishing uses short-lived GitHub OIDC credentials, not a stored PyPI API token.
Only the publishing job has id-token: write; only the GitHub release job has
contents: write. Actions are pinned to commit hashes.
One-time setup before the first release
-
The PyPI distribution name is
um-smart-hub([project].nameinpyproject.toml). The explicit build-backendmodule-name = "smart_hub"keeps the import package independent of the distribution name. The CLI remainshub. -
In this repository's GitHub settings, create an environment named
pypi. Restrict deployments to release tags (v*); requiring reviewer approval is recommended. -
In your PyPI publishing settings, add a pending Trusted Publisher for
um-smart-hub:Setting Value PyPI project um-smart-hubOwner mattytrentiniRepository um-smart-hubWorkflow filename release.ymlEnvironment pypiFor an existing PyPI project you own, add the same publisher in that project's publishing settings instead. A pending publisher creates a new project on the first successful upload; it does not reserve its name in advance. See the PyPI setup guide.
-
Commit and push the workflow, package metadata, and lockfile before pushing a release tag.
Creating a release
For an initial 0.1.0 release, after completing the setup above:
uv version 0.1.0
uv lock
# Commit any name/version/lockfile changes, then push the release commit.
git push origin main
git tag -a v0.1.0 -m "Release 0.1.0"
git push origin v0.1.0
Use a new package version and matching tag for each subsequent release. Creating a local tag alone does not publish anything. Never reuse a version already uploaded to PyPI. The workflow deliberately has no manual-dispatch trigger.
Metadata
Release files for um-smart-hub 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| um_smart_hub-0.1.0.tar.gz | 11.3 kB | With provenance | Details for um_smart_hub-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| um_smart_hub-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for um_smart_hub-0.1.0-py3-none-any.whl |
Total release size: 24.7 kB
Release files / um_smart_hub-0.1.0.tar.gz
| Download URL | um_smart_hub-0.1.0.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c140bbdc8699cc0e42a6c9ada391c3cb14909a573bc132486017805cb3be42f5
|
|
BLAKE2b-256 checksum How to use checksums |
bbb4615af877504a6677885c8e0c34e54b7f6a354275c86eb60d69fb234b847f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logRelease files / um_smart_hub-0.1.0-py3-none-any.whl
| Download URL | um_smart_hub-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aee9c51783fce8dd0aefd82f1e5201ebf50c0f509d58273f38675322ebcf3c7e
|
|
BLAKE2b-256 checksum How to use checksums |
921504e0406f3fe5c66396e54d4eb766216ee3c80a0d09f043add6a3b50687cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logSecurity for um-smart-hub 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for um_smart_hub-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.