UNPKG

nuki-web-api

Version:

Node.js implementation (using promises) of the Nuki Web API

169 lines (138 loc) 7.98 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Smartlock.js - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Nuki.html">Nuki</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getAccount">module.exports.getAccount</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getBrand">module.exports.getBrand</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getModel">module.exports.getModel</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getNotification">module.exports.getNotification</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getSmartlock">module.exports.getSmartlock</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getSmartlockAuth">module.exports.getSmartlockAuth</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getSmartlockAuths">module.exports.getSmartlockAuths</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getSmartlockLogs">module.exports.getSmartlockLogs</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getSmartlocks">module.exports.getSmartlocks</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getSmartlockUsers">module.exports.getSmartlockUsers</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.getSubscription">module.exports.getSubscription</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.setAction">module.exports.setAction</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#.module.exports.updateSmartlock">module.exports.updateSmartlock</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Nuki.html#_req">_req</a></span></li> </nav> <div id="main"> <h1 class="page-title">Smartlock.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>'use strict'; /** * This function returns a list of locks. * * @memberof Nuki * @description This function returns a list of locks. * @param {Object} [parameters] Parameters to use * @param {Integer} parameters.authId Filter for authId * @param {Integer} parameters.type Filter for type * @returns {Promise} * @see https://api.nuki.io/#!/Smartlock/get */ module.exports.getSmartlocks = function(parameters) { let self = this; return this ._req('smartlock', parameters) .then(function(locks) { if (!Array.isArray(locks)) throw new Error('Did not receive a list of smartlocks!'); return locks; }); }; /** * This function returns a specific lock. * * @memberof Nuki * @description This function returns a specific lock. * @param {Integer} smartlockId The smartlock id * @returns {Promise} * @see https://api.nuki.io/#!/Smartlock/get_0 */ module.exports.getSmartlock = function(smartlockId) { let self = this; return this ._req('smartlock/' + smartlockId) .then(function(lock) { if (typeof lock != 'object') throw new Error('Did not receive the requested smartlock!'); return lock; }); }; /** * This function updates a smartlock. * * @memberof Nuki * @description This function updates a smartlock. * @param {Integer} smartlockId The smartlock id * @param {Object|Boolean} update Values to be updated, if {Object} is provided, either or both the indizes name and favorite have to be supplied, otherwise {Boolean} for a shortcut to favorite * @param {String} [update.name] The new name of the smartlock * @param {Boolean} [update.favorite] True if the smartlock is favorite * @returns {Promise} * @see https://api.nuki.io/#!/Smartlock/post */ module.exports.updateSmartlock = function(smartlockId, update) { let set = {} if (typeof update == 'object') ['name', 'favorite'].forEach(function(key) {if (update[key]) set[key] = update[key]}); else if (typeof update == 'boolean' || typeof update == 'number') set = {favorite: !!update} if (!Object.keys(set).length) throw new Error('Incorrect parameter supplied to function updateSmartlock()!'); let self = this; return this ._req('smartlock/' + smartlockId, {}, 'POST', set) .then(function() { return true; }); }; /** * This function applies an action on your smartolock, e.g. lock, unlock or unlatch. * * @memberof Nuki * @description This function applies an action on your smartolock, e.g. lock, unlock or unlatch. * @param {Integer} smartlockId The smartlock id * @param {Object|Integer} action Action to be applied, if {Object} is provided, the indizes command and option have to be supplied, otherwise {Integer} for a shortcut of action.command * @param {Integer} action.command The action - 1: unlock, 2: lock, 3: unlatch, 4: lockngo, 5: lockngo with unlatch * @param {Integer} [action.option] The option mask: 0: none, 2: force, 4: full lock * @returns {Promise} * @see https://api.nuki.io/#!/Smartlock/post_0 */ module.exports.setAction = function(smartlockId, action) { if ((typeof action == 'object' &amp;&amp; !action.command) || (typeof action != 'object' &amp;&amp; !Number.isInteger(action))) throw new Error('Incorrect parameter supplied to function setAction()!'); let self = this; return this ._req('smartlock/' + smartlockId + '/action', {}, 'POST', Number.isInteger(action) ? {action: action} : {action: action.command, option: action.option}) .then(function() { return true; }); }; </code></pre> </article> </section> </div> <br class="clear"> <footer> Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Sep 08 2019 22:07:49 GMT+0200 (GMT+02:00) using the Minami theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>