Skip to main content

Allows to switch power on usb hubs

Project description

usbhubctl

usbhubctl extends uhubctl.

State of this project

Still alpha. The concept/solution seems fine.

To be improved

  • Much too slow (uhubctl may take seconds just to switch one plug)
  • Implementation to complicated (uses lsusb -tv, uhubctl, root rights, ...)

Use Case

Image

I would like to switch on power on plug 3 on my RSH_A16 hub.

Problem

uhubctl allows me to do this - but I have to know which usb device id corresponds to plug 3.

  • I have to first figure out the topology (internal structure) of my RSH_A16 hub. Spoiler: there are 5 hubs chips with 4 ports each.
  • Now I have to figure out, which port is connected to each plug.
  • When I reconnect the RSH_A16 to another USB connected on my compunter, the whole assignement changes again.

Now I can issue uhubctl -l 3-4.6.1 -p 3 --action on.

Solution with usbhubctl/uhbuctl

This is the topology of the RSH_A16.

rsh_a16 = Hub(
    manufacturer="RSHTECH",
    model="RSH-A16",
    comment="",
    plug_count=16,
    hub_chip=HubChip(
        "0bda:5411",
        plug_or_chip=[
            1,
            2,
            HubChip(
                "0bda:5411",
                plug_or_chip=[
                    7,
                    8,
                    HubChip("0bda:5411", plug_or_chip=[13, 14, 15, 16]),
                    HubChip("0bda:5411", plug_or_chip=[9, 10, 11, 12]),
                ],
            ),
            HubChip("0bda:5411", plug_or_chip=[3, 4, 5, 6]),
        ],
    ),
)

Here you see the 5 internal hub-chips and to which usb-plugs the are connected.

This code will power on usb-plug number 3:

from usbhubctl.known_hubs import rsh_a10, rsh_a16

# Call `lsusb -tv` and find all connected RSH_A16
hubs = rsh_a16.find_connected_hubs()

if len(hubs) > 1:
    print("More than one RSH_A16 hub detected: unambiguously")
    return
if len(hubs) == 0:
    print("No RSH_A16 hub detected")
    return
hub = hubs.hubs[0]

# Finally power on
# Internally, this will call `uhubctl -l 3-4.6.1 -p 3 --action on`
hub.get_plug(3).on()

Benefit

No matter, where you connected the RSH-A16 hub, the method find_connected_hubs will find it and call uhubctl -l 3-4.6.1 -p 3 --action on with the correct parameters.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usbhubctl-0.0.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

usbhubctl-0.0.1-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file usbhubctl-0.0.1.tar.gz.

File metadata

  • Download URL: usbhubctl-0.0.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for usbhubctl-0.0.1.tar.gz
Algorithm Hash digest
SHA256 10ec8e8ee35cad161826109b22afab8645b670a49ed6a794b3de9f69d4567f2e
MD5 2d1b9030b2be78403d3a1b2e649f582a
BLAKE2b-256 78ec8242e6082e62b4776afc88e30206a874c4fc746146d0ef1d623857d8236a

See more details on using hashes here.

File details

Details for the file usbhubctl-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: usbhubctl-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for usbhubctl-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f55573498cd05d22236cfb558cbd5e0b9b8d1e654f446e82ca463d0d2b107ff2
MD5 43f8fd8c60ea81195d0d2b8662611cda
BLAKE2b-256 40ea39c5673342aaaba790e4f47f52069627b3e8f7e025e28de208754132d693

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page