DeviceHub Drivers
13 min
the drivers module provides access to devicehub driver definitions and a bundled template library for offline use imports from litmussdk devicehub import drivers # live api from litmussdk devicehub record import drivertemplates # bundled templates driver api listing drivers from litmussdk devicehub import drivers all drivers = drivers list all drivers() # list\[driver] pass raw=true to skip pydantic validation and return the api json unchanged useful when the driver schema drifts ahead of your installed sdk all raw = drivers list all drivers(raw=true) # list\[dict\[str, any]] each driver is a pydantic model with fields including id str name str driver gen str "gen1" or "gen2" group id str properties list\[property] valid device level configuration fields registers list\[supportedregister] valid register (tag) types for this driver meta meta browse support, discovery support, version, etc \# find a driver by name driver = next((d for d in drivers list all drivers() if d name == "simulator (gen1)"), none) driver id = driver id \# or, with raw dicts driver = next((d for d in drivers list all drivers(raw=true) if d\["name"] == "simulator (gen1)"), none) driver id = driver\["id"] \# get supported registers for a driver details = next((d for d in drivers list all drivers() if d name == "simulator (gen1)"), none) registers = details registers driver templates the sdk ships with a bundled set of driver definitions compiled from the litmus edge api these let you look up driver ids and validate device configuration without making live api calls templates are regenerated via the download dh record cli command or during ci builds run list dh versions to see available versions and get dh cache dir to find where they are cached getting a driver by name or id from litmussdk devicehub record import drivertemplates, get driver by name, driver library by id \# from the drivertemplates class (known drivers) simulator = drivertemplates simulator gen1 driver id = simulator id \# by name (searches the full library) driver = get driver by name("simulator (gen1)") \# by id driver = driver library by id\["50e3eda1 11f9 41d6 9232 778a28665580"] inspecting driver properties registers = drivertemplates simulator gen1 registers properties = drivertemplates simulator gen1 properties validating device configuration (json schema) both drivertemplate and registertype objects can generate a json schema https //json schema org/ for their configuration fields, useful for client side validation before making api calls import jsonschema from litmussdk devicehub record import drivertemplates device config = { "networkaddress" "192 168 1 10", "networkport" 102, "slotnumber" 0, } \# validates successfully against the siemens s7 schema jsonschema validate(device config, drivertemplates siemens s7 schema) \# raises validationerror, wrong driver jsonschema validate(device config, drivertemplates simulator gen1 schema) template data classes drivertemplate represents a driver type with the following fields name str id str driver gen str group id str properties list\[propertytype] registers list\[registertype] description str (optional) registertype represents a valid tag/register type for a driver name str readonly bool properties list\[propertytype] description str (optional) propertytype describes a single configuration field name str value type str required bool description str | none default value str | none number min int | none , number max int | none license copyright (c) litmus automation inc