69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
|
|
class Action():
|
|
def __init__(self, task, action_id, action):
|
|
self._task = task
|
|
self._id:str = action_id
|
|
self._type:str = action['type']
|
|
self._target:str = action['target']
|
|
self._condition_list:list[str] = action['condition']
|
|
self._duration = action.get('duration', None)
|
|
self._goto = action.get('goto', None)
|
|
self._cycle = action.get('cycle', None)
|
|
self._instruction = None
|
|
|
|
self.update_instruction()
|
|
|
|
@property
|
|
def type(self):
|
|
return self._type
|
|
|
|
def update_instruction(self):
|
|
instruction_type = self._type
|
|
if instruction_type == 'stop':
|
|
instruction_type = 'interrupt'
|
|
|
|
self._instruction = {
|
|
"device_instruction": {
|
|
"header": "call_instruction",
|
|
"device": self._target,
|
|
"arguments": {
|
|
"instruction": instruction_type,
|
|
}
|
|
},
|
|
"device_parameter": {
|
|
"header": "set_multi_parameters",
|
|
"device": self._target,
|
|
"arguments": {
|
|
"parameter": self._task.get_parameter_set_by_device(self._target),
|
|
}
|
|
},
|
|
"device_recording_file_name": {
|
|
"header": "update_recording_file_name_info",
|
|
"device": self._target,
|
|
"arguments": {
|
|
"content": self._task.file_name,
|
|
}
|
|
},
|
|
"device_parent": {
|
|
"header": "update_parent_info",
|
|
"device": self._target,
|
|
"arguments": {
|
|
"content": self._task.parent
|
|
}
|
|
}
|
|
}
|
|
|
|
def get_condition_list(self):
|
|
return self._condition_list
|
|
|
|
def get_instruction(self, value):
|
|
return self._instruction[value]
|
|
|
|
def get_instruction_list(self):
|
|
instruction_set = {
|
|
'start': ['device_parent', 'device_recording_file_name', 'device_parameter', 'device_instruction'],
|
|
'stop': ['device_instruction'],
|
|
}
|
|
|
|
return map(self.get_instruction, instruction_set[self._type])
|