@@ -41,21 +41,19 @@ def as_action_description(self):
4141 Returns a dictionary describing the action.
4242 """
4343 description = {
44- self .name : {
45- "href" : self .href_prefix + self .href ,
46- "timeRequested" : self .time_requested ,
47- "status" : self .status ,
48- },
44+ "name" : self .name ,
45+ "id" : self .id ,
46+ "href" : self .href_prefix + self .href ,
47+ "timeRequested" : self .time_requested ,
48+ "timeCompleted" : self .time_completed ,
49+ "status" : self .status ,
4950 }
5051
5152 if self .input is not None :
52- description [self . name ][ "input" ] = self .input
53+ description ["input" ] = self .input
5354
5455 if self .output is not None :
55- description [self .name ]["output" ] = self .output
56-
57- if self .time_completed is not None :
58- description [self .name ]["timeCompleted" ] = self .time_completed
56+ description ["output" ] = self .output
5957
6058 return description
6159
@@ -135,12 +133,15 @@ def finish(self, future):
135133class Action :
136134 """An Action represents a class of actions on a thing."""
137135
138- def __init__ (self , thing , name , invokeaction = None , metadata = None ):
136+ def __init__ (self , thing , name , invokeaction = None , metadata = None , input_ = None , output = None ):
139137 self .thing = thing
140138 self .name = name
141139 self .href_prefix = ""
142140 self .href = "/actions/{}" .format (self .name )
141+
143142 self .metadata = metadata if metadata is not None else {}
143+ self .input = input_ if input_ is not None else {}
144+ self .output = output if output is not None else {}
144145
145146 self .invokeaction_forwarder = invokeaction or (lambda : None )
146147
@@ -154,6 +155,25 @@ def as_action_description(self):
154155 """
155156 description = deepcopy (self .metadata )
156157
158+ # Create WoT TD v1 input and output keys
159+ if "input" not in description :
160+ description ["input" ] = self .input
161+
162+ if "output" not in description :
163+ description ["output" ] = {
164+ "type" : "object" ,
165+ "properties" : {
166+ "name" : {"type" : "string" },
167+ "id" : {"type" : "string" },
168+ "href" : {"type" : "string" , "format" : "uri" },
169+ "timeRequested" : {"type" : "string" , "format" : "date-time" },
170+ "timeCompleted" : {"type" : "string" , "format" : "date-time" },
171+ "status" : {"type" : "string" , "enum" : ["created" , "pending" , "completed" , "cancelled" , "error" ]},
172+ ** ({"output" : self .output } if self .output else {}),
173+ ** ({"input" : self .input } if self .input else {}),
174+ }
175+ }
176+
157177 # Create forms
158178 if "forms" not in description :
159179 description ["forms" ] = []
0 commit comments