From 3a93bfce800f49e917ea17017495d1021b801361 Mon Sep 17 00:00:00 2001 From: Justin Weisz Date: Mon, 9 Nov 2020 15:19:03 -0500 Subject: [PATCH] fixed all lint errors --- lib/tjbot.js | 433 ++++++++++++++++++++++++++------------------------- 1 file changed, 218 insertions(+), 215 deletions(-) diff --git a/lib/tjbot.js b/lib/tjbot.js index 0e29f26..bf3eda5 100644 --- a/lib/tjbot.js +++ b/lib/tjbot.js @@ -1,3 +1,4 @@ +/* eslint-disable import/extensions */ /** * Copyright 2016-2020 IBM Corp. All Rights Reserved. * @@ -76,7 +77,7 @@ class TJBot { LED_COMMON_ANODE: 'led_common_anode', MICROPHONE: 'microphone', SERVO: 'servo', - SPEAKER: 'speaker' + SPEAKER: 'speaker', }; /** @@ -205,14 +206,14 @@ class TJBot { // see https://pinout.xyz for a pin diagram neopixel: { gpioPin: 18, // default pin is GPIO 18 (physical pin 12) - grbFormat: false // if false, the RGB color format will be used for the LED; if true, the GRB format will be used + grbFormat: false, // if false, the RGB color format will be used for the LED; if true, the GRB format will be used }, commonAnode: { redPin: 19, // default red pin is GPIO 19 (physical pin 35) greenPin: 13, // default green pin is GPIO 13 (physical pin 33) - bluePin: 12 // default blue pin is GPIO 12 (physical pin 32) - } - } + bluePin: 12, // default blue pin is GPIO 12 (physical pin 32) + }, + }, }; /** @@ -265,35 +266,36 @@ class TJBot { hardware.forEach((device) => { switch (device) { - case TJBot.HARDWARE.CAMERA: - this._setupCamera(); - break; - - case TJBot.HARDWARE.LED_NEOPIXEL: - this._setupLEDNeopixel(this.configuration.shine.neopixel.gpioPin); - break; - - case TJBot.HARDWARE.LED_COMMON_ANODE: - this._setupLEDCommonAnode( - this.configuration.shine.commonAnode.redPin, - this.configuration.shine.commonAnode.greenPin, - this.configuration.shine.commonAnode.bluePin); - break; - - case TJBot.HARDWARE.MICROPHONE: - this._setupMicrophone(); - break; - - case TJBot.HARDWARE.SERVO: - this._setupServo(this.configuration.wave.servoPin); - break; - - case TJBot.HARDWARE.SPEAKER: - this._setupSpeaker(); - break; - - default: - break; + case TJBot.HARDWARE.CAMERA: + this._setupCamera(); + break; + + case TJBot.HARDWARE.LED_NEOPIXEL: + this._setupLEDNeopixel(this.configuration.shine.neopixel.gpioPin); + break; + + case TJBot.HARDWARE.LED_COMMON_ANODE: + this._setupLEDCommonAnode( + this.configuration.shine.commonAnode.redPin, + this.configuration.shine.commonAnode.greenPin, + this.configuration.shine.commonAnode.bluePin, + ); + break; + + case TJBot.HARDWARE.MICROPHONE: + this._setupMicrophone(); + break; + + case TJBot.HARDWARE.SERVO: + this._setupServo(this.configuration.wave.servoPin); + break; + + case TJBot.HARDWARE.SPEAKER: + this._setupSpeaker(); + break; + + default: + break; } }, this); } @@ -332,7 +334,7 @@ class TJBot { // init with 1 LED this._neopixelLed = ws281x; this._neopixelLed.init(1, { - gpioPin: gpioPin + gpioPin, }); // capture 'this' context @@ -359,14 +361,14 @@ class TJBot { this._commonAnodeLed = { redPin: new Gpio(redPin, { - mode: Gpio.OUTPUT + mode: Gpio.OUTPUT, }), greenPin: new Gpio(greenPin, { - mode: Gpio.OUTPUT + mode: Gpio.OUTPUT, }), bluePin: new Gpio(bluePin, { - mode: Gpio.OUTPUT - }) + mode: Gpio.OUTPUT, + }), }; } @@ -449,69 +451,69 @@ class TJBot { winston.verbose(`initializing ${service} service`); switch (service) { - case TJBot.SERVICES.ASSISTANT: { - // https://cloud.ibm.com/apidocs/assistant-v2 - const defaultVersion = '2018-09-19'; - - // there seems to be a bug in the AssistantV2 service where - // the service name is 'conversation', so it expects the environment - // variables for the credentails to be named CONVERSATION_*, but - // when downloading the credentials files, they are named - // ASSISTANT_* - // AssistantV2.DEFAULT_SERVICE_NAME = 'assistant'; - - this._assistant = new AssistantV2({ - serviceName: 'assistant', - version: version || defaultVersion, - }); - break; - } + case TJBot.SERVICES.ASSISTANT: { + // https://cloud.ibm.com/apidocs/assistant-v2 + const defaultVersion = '2018-09-19'; + + // there seems to be a bug in the AssistantV2 service where + // the service name is 'conversation', so it expects the environment + // variables for the credentails to be named CONVERSATION_*, but + // when downloading the credentials files, they are named + // ASSISTANT_* + // AssistantV2.DEFAULT_SERVICE_NAME = 'assistant'; + + this._assistant = new AssistantV2({ + serviceName: 'assistant', + version: version || defaultVersion, + }); + break; + } - case TJBot.SERVICES.LANGUAGE_TRANSLATOR: { - // https://cloud.ibm.com/apidocs/language-translator - const defaultVersion = '2018-05-01'; + case TJBot.SERVICES.LANGUAGE_TRANSLATOR: { + // https://cloud.ibm.com/apidocs/language-translator + const defaultVersion = '2018-05-01'; - this._languageTranslator = new LanguageTranslatorV3({ - version: version || defaultVersion, - }); - break; - } + this._languageTranslator = new LanguageTranslatorV3({ + version: version || defaultVersion, + }); + break; + } - case TJBot.SERVICES.SPEECH_TO_TEXT: { - // https://cloud.ibm.com/apidocs/speech-to-text - this._stt = new SpeechToTextV1({}); - break; - } + case TJBot.SERVICES.SPEECH_TO_TEXT: { + // https://cloud.ibm.com/apidocs/speech-to-text + this._stt = new SpeechToTextV1({}); + break; + } - case TJBot.SERVICES.TEXT_TO_SPEECH: { - // https://cloud.ibm.com/apidocs/text-to-speech - this._tts = new TextToSpeechV1({}); - break; - } + case TJBot.SERVICES.TEXT_TO_SPEECH: { + // https://cloud.ibm.com/apidocs/text-to-speech + this._tts = new TextToSpeechV1({}); + break; + } - case TJBot.SERVICES.TONE_ANALYZER: { - // https://cloud.ibm.com/apidocs/tone-analyzer - const defaultVersion = '2017-09-21'; + case TJBot.SERVICES.TONE_ANALYZER: { + // https://cloud.ibm.com/apidocs/tone-analyzer + const defaultVersion = '2017-09-21'; - this._toneAnalyzer = new ToneAnalyzerV3({ - version: version || defaultVersion, - }); - break; - } + this._toneAnalyzer = new ToneAnalyzerV3({ + version: version || defaultVersion, + }); + break; + } - case TJBot.SERVICES.VISUAL_RECOGNITION: { - // https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v3 - const defaultVersion = '2018-03-19'; + case TJBot.SERVICES.VISUAL_RECOGNITION: { + // https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v3 + const defaultVersion = '2018-03-19'; - this._visualRecognition = new VisualRecognitionV3({ - serviceName: 'visual_recognition', - version: version || defaultVersion, - }); - break; - } + this._visualRecognition = new VisualRecognitionV3({ + serviceName: 'visual_recognition', + version: version || defaultVersion, + }); + break; + } - default: - break; + default: + break; } } @@ -523,94 +525,94 @@ class TJBot { */ _assertCapability(capability) { switch (capability) { - case TJBot.CAPABILITIES.ANALYZE_TONE: - if (!this._toneAnalyzer) { - this._createServiceAPI(TJBot.SERVICES.TONE_ANALYZER); - } - break; + case TJBot.CAPABILITIES.ANALYZE_TONE: + if (!this._toneAnalyzer) { + this._createServiceAPI(TJBot.SERVICES.TONE_ANALYZER); + } + break; - case TJBot.CAPABILITIES.CONVERSE: - if (!this.configuration.converse.assistantId) { - throw new Error( - 'TJBot is not configured to converse. ' + case TJBot.CAPABILITIES.CONVERSE: + if (!this.configuration.converse.assistantId) { + throw new Error( + 'TJBot is not configured to converse. ' + 'Please check that you defined an assistantId for the ' + 'converse.assistantId parameter in the TJBot initialize() method.', - ); - } - if (!this._assistant) { - this._createServiceAPI(TJBot.SERVICES.ASSISTANT); - } - break; + ); + } + if (!this._assistant) { + this._createServiceAPI(TJBot.SERVICES.ASSISTANT); + } + break; - case TJBot.CAPABILITIES.LISTEN: - if (!this._mic) { - throw new Error( - 'TJBot is not configured to listen. ' + case TJBot.CAPABILITIES.LISTEN: + if (!this._mic) { + throw new Error( + 'TJBot is not configured to listen. ' + 'Please check that you included the ' + `${TJBot.HARDWARE.MICROPHONE} hardware in the TJBot initialize() method.`, - ); - } - if (!this._stt) { - this._createServiceAPI(TJBot.SERVICES.SPEECH_TO_TEXT); - } - break; + ); + } + if (!this._stt) { + this._createServiceAPI(TJBot.SERVICES.SPEECH_TO_TEXT); + } + break; - case TJBot.CAPABILITIES.SEE: - if (!this._camera) { - throw new Error( - 'TJBot is not configured to see. ' + case TJBot.CAPABILITIES.SEE: + if (!this._camera) { + throw new Error( + 'TJBot is not configured to see. ' + 'Please check that you included the ' + `${TJBot.HARDWARE.CAMERA} hardware in the TJBot initialize() method.`, - ); - } - if (!this._visualRecognition) { - this._createServiceAPI(TJBot.SERVICES.VISUAL_RECOGNITION); - } - break; + ); + } + if (!this._visualRecognition) { + this._createServiceAPI(TJBot.SERVICES.VISUAL_RECOGNITION); + } + break; - case TJBot.CAPABILITIES.SHINE: - // one LED should be defined - if (!this._neopixelLed && !this._commonAnodeLed) { - throw new Error( - 'TJBot is not configured with an LED. ' + case TJBot.CAPABILITIES.SHINE: + // one LED should be defined + if (!this._neopixelLed && !this._commonAnodeLed) { + throw new Error( + 'TJBot is not configured with an LED. ' + 'Please check that you included the ' + `${TJBot.HARDWARE.LED_NEOPIXEL} or ${TJBot.HARDWARE.LED_COMMON_ANODE} ` + 'hardware in the TJBot initialize() method.', - ); - } - break; + ); + } + break; - case TJBot.CAPABILITIES.SPEAK: - if (!this._soundplayer) { - throw new Error( - 'TJBot is not configured to speak. ' + case TJBot.CAPABILITIES.SPEAK: + if (!this._soundplayer) { + throw new Error( + 'TJBot is not configured to speak. ' + 'Please check that you included the ' + `${TJBot.HARDWARE.SPEAKER} hardware in the TJBot initialize() method.`, - ); - } - if (!this._tts) { - this._createServiceAPI(TJBot.SERVICES.TEXT_TO_SPEECH); - } - break; + ); + } + if (!this._tts) { + this._createServiceAPI(TJBot.SERVICES.TEXT_TO_SPEECH); + } + break; - case TJBot.CAPABILITIES.TRANSLATE: - if (!this._languageTranslator) { - this._createServiceAPI(TJBot.SERVICES.LANGUAGE_TRANSLATOR); - } - break; + case TJBot.CAPABILITIES.TRANSLATE: + if (!this._languageTranslator) { + this._createServiceAPI(TJBot.SERVICES.LANGUAGE_TRANSLATOR); + } + break; - case TJBot.CAPABILITIES.WAVE: - if (!this._motor) { - throw new Error( - 'TJBot is not configured with an arm. ' + case TJBot.CAPABILITIES.WAVE: + if (!this._motor) { + throw new Error( + 'TJBot is not configured with an arm. ' + 'Please check that you included the ' + `${TJBot.HARDWARE.SERVO} hardware in the TJBot initialize() method.`, - ); - } - break; + ); + } + break; - default: - break; + default: + break; } } @@ -976,7 +978,7 @@ class TJBot { /** * Internal method to capture an image at the given path. Used to avoid triggering - * the check for an apikey for Watson Visual Recognition in _assertCapability() + * the check for an apikey for Watson Visual Recognition in _assertCapability() * during testing. * @param {string=} filePath (optional) Path at which to save the photo file. If not * specified, photo will be saved in a temp location. @@ -1223,24 +1225,25 @@ class TJBot { /** * Convert hex color code to RGB value. - * @param {string} hexColor Hex color code + * @param {string} hexColor Hex color code * @return {array} RGB color (e.g. (255, 128, 128)) * @private */ + // eslint-disable-next-line class-methods-use-this _convertHexToRgbColor(hexColor) { - return hexColor.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i - , (m, r, g, b) => '#' + r + r + g + g + b + b) + return hexColor.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, + (m, r, g, b) => `#${r}${r}${g}${g}${b}${b}`) .substring(1).match(/.{2}/g) - .map(x => parseInt(x, 16)) + .map((x) => parseInt(x, 16)); } /** * Render the given rgb color for the common anode led. - * @param {string} hexColor Color in hex format + * @param {string} hexColor Color in hex format * @private */ _renderCommonAnodeLed(hexColor) { - const rgb = this._convertHexToRgbColor(hexColor) + const rgb = this._convertHexToRgbColor(hexColor); this._commonAnodeLed.redPin.pwmWrite(rgb[0] == null ? 255 : 255 - rgb[0]); this._commonAnodeLed.greenPin.pwmWrite(rgb[1] == null ? 255 : 255 - rgb[1]); this._commonAnodeLed.bluePin.pwmWrite(rgb[2] == null ? 255 : 255 - rgb[2]); @@ -1556,30 +1559,30 @@ class TJBot { // eslint-disable-next-line class-methods-use-this languageForCode(languageCode) { switch (languageCode.toLowerCase()) { - case 'ar': - return 'Arabic'; - case 'de': - return 'German'; - case 'en': - return 'English'; - case 'es': - return 'Spanish'; - case 'fr': - return 'French'; - case 'it': - return 'Italian'; - case 'ja': - return 'Japanese'; - case 'ko': - return 'Korean'; - case 'nl': - return 'Dutch'; - case 'pt': - return 'Portuguese'; - case 'zh': - return 'Chinese'; - default: - return undefined; + case 'ar': + return 'Arabic'; + case 'de': + return 'German'; + case 'en': + return 'English'; + case 'es': + return 'Spanish'; + case 'fr': + return 'French'; + case 'it': + return 'Italian'; + case 'ja': + return 'Japanese'; + case 'ko': + return 'Korean'; + case 'nl': + return 'Dutch'; + case 'pt': + return 'Portuguese'; + case 'zh': + return 'Chinese'; + default: + return undefined; } } @@ -1591,30 +1594,30 @@ class TJBot { // eslint-disable-next-line class-methods-use-this codeForLanguage(language) { switch (language.toLowerCase()) { - case 'arabic': - return 'ar'; - case 'german': - return 'de'; - case 'english': - return 'en'; - case 'spanish': - return 'es'; - case 'french': - return 'fr'; - case 'italian': - return 'it'; - case 'japanese': - return 'ja'; - case 'korean': - return 'ko'; - case 'dutch': - return 'nl'; - case 'portuguese': - return 'pt'; - case 'chinese': - return 'zh'; - default: - return undefined; + case 'arabic': + return 'ar'; + case 'german': + return 'de'; + case 'english': + return 'en'; + case 'spanish': + return 'es'; + case 'french': + return 'fr'; + case 'italian': + return 'it'; + case 'japanese': + return 'ja'; + case 'korean': + return 'ko'; + case 'dutch': + return 'nl'; + case 'portuguese': + return 'pt'; + case 'chinese': + return 'zh'; + default: + return undefined; } }