@@ -34,6 +34,7 @@ const context = {
3434} ; 
3535const  apply  =  async . apply ; 
3636let  provisioningHandler ; 
37+ let  updatingHandler ; 
3738let  removeDeviceHandler ; 
3839let  updateDeviceTemplate ; 
3940let  createDeviceTemplate ; 
@@ -53,6 +54,7 @@ const provisioningAPITranslation = {
5354    protocol : 'protocol' , 
5455    transport : 'transport' , 
5556    endpoint : 'endpoint' , 
57+     polling : 'polling' , 
5658    attributes : 'active' , 
5759    commands : 'commands' , 
5860    lazy : 'lazy' , 
@@ -204,6 +206,7 @@ function toProvisioningAPIFormat(device) {
204206        timezone : device . timezone , 
205207        timestamp : device . timestamp , 
206208        endpoint : device . endpoint , 
209+         polling : device . polling , 
207210        transport : device . transport , 
208211        attributes : device . active  ? device . active . map ( attributeToProvisioningAPIFormat )  : undefined , 
209212        lazy : device . lazy  ? device . lazy . map ( attributeToProvisioningAPIFormat )  : undefined , 
@@ -317,6 +320,14 @@ function handleRemoveDevice(req, res, next) {
317320 * This middleware handles updates in the provisioning devices. The only attribute 
318321 */ 
319322function  handleUpdateDevice ( req ,  res ,  next )  { 
323+     function  applyUpdatingHandler ( device ,  callback )  { 
324+         if  ( updatingHandler )  { 
325+             updatingHandler ( device ,  callback ) ; 
326+         }  else  { 
327+             callback ( null ,  device ) ; 
328+         } 
329+     } 
330+ 
320331    if  ( req . body . device_id )  { 
321332        next ( new  errors . BadRequest ( "Can't change the ID of a preprovisioned device" ) ) ; 
322333    }  else  { 
@@ -338,12 +349,19 @@ function handleUpdateDevice(req, res, next) {
338349                    if  ( req . body . entity_name  ||  req . body . entity_type )  { 
339350                        isTypeOrNameUpdated  =  true ; 
340351                    } 
341-                     deviceService . updateRegister ( newDevice ,  isTypeOrNameUpdated ,  function  handleDeviceUpdate ( error )  { 
342-                         if  ( error )  { 
343-                             next ( error ) ; 
344-                         }  else  { 
345-                             res . status ( 204 ) . json ( { } ) ; 
346-                         } 
352+                     async . waterfall ( [ apply ( applyUpdatingHandler ,  newDevice ) ] ,  function  handleUpdating ( 
353+                         error , 
354+                         newDeviceUpdated 
355+                     )  { 
356+                         deviceService . updateRegister ( newDeviceUpdated ,  isTypeOrNameUpdated ,  function  handleDeviceUpdate ( 
357+                             error 
358+                         )  { 
359+                             if  ( error )  { 
360+                                 next ( error ) ; 
361+                             }  else  { 
362+                                 res . status ( 204 ) . json ( { } ) ; 
363+                             } 
364+                         } ) ; 
347365                    } ) ; 
348366                }  else  { 
349367                    next ( new  errors . DeviceNotFound ( req . params . deviceId ) ) ; 
@@ -392,6 +410,10 @@ function setProvisioningHandler(newHandler) {
392410    provisioningHandler  =  newHandler ; 
393411} 
394412
413+ function  setUpdatingHandler ( newHandler )  { 
414+     updatingHandler  =  newHandler ; 
415+ } 
416+ 
395417function  setRemoveDeviceHandler ( newHandler )  { 
396418    removeDeviceHandler  =  newHandler ; 
397419} 
@@ -409,6 +431,7 @@ function clear(callback) {
409431exports . setConfiguration  =  setConfiguration ; 
410432exports . loadContextRoutes  =  intoTrans ( context ,  loadContextRoutes ) ; 
411433exports . setProvisioningHandler  =  intoTrans ( context ,  setProvisioningHandler ) ; 
434+ exports . setUpdatingHandler  =  intoTrans ( context ,  setUpdatingHandler ) ; 
412435exports . setRemoveDeviceHandler  =  intoTrans ( context ,  setRemoveDeviceHandler ) ; 
413436exports . addDeviceProvisionMiddleware  =  addDeviceProvisionMiddleware ; 
414437exports . clear  =  clear ; 
0 commit comments