-
Notifications
You must be signed in to change notification settings - Fork 1
New task
To make DeviceControl as agile as possible, users have the option to implement additional Tasks.
All of these implementations are to be placed within the app/workspace/tasks
. A Python
package with the following structure is expected:
|- app
| |- workspace
| | |-- tasks
| | | |--<your-file.py>
You can create a new file or extend an existing one, depending on whether the task is relevant for an existing type of device. There is an __init__.py
file located in the app/workspace/tasks
folder. In this file, a dictionary named classes
can be found. You must register all your newly implemented task classes and types in this dictionary under a unique pair of keys by which DeviceControl
will know to reference your task. Be sure to leave a reference to the class, not an instance of it! In order to use your task in an experiment, simply provide this pair of keys in the task_class
and task_type
fields when initiating the task.
Your class should extend the BaseTask
class (or an existing Task). The super
call must provide the BaseTask
class with a dictionary.
from .. import BaseTask
class YourClass(BaseTask):
def __init__(self, config: dict):
super(YourClass, self).__init__(config)
The dictionary passed to the constructor contains (key, value)
pairs as provided by the data message sent via Task initiation. These pairs are stored within your class as the object's attributes, meaning that a value sent under your_parameter
key can be accessed within the object's methods as self.your_parameter
.
To assure compatibility between your class and DeviceControl, the class must introduce the following mandatory methods.
def start(self):
# specify what should happen on task initiation
def end(self):
# specify what should happen on task termiation