diff --git a/examples/scripts/smart-coffee-machine-oauth.js b/examples/scripts/smart-coffee-machine-oauth.js index 97a874619..5dba209ad 100644 --- a/examples/scripts/smart-coffee-machine-oauth.js +++ b/examples/scripts/smart-coffee-machine-oauth.js @@ -251,38 +251,37 @@ Assumes one medium americano if not specified, but time and mode are mandatory f // Override a write handler for availableResourceLevel property, // utilizing the uriVariables properly thing.setPropertyWriteHandler('availableResourceLevel', (val, options) => { - // Check if uriVariables are provided - if (options && typeof options === 'object' && 'uriVariables' in options) { - const uriVariables = options['uriVariables']; - if ('id' in uriVariables) { - return thing.readProperty('allAvailableResources').then((resources) => { - const id = uriVariables['id']; - resources[id] = val; - return thing.writeProperty('allAvailableResources', resources); - }); - } - } return new Promise((resolve, reject) => { - resolve('Please specify id variable as uriVariables.'); + // Check if uriVariables are provided + if (options && typeof options === 'object' && 'uriVariables' in options) { + const uriVariables = options['uriVariables']; + if ('id' in uriVariables) { + return thing.readProperty('allAvailableResources').then((resources) => { + const id = uriVariables['id']; + resources[id] = val; + thing.writeProperty('allAvailableResources', resources); + return resolve(); + }); + } + } + return reject('Please specify id variable as uriVariables.'); }); }); // Override a read handler for availableResourceLevel property, // utilizing the uriVariables properly thing.setPropertyReadHandler('availableResourceLevel', (options) => { - // Check if uriVariables are provided - if (options && typeof options === 'object' && 'uriVariables' in options) { - const uriVariables = options['uriVariables']; - if ('id' in uriVariables) { - return thing.readProperty('allAvailableResources').then((resources) => { - const id = uriVariables['id']; - return new Promise((resolve, reject) => { - resolve(resources[id]); + return new Promise((resolve, reject) => { + // Check if uriVariables are provided + if (options && typeof options === 'object' && 'uriVariables' in options) { + const uriVariables = options['uriVariables']; + if ('id' in uriVariables) { + return thing.readProperty('allAvailableResources').then((resources) => { + const id = uriVariables['id']; + return resolve(resources[id]); }); - }); + } } - } - return new Promise((resolve, reject) => { - resolve('Please specify id variable as uriVariables.'); + return reject('Please specify id variable as uriVariables.'); }); }); // Set up a handler for makeDrink action diff --git a/examples/scripts/smart-coffee-machine.js b/examples/scripts/smart-coffee-machine.js index a9cb02b88..3d83163c9 100644 --- a/examples/scripts/smart-coffee-machine.js +++ b/examples/scripts/smart-coffee-machine.js @@ -237,38 +237,37 @@ Assumes one medium americano if not specified, but time and mode are mandatory f // Override a write handler for availableResourceLevel property, // utilizing the uriVariables properly thing.setPropertyWriteHandler('availableResourceLevel', (val, options) => { - // Check if uriVariables are provided - if (options && typeof options === 'object' && 'uriVariables' in options) { - const uriVariables = options['uriVariables']; - if ('id' in uriVariables) { - return thing.readProperty('allAvailableResources').then((resources) => { - const id = uriVariables['id']; - resources[id] = val; - return thing.writeProperty('allAvailableResources', resources); - }); - } - } return new Promise((resolve, reject) => { - resolve('Please specify id variable as uriVariables.'); + // Check if uriVariables are provided + if (options && typeof options === 'object' && 'uriVariables' in options) { + const uriVariables = options['uriVariables']; + if ('id' in uriVariables) { + return thing.readProperty('allAvailableResources').then((resources) => { + const id = uriVariables['id']; + resources[id] = val; + thing.writeProperty('allAvailableResources', resources); + return resolve(); + }); + } + } + return reject('Please specify id variable as uriVariables.'); }); }); // Override a read handler for availableResourceLevel property, // utilizing the uriVariables properly thing.setPropertyReadHandler('availableResourceLevel', (options) => { - // Check if uriVariables are provided - if (options && typeof options === 'object' && 'uriVariables' in options) { - const uriVariables = options['uriVariables']; - if ('id' in uriVariables) { - return thing.readProperty('allAvailableResources').then((resources) => { - const id = uriVariables['id']; - return new Promise((resolve, reject) => { - resolve(resources[id]); + return new Promise((resolve, reject) => { + // Check if uriVariables are provided + if (options && typeof options === 'object' && 'uriVariables' in options) { + const uriVariables = options['uriVariables']; + if ('id' in uriVariables) { + return thing.readProperty('allAvailableResources').then((resources) => { + const id = uriVariables['id']; + return resolve(resources[id]); }); - }); + } } - } - return new Promise((resolve, reject) => { - resolve('Please specify id variable as uriVariables.'); + return reject('Please specify id variable as uriVariables.'); }); }); // Set up a handler for makeDrink action diff --git a/packages/examples/src/scripts/smart-coffee-machine-oauth.ts b/packages/examples/src/scripts/smart-coffee-machine-oauth.ts index 7af2d5693..24f957336 100644 --- a/packages/examples/src/scripts/smart-coffee-machine-oauth.ts +++ b/packages/examples/src/scripts/smart-coffee-machine-oauth.ts @@ -263,41 +263,38 @@ Assumes one medium americano if not specified, but time and mode are mandatory f // Override a write handler for availableResourceLevel property, // utilizing the uriVariables properly thing.setPropertyWriteHandler('availableResourceLevel', (val, options) => { - - // Check if uriVariables are provided - if (options && typeof options === 'object' && 'uriVariables' in options) { - const uriVariables: any = options['uriVariables']; - if ('id' in uriVariables) { - return thing.readProperty('allAvailableResources').then((resources) => { - const id = uriVariables['id']; - resources[id] = val; - return thing.writeProperty('allAvailableResources', resources); - }); - } - } return new Promise((resolve, reject) => { - resolve('Please specify id variable as uriVariables.'); + // Check if uriVariables are provided + if (options && typeof options === 'object' && 'uriVariables' in options) { + const uriVariables: any = options['uriVariables']; + if ('id' in uriVariables) { + return thing.readProperty('allAvailableResources').then((resources) => { + const id = uriVariables['id']; + resources[id] = val; + thing.writeProperty('allAvailableResources', resources); + return resolve(); + }); + } + } + return reject('Please specify id variable as uriVariables.'); }); }); // Override a read handler for availableResourceLevel property, // utilizing the uriVariables properly thing.setPropertyReadHandler('availableResourceLevel', (options) => { - - // Check if uriVariables are provided - if (options && typeof options === 'object' && 'uriVariables' in options) { - const uriVariables: any = options['uriVariables']; - if ('id' in uriVariables) { - return thing.readProperty('allAvailableResources').then((resources) => { - const id = uriVariables['id']; - return new Promise((resolve, reject) => { - resolve(resources[id]); + return new Promise((resolve, reject) => { + // Check if uriVariables are provided + if (options && typeof options === 'object' && 'uriVariables' in options) { + const uriVariables: any = options['uriVariables']; + if ('id' in uriVariables) { + return thing.readProperty('allAvailableResources').then((resources) => { + const id = uriVariables['id']; + return resolve(resources[id]); }); - }); + } } - } - return new Promise((resolve, reject) => { - resolve('Please specify id variable as uriVariables.'); + return reject('Please specify id variable as uriVariables.'); }); }); diff --git a/packages/examples/src/scripts/smart-coffee-machine.ts b/packages/examples/src/scripts/smart-coffee-machine.ts index efd1a8b97..ac6b8fcd3 100644 --- a/packages/examples/src/scripts/smart-coffee-machine.ts +++ b/packages/examples/src/scripts/smart-coffee-machine.ts @@ -249,41 +249,38 @@ Assumes one medium americano if not specified, but time and mode are mandatory f // Override a write handler for availableResourceLevel property, // utilizing the uriVariables properly thing.setPropertyWriteHandler('availableResourceLevel', (val, options) => { - - // Check if uriVariables are provided - if (options && typeof options === 'object' && 'uriVariables' in options) { - const uriVariables: any = options['uriVariables']; - if ('id' in uriVariables) { - return thing.readProperty('allAvailableResources').then((resources) => { - const id = uriVariables['id']; - resources[id] = val; - return thing.writeProperty('allAvailableResources', resources); - }); - } - } return new Promise((resolve, reject) => { - resolve('Please specify id variable as uriVariables.'); + // Check if uriVariables are provided + if (options && typeof options === 'object' && 'uriVariables' in options) { + const uriVariables: any = options['uriVariables']; + if ('id' in uriVariables) { + return thing.readProperty('allAvailableResources').then((resources) => { + const id = uriVariables['id']; + resources[id] = val; + thing.writeProperty('allAvailableResources', resources); + return resolve(); + }); + } + } + return reject('Please specify id variable as uriVariables.'); }); }); // Override a read handler for availableResourceLevel property, // utilizing the uriVariables properly thing.setPropertyReadHandler('availableResourceLevel', (options) => { - - // Check if uriVariables are provided - if (options && typeof options === 'object' && 'uriVariables' in options) { - const uriVariables: any = options['uriVariables']; - if ('id' in uriVariables) { - return thing.readProperty('allAvailableResources').then((resources) => { - const id = uriVariables['id']; - return new Promise((resolve, reject) => { - resolve(resources[id]); + return new Promise((resolve, reject) => { + // Check if uriVariables are provided + if (options && typeof options === 'object' && 'uriVariables' in options) { + const uriVariables: any = options['uriVariables']; + if ('id' in uriVariables) { + return thing.readProperty('allAvailableResources').then((resources) => { + const id = uriVariables['id']; + return resolve(resources[id]); }); - }); + } } - } - return new Promise((resolve, reject) => { - resolve('Please specify id variable as uriVariables.'); + return reject('Please specify id variable as uriVariables.'); }); });