Execute Method¶
@bp.method('device.execute')
This method is used to take the input which the user entered in the user interface and pass it to the implementation of the hardware communication. You will have to implement this method on your own, regarding some requirements.
Requirements¶
The parameter order and amount has to match the options in device.json
Parameter types are always dict, add
:dict
for eachThe argument name can be chosen freely, however it’s recommended to use the id of the option since its unique and thus easily understandable.
Parameters¶
You must add the parameters on your own, making sure the requirements above are met.
Values passed to the method will be provided in a uniform json format:
{
"id": <ID_OF_THE_OPTION>,
"value": <VALUE_FROM_THE_USER>
}
Note
The data type of <VALUE_FROM_THE_USER>
is dependent of the option type.
If you are not sure how the passed argument will look like you can print it out using print(<PARAMETER_NAME>)
in the development phase.
Example¶
Lets assume the device.json
has one option of type input looking like this:
{
"name": "Message",
"id": "unique-input-id-1",
"type": "input",
"values": {
"placeholder": ["Enter some text"]
}
}
The execute method must have this one parameter:
@bp.method('device.execute')
def execute(unique_input_id_1: dict) -> str:
Assuming the user entered a text saying “Hello World!” the value passed to the execute method will then look like this:
{
"id": "unique-input-id-1",
"value": "Hello World!"
}
Then the effective value to pass to the hardware implementation can be retrieved like this:
unique_input_id_1['value']
Which will result in “Hello World!” again.