directories.forEach((directory) => { logger.info(`Installing dependencies in folder ${directory}`); try { execSync(`cd ${directory} && npm install --unsafe-perm`, { maxBuffer: 10 * 1000 * 1024, // 10Mo of logs allowed for module with big npm install }); } catch (e) { logger.warn(e); } });
const displayNumberOfEventProcessedBySeconds = (time) => { const seconds = process.hrtime(time)[0]; const elapsed = seconds + process.hrtime(time)[1] / 1000000 / 1000; const perSecond = (NUMBER_OF_SCENE_TO_REGISTER * NUMBER_OF_ACTIONS_PER_SCENE) / elapsed; const millionsEventProcessedPerSecond = perSecond / 1000000; const millionsEventProcessedPerSecondBeautiful = Math.round(millionsEventProcessedPerSecond * 100) / 100; logger.info( `Executed 1 million actions in ${elapsed} s, so ${millionsEventProcessedPerSecondBeautiful}M actions/per second`, ); }
/** * @public * @description This function starts the service * @example * gladys.services.usb.start(); */ async function start() { logger.info('Starting usb service'); }
/** * @description Return Philips hue bridges * @example * getBridges(); */ async function getBridges() { this.bridges = await this.hueClient.discovery.nupnpSearch(); logger.info(`PhilipsHueService: Found ${this.bridges.length} bridges`); this.bridges.forEach((bridge) => { this.bridgesBySerialNumber.set(bridge.model.serial, bridge); }); return this.bridges; }
/** * @description Delete all CalDAV calendars and events. * @param {Object} userId - Gladys user to clean up. * @returns {Promise} Resolving with client connected. * @example * cleanUp(user.id) */ async function cleanUp(userId) { logger.info(`Start cleaning CalDAV data for user: ${userId}`); const gladysCalendars = await this.gladys.calendar.get(userId, { serviceId: this.serviceId }); logger.info(`${gladysCalendars.length} calendars to clean`); await Promise.map(gladysCalendars, (calendar) => this.gladys.calendar.destroy(calendar.selector), { concurrency: 2 }); }
const displayNumberOfEventProcessedBySeconds = (time) => { const elapsed = process.hrtime(time)[1] / 1000000; // divide by a million to get nano to milli const perSecond = (1000 * NUMBER_OF_EVENTS_TO_THROW) / elapsed; const millionEventProcessedPerSecond = perSecond / 1000000; const millionEventProcessedPerSecondBeautiful = Math.round(millionEventProcessedPerSecond * 100) / 100; logger.info( `Processed 1 million events in ${elapsed} ms, so ${millionEventProcessedPerSecondBeautiful}M events/per second`, ); }
/** * @description Unsubscribes to a topic. * @param {string} topic - Topic to unsubscribe to. * @example * unsubscribe('topic/to/unsubscribe'); */ function unsubscribe(topic) { logger.info(`Unsubscribing to MQTT topic ${topic}`); if (this.mqttClient) { this.mqttClient.unsubscribe(topic); } delete this.topicBinds[topic]; }
/** * @public * @description This function starts the TelegramService * @example * gladys.services.telegram.start(); */ async function start() { logger.info('Starting telegram service'); const token = await gladys.variable.getValue('TELEGRAM_API_KEY', serviceId); if (!token) { throw new ServiceNotConfiguredError('No telegram api token found. Not starting telegram service'); } await messageHandler.connect(token); }
directories.forEach((directory) => { logger.info(`Installing dependencies in folder ${directory}`); try { execSync(`cd ${directory} && npm install --unsafe-perm`, { maxBuffer: 10 * 1000 * 1024, // 10Mo of logs allowed for module with big npm install }); } catch (e) { logger.warn(e); } });
const displayNumberOfEventProcessedBySeconds = (time) => { const elapsed = process.hrtime(time)[1] / 1000000; // divide by a million to get nano to milli const perSecond = (1000 * NUMBER_OF_EVENTS_TO_THROW) / elapsed; const millionEventProcessedPerSecond = perSecond / 1000000; const millionEventProcessedPerSecondBeautiful = Math.round(millionEventProcessedPerSecond * 100) / 100; logger.info( `Processed 1 million events in ${elapsed} ms, so ${millionEventProcessedPerSecondBeautiful}M events/per second`, ); }
/** * @public * @description This function starts the service * @example * gladys.services.usb.start(); */ async function start() { logger.info('Starting usb service'); }
/** * @public * @description This function starts the service * @example * gladys.services.usb.start(); */ async function start() { logger.info('Starting usb service'); }
const displayNumberOfEventProcessedBySeconds = (time) => { const seconds = process.hrtime(time)[0]; const elapsed = seconds + process.hrtime(time)[1] / 1000000 / 1000; const perSecond = (NUMBER_OF_SCENE_TO_REGISTER * NUMBER_OF_ACTIONS_PER_SCENE) / elapsed; const millionsEventProcessedPerSecond = perSecond / 1000000; const millionsEventProcessedPerSecondBeautiful = Math.round(millionsEventProcessedPerSecond * 100) / 100; logger.info( `Executed 1 million actions in ${elapsed} s, so ${millionsEventProcessedPerSecondBeautiful}M actions/per second`, ); }
/** * @description Unsubscribes to a topic. * @param {string} topic - Topic to unsubscribe to. * @example * unsubscribe('topic/to/unsubscribe'); */ function unsubscribe(topic) { logger.info(`Unsubscribing to MQTT topic ${topic}`); if (this.mqttClient) { this.mqttClient.unsubscribe(topic); } delete this.topicBinds[topic]; }
/** * @public * @description This function starts the service * @example * gladys.services.zwave.start(); */ async function start() { logger.info('Starting zwave service'); const zwaveDriverPath = await gladys.variable.getValue('ZWAVE_DRIVER_PATH', serviceId); if (!zwaveDriverPath) { throw new ServiceNotConfiguredError('ZWAVE_DRIVER_PATH_NOT_FOUND'); } zwaveManager.connect(zwaveDriverPath); }