@@ -15,7 +15,14 @@ def validate_attributes(required, attributes, class_name):
1515
1616
1717class AppManager :
18+ """
19+ Defines entry points to the application.
20+ """
21+
1822 def init_app (self ):
23+ """
24+ Initializes the application.
25+ """
1926 from app .src .task_manager import TaskManager
2027 from app .src .data_manager import DataManager
2128 from app .src .device_manager import DeviceManager
@@ -26,6 +33,13 @@ def init_app(self):
2633
2734 @log_initialise ('device' )
2835 def register_device (self , config : dict ) -> Response :
36+ """
37+ Register a new device (see
38+ `details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#device-initiation>`__).
39+
40+ :param config: A dictionary with pre-defined keys
41+ :return: Response object
42+ """
2943 try :
3044 validate_attributes (['device_id' , 'device_class' , 'device_type' , 'address' ], config , 'Connector' )
3145 device = self .deviceManager .new_device (config )
@@ -38,6 +52,12 @@ def register_device(self, config: dict) -> Response:
3852
3953 @log_terminate
4054 def end_device (self , device_id : str ) -> Response :
55+ """
56+ Terminates an existing device.
57+
58+ :param device_id: ID of an existing device
59+ :return: Response object
60+ """
4161 try :
4262 self .deviceManager .remove_device (device_id )
4363 self .dataManager .event_device_end (device_id )
@@ -51,7 +71,14 @@ def end_device(self, device_id: str) -> Response:
5171 Log .error (exc )
5272 return Response (False , None , exc )
5373
54- def command (self , config ) -> Response :
74+ def command (self , config : dict ) -> Response :
75+ """
76+ Run a specific command (see
77+ `details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#command>`__).
78+
79+ :param config: A dictionary with pre-defined keys
80+ :return: Response object
81+ """
5582 try :
5683 validate_attributes (['device_id' , 'command_id' ], config , 'Command' )
5784
@@ -61,7 +88,7 @@ def command(self, config) -> Response:
6188 source = config .get ('source' , 'external' )
6289 await_result = config .get ('await' , False )
6390
64- cmd = self .create_command (device_id , command_id , args , source )
91+ cmd = self ._create_command (device_id , command_id , args , source )
6592 if await_result :
6693 self .deviceManager .get_device (device_id ).post_command (cmd )
6794 cmd .await_cmd ()
@@ -74,7 +101,14 @@ def command(self, config) -> Response:
74101 return Response (False , None , e )
75102
76103 @log_initialise ('task' )
77- def register_task (self , config ) -> Response :
104+ def register_task (self , config : dict ) -> Response :
105+ """
106+ Register a new task (see
107+ `details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#task-initiation>`__).
108+
109+ :param config: A dictionary with pre-defined keys
110+ :return: Response object
111+ """
78112 try :
79113 validate_attributes (['task_id' , 'task_class' , 'task_type' ], config , 'Task' )
80114 task = self .taskManager .create_task (config )
@@ -87,6 +121,12 @@ def register_task(self, config) -> Response:
87121
88122 @log_terminate
89123 def end_task (self , task_id ) -> Response :
124+ """
125+ Terminate an existing task.
126+
127+ :param task_id: ID of an existing task
128+ :return: Response object
129+ """
90130 try :
91131 device_id = self .taskManager .remove_task (task_id )
92132 self .dataManager .event_task_end (device_id , task_id )
@@ -97,12 +137,25 @@ def end_task(self, task_id) -> Response:
97137 return Response (False , None , exc )
98138
99139 def ping (self ) -> Response :
140+ """
141+ Get status information about the running devices and tasks (see
142+ `details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#ping>`__).
143+
144+ :return: Response object
145+ """
100146 return Response (True , {
101147 'devices' : self .deviceManager .ping (),
102148 'tasks' : self .taskManager .ping ()
103149 }, None )
104150
105- def get_data (self , config ) -> Response :
151+ def get_data (self , config : dict ) -> Response :
152+ """
153+ Retrieves data in supported format (see
154+ `details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#get-data>`__).
155+
156+ :param config: A dictionary with pre-defined keys
157+ :return: Response object
158+ """
106159 try :
107160 validate_attributes (['device_id' , 'type' ], config , 'GetData' )
108161
@@ -120,6 +173,12 @@ def get_data(self, config) -> Response:
120173 return Response (False , None , e )
121174
122175 def get_latest_data (self , config ) -> Response :
176+ """
177+ Retrieves the last data entry for specified Device ID and Data Type.
178+
179+ :param config: A dictionary which specifies the "device_id": string and "type": string
180+ :return: Response object
181+ """
123182 try :
124183 validate_attributes (['device_id' , 'type' ], config , 'GetData' )
125184 device_id = config .get ('device_id' )
@@ -130,18 +189,24 @@ def get_latest_data(self, config) -> Response:
130189 Log .error (e )
131190 return Response (False , None , e )
132191
133- @staticmethod
134- def create_command (device_id , command_id , args , source ):
135- from ..command import Command
136- return Command (device_id , command_id , eval (args ), source )
137-
138192 @log_terminate_all
139193 def end (self ) -> Response :
194+ """
195+ Ends the application (see
196+ `details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#end>`__).
197+
198+ :return: Response object
199+ """
140200 self .taskManager .end ()
141201 self .deviceManager .end ()
142202 return Response (True , None , None )
143203
144- def restore_session (self ):
204+ @staticmethod
205+ def _create_command (device_id , command_id , args , source ):
206+ from ..command import Command
207+ return Command (device_id , command_id , eval (args ), source )
208+
209+ def _restore_session (self ):
145210 # first start devices
146211 tasks = []
147212 for log in self .dataManager .load_log ():
0 commit comments