Usage Guideline + Authenticati...
DeviceHub Drivers
14min
drivers structure devicehub \| drivers py driver templates \| driver templates engine py \| driver py \| driver templates py sub module components devicehub/drivers py api endpoints for drivers driver templates/driver py defines object representations of driver and register types driver templates/driver templates py stores all currently available drivers and registers as driver objects driver templates/driver templates engine py code generation engine for producing driver templates/driver templates py via the api use cases below are common use cases of the sdk that can help you familiarize yourself with how it works and how to use it it is not intended to be an exhaustive documentation of all functions for that review the docstrings of the methods driver api list drivers and driver properties there are multiple ways to list devices using the sdk all return a pandas dataframe with the device name as the index, but have different columns as listed below drivers list drivers index drivertype str id str drivergroupid str name str drivers list drivers details index drivertype str id str drivergroupid str name str description str drivergeneration str either gen1 or gen2 deviceproperties list\[dict] list of dictionaries with the following properties specifying the internal properties of a device with this driver (eg path, port) tab none position int newline bool name str description str stringformat str defaultvalue str valuetype str numbermin int numbermax int linkedfieldname str required bool optional bool metatype str listvalues list\[dict] supportedregisters list\[dict] list of dictionaries with the following properties specifying the valid registers for a device with this driver name str description str readonly bool registerproperties list\[dict] internal properties of register, same as deviceproperties meta dict metadata about the drive with the following properties browsesupported bool dynamicbrowsesupported bool driverconnectiontype str version str discovery supported str freetag bool driverstate str discoveryproperties list\[dict] drivergroup dict specifies to which group the driver belongs with the following properties id str name str logo str get id of driver from name from litmussdk devicehub drivers import drivers def getdriverid(driver name) status code, df = drivers list drivers() assert(status code == 200) return df loc\[df\['name']==driver name]\['id'] ids = getdriverid('simulator (gen1)') get registers of driver from litmussdk devicehub drivers import drivers def getdriverregisters(driver name) status code, response = drivers list drivers details() assert(status code == 200) return df loc\[df\['name']==driver name]\['supportedregisters'] registers = getdriverregisters("simulator (gen1)") driver templates because the driver api data is relatively complicated, the sdk provides a useful abstraction layer to more easily these can all be found under the driver templates module note the driver templates module is still a work in progress and some features are not guarenteed to work as expected driver and register template classes propertytype a dataclass representing a type of device or register properties, specifying the limitations of that property used for generating the json schema for the register or driver contains the following properties name str position int description str | none string format str | none value type propertyvalue required bool meta type str optional list values list\[dict] optional linked field name none optional linked values none optional number min int | none optional number max int | none optional default value str | none optional new line bool ignored tab none ignored optional bool registertype a dataclass for a register specifying the valid properties and configuration of an instance of that register contains the following properties name str readonly bool properties list\[propertytype] optional description str drivertemplate a dataclass specifying the valid properties and components of a driver with the following properties name str id str driver gen str group id str properties list\[propertytype] registers list\[registerstype] optional description str getting drivertemplate from name or id get driver id by name in library from litmussdk driver templates driver templates import get driver by name simulator = get driver by name("simulator (gen1)") id = simulator id get driver id by name in templates from litmussdk driver templates driver templates import drivertemplates simulator = drivertemplates simulator gen1 id = simulator id get driver by id from litmussdk driver templates driver templates import driver library by id driver id = "50e3eda1 11f9 41d6 9232 778a28665580" driver = driver library by id\[id] get registers of driver from litmussdk driver templates driver templates import drivertemplates registers = drivertemplates simulator gen1 registers getting json schema of driver properties both drivers and register templates can generate a json schema https //json schema org/overview/what is jsonschema for their internal properties can be used to validate device configuration client side before an api call example uses the third party library jsonschema test device configuration import jsonschema from litmussdk driver templates driver templates import drivertemplates device properties = { 'networkaddress' '127 0 0 1', 'networkport' 8080, 'name' 'test device', 'slotnumber' 100, 'description' ""} \# will succeed jsonschema validate(device properties, drivertemplates siemens s7 schema) \# will fail jsonschema validate(device properties, drivertemplates simulator gen1 schema)