@@ -44,15 +44,16 @@ def view_to_thing_action_forms(rules: list, view: View):
44
44
break
45
45
46
46
for url in prop_urls :
47
- forms .append (
48
- {
49
- "op" : ["invokeaction" ],
50
- "htv:methodName" : "POST" ,
51
- "href" : url ,
52
- "contentType" : content_type ,
53
- "response" : {"contentType" : response_content_type },
54
- }
55
- )
47
+ form = {
48
+ "op" : ["invokeaction" ],
49
+ "htv:methodName" : "POST" ,
50
+ "href" : url ,
51
+ "contentType" : content_type ,
52
+ }
53
+ if response_content_type != content_type :
54
+ form ["responses" ] = {"contentType" : response_content_type }
55
+
56
+ forms .append (form )
56
57
57
58
return forms
58
59
@@ -84,43 +85,49 @@ def view_to_thing_property_forms(rules: list, view: View):
84
85
response_content_type = responses [response_code ].get ("content_type" )
85
86
break
86
87
88
+ # TODO: Clean up repeated code
89
+
87
90
# HTTP readproperty requires GET method
88
91
if hasattr (view , "get" ):
89
92
for url in prop_urls :
90
- forms .append (
91
- {
92
- "op" : ["readproperty" ],
93
- "htv:methodName" : "GET" ,
94
- "href" : url ,
95
- "contentType" : content_type ,
96
- "response" : {"contentType" : response_content_type },
97
- }
98
- )
93
+ form = {
94
+ "op" : ["readproperty" ],
95
+ "htv:methodName" : "GET" ,
96
+ "href" : url ,
97
+ "contentType" : content_type ,
98
+ "response" : {"contentType" : response_content_type },
99
+ }
100
+ if response_content_type != content_type :
101
+ form ["responses" ] = {"contentType" : response_content_type }
102
+ forms .append (form )
99
103
100
104
# HTTP writeproperty requires PUT method
101
105
if hasattr (view , "put" ):
102
106
for url in prop_urls :
103
- forms .append (
104
- {
105
- "op" : ["writeproperty" ],
106
- "htv:methodName" : "PUT" ,
107
- "href" : url ,
108
- "contentType" : content_type ,
109
- "response" : {"contentType" : response_content_type },
110
- }
111
- )
107
+ form = {
108
+ "op" : ["writeproperty" ],
109
+ "htv:methodName" : "PUT" ,
110
+ "href" : url ,
111
+ "contentType" : content_type ,
112
+ "response" : {"contentType" : response_content_type },
113
+ }
114
+ if response_content_type != content_type :
115
+ form ["responses" ] = {"contentType" : response_content_type }
116
+ forms .append (form )
117
+
112
118
# HTTP writeproperty may use POST method
113
119
elif hasattr (view , "post" ):
114
120
for url in prop_urls :
115
- forms .append (
116
- {
117
- "op" : ["writeproperty" ],
118
- "htv:methodName" : "POST" ,
119
- "href" : url ,
120
- "contentType" : content_type ,
121
- "response" : {"contentType" : response_content_type },
122
- }
123
- )
121
+ form = {
122
+ "op" : ["writeproperty" ],
123
+ "htv:methodName" : "POST" ,
124
+ "href" : url ,
125
+ "contentType" : content_type ,
126
+ "response" : {"contentType" : response_content_type },
127
+ }
128
+ if response_content_type != content_type :
129
+ form ["responses" ] = {"contentType" : response_content_type }
130
+ forms .append (form )
124
131
125
132
return forms
126
133
0 commit comments