https://github.com/nbuchwitz/python3-uhubctl
Simple uhubctl wrapper for Python 3
https://github.com/nbuchwitz/python3-uhubctl
automation hub python testing usb
Last synced: about 2 months ago
JSON representation
Simple uhubctl wrapper for Python 3
- Host: GitHub
- URL: https://github.com/nbuchwitz/python3-uhubctl
- Owner: nbuchwitz
- License: mit
- Created: 2022-08-11T17:59:09.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T20:26:59.000Z (over 1 year ago)
- Last Synced: 2024-05-22T20:05:38.378Z (over 1 year ago)
- Topics: automation, hub, python, testing, usb
- Language: Python
- Homepage:
- Size: 36.1 KB
- Stars: 15
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Python wrapper for uhubctl
This is a simple Python wrapper for [uhubctl](https://github.com/mvp/uhubctl)
# Examples
## Discover all usable USB hubs
```python
import uhubctlhubs = uhubctl.discover_hubs()
for hub in hubs:
print(f"Found hub: {hub}")for port in hub.ports:
print(f" Found port: {port}")
```## Create hub and enumerate attached ports
```python
import uhubctlhub = Hub("1-1", enumerate_ports=True)
# Iterate all ports
for port in hub.ports:
print(f"Found port: {port}")# Get port by port number
port_2 = hub.find_port(2)
print(f"The status of port 2 is {port_2.status}")
```## Manually specify hub and port
```python
from uhubctl import Hub, Porthub = Hub("1-1")
hub.add_port(1)
```## Control ports
```python
from uhubctl import Hub, Porthub = Hub("1-1")
port = hub.add_port(1)print("Switch port 1-1.1 off")
port.status = Falseprint("Switch port 1-1.1 on")
port.status = Trueprint("Get port 1-1.1 status")
print(port.status)
```## Device details
```python
import uhubctlhubs = uhubctl.discover_hubs()
for hub in hubs:
print(f"Found hub: {hub}")for port in hub.ports:
print(f" Found port: {port}")
# You can use the optional argument `cached_results=False` for each of
# these 3 methods in order to invalidate the internal cache,
# which is used for performance reasons
print(f" Description: {port.description()}")
print(f" Vendor ID: {port.vendor_id()}")
print(f" Product ID: {port.product_id()}")
```# FAQ
### How can I specify the path to ´uhubctl´
```python
import uhubctluhubctl.utils.UHUBCTL_BINARY = "sudo /usr/local/bin/uhubctl"
```