UNPKG

browser-sdk

Version:

javascript SDK for the lightelligence-platform

182 lines (158 loc) 6.79 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _apiService = _interopRequireDefault(require("../tools/apiService")); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } /** * Methods for device operations */ var Device = /*#__PURE__*/ function () { function Device() { (0, _classCallCheck2["default"])(this, Device); } (0, _createClass2["default"])(Device, null, [{ key: "createDevice", /** * Creates a new device * @param {object} device * @returns {Promise} */ value: function createDevice(device) { return _apiService["default"].call('/devices', 'POST', device); } /** * Get all devices * @param {object} params * @param {number} [params.page=0] The number of the result page starting with 0 * @param {number} [params.pageSize=10] The number of result per page. Default is 10 * @param {string} [params.tags=undefined] Filter the results to contain only devices having all the comma-separated list of tags provided here. Case-insensitive. Surround the tag with * for substring matching. Example: subString-of-a-tag,fullMatching-Tag * @param {string} [params.name=undefined] Filter the results to contain only devices having the provided name. Case-insensitive. Surround with * for substring matching. Example: &subString* OR fullMatchingName * @param {string} [params.deviceTypeId=undefined] Filter returning devices matching a single device type UUID. * @param {string} [params.connectedBy=undefined] Filter the results to contain only devices connected by a given device UUID. * @returns {Promise} */ }, { key: "getDevices", value: function getDevices(params) { var urlParams = new URLSearchParams(params); return _apiService["default"].call("/devices?".concat(urlParams.toString())); } /** * Get all device tags * @returns {Promise} */ }, { key: "getDeviceTags", value: function getDeviceTags() { return _apiService["default"].call('/devices/tags'); } /** * Get a device by its deviceId. * @param {string} deviceId * @returns {Promise} */ }, { key: "getDevice", value: function getDevice(deviceId) { return _apiService["default"].call("/devices/".concat(deviceId)); } /** * Edit a specific device by id partially. Id is not patchable. You can also only patch a single property from your custom data. To delete submit null. * @param {string} deviceId * @param {object} patch changes to device * @returns {Promise} */ }, { key: "patchDevice", value: function patchDevice(deviceId, patch) { return _apiService["default"].call("/devices/".concat(deviceId), 'PATCH', patch); } /** * Delete a specific device by id. * @param {string} deviceId * @returns {Promise} */ }, { key: "deleteDevice", value: function deleteDevice(deviceId) { return _apiService["default"].call("/devices/".concat(deviceId), 'DELETE'); } /** * Trigger device action * @param {string} deviceId * @returns {Promise} */ }, { key: "createAction", value: function createAction(deviceId, action) { return _apiService["default"].call("/devices/".concat(deviceId, "/actions"), 'POST', action); } /** * The current state of a a device are the attributes and configurations the device has last sent to the cloud. Newer values for the same attribute and configuration overwrite older on. * @param {string} deviceId * @returns {Promise} */ }, { key: "getState", value: function getState(deviceId) { return _apiService["default"].call("/devices/".concat(deviceId, "/state")); } /** * List device diagnostic messages sorted descending by time for a specific device for the last hour to simplify debugging. * @param {string} deviceId * @returns {Promise} */ }, { key: "getLastDiagnostics", value: function getLastDiagnostics(deviceId) { return _apiService["default"].call("/devices/".concat(deviceId, "/last-diagnostics")); } /** * Push data to device * @param {string} deviceId * @param {object} data * @returns {Promise} */ }, { key: "pushData", value: function pushData(deviceId, data) { var post = _objectSpread({}, data, { deviceId: deviceId }); return _apiService["default"].call('/data-ingest', 'POST', post); } /** * Get the online monitoring configuration for a device * @param {string} deviceId * @returns {Promise} */ }, { key: "getOnlineMonitoringRules", value: function getOnlineMonitoringRules(deviceId) { return _apiService["default"].call("/devices/".concat(deviceId, "/onlinemonitoring")); } /** * Edit the online monitoring configuration for a device * @param {string} deviceId * @param {object} config changes to device * @param {number|null} config.communicationInterval The expected communication interval in seconds. Special cases: **0** means monitoring is disabled, **null** means inherit from device type * @returns {Promise} */ }, { key: "patchOnlineMonitoringRules", value: function patchOnlineMonitoringRules(deviceId, config) { return _apiService["default"].call("/devices/".concat(deviceId, "/onlinemonitoring"), 'PATCH', config); } }]); return Device; }(); exports["default"] = Device;