@@ -97,7 +97,7 @@ def get_hub_message(self, device_id):
97
97
self ._iot_hub_url , device_id , etag , AZ_API_VER )
98
98
if reject_message :
99
99
path_complete += '&reject'
100
- del_status = self ._delete (path_complete , is_c2d = True )
100
+ del_status = self ._delete (path_complete )
101
101
if del_status == 204 :
102
102
return data [0 ]
103
103
return - 1
@@ -139,24 +139,25 @@ def replace_device_twin(self, device_id, properties):
139
139
140
140
# IoT Hub Service
141
141
def get_devices (self ):
142
- """Enumerate devices from the identity registry of your IoT hub .
142
+ """Enumerate devices from the identity registry of your IoT Hub .
143
143
"""
144
144
path = "{0}/devices/?api-version={1}" .format (self ._iot_hub_url , AZ_API_VER )
145
145
return self ._get (path )
146
146
147
147
def get_device (self , device_id ):
148
- """Gets device information from the identity registry of an IoT hub .
148
+ """Gets device information from the identity registry of an IoT Hub .
149
149
:param str device_id: Device Identifier.
150
150
"""
151
151
path = "{0}/devices/{1}?api-version={2}" .format (self ._iot_hub_url , device_id , AZ_API_VER )
152
152
return self ._get (path )
153
153
154
- def delete_device (self , device_id ):
154
+ def delete_device (self , device_id , device_etag ):
155
155
"""Deletes a specified device from the identity register of an IoT Hub.
156
156
:param str device_id: Device Identifier.
157
+ :param str device_etag: Device Identity Tag.
157
158
"""
158
159
path = "{0}/devices/{1}?api-version={2}" .format (self ._iot_hub_url , device_id , AZ_API_VER )
159
- self ._delete (path )
160
+ self ._delete (path , etag = device_etag )
160
161
161
162
# HTTP Helper Methods
162
163
def _post (self , path , payload , return_response = True ):
@@ -188,18 +189,19 @@ def _get(self, path, is_c2d=False):
188
189
self ._parse_http_status (response .status_code , response .reason )
189
190
return response .json ()
190
191
191
- def _delete (self , path , is_c2d = False ):
192
+ def _delete (self , path , etag = None ):
192
193
"""HTTP DELETE
193
194
:param str path: Formatted Azure IOT Hub Path.
194
- :param bool is_c2d: Cloud-to-device delete request.
195
195
"""
196
+ if etag :
197
+ data_headers = {"Authorization" :self ._sas_token , "If-Match" :'"%s"' % etag }
198
+ else :
199
+ data_headers = self ._azure_header
196
200
response = self ._wifi .delete (
197
201
path ,
198
- headers = self . _azure_header )
202
+ headers = data_headers )
199
203
self ._parse_http_status (response .status_code , response .reason )
200
- if is_c2d : # check server response for complete message request
201
- return response .status_code
202
- return response .json ()
204
+ return response .status_code
203
205
204
206
def _patch (self , path , payload ):
205
207
"""HTTP PATCH
0 commit comments