diff --git a/index.js b/index.js index b9d1e39..93ff9bd 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ function cloud (username, password, version) { function local (username, password, ip, version, interval) { if (version === 1) return localV1(username, password, ip); - return localV2(username, password, ip, interval); + return localV2(username, password, ip, interval, version); } module.exports = { diff --git a/lib/v2/local.js b/lib/v2/local.js index 97156d1..8f93b1c 100644 --- a/lib/v2/local.js +++ b/lib/v2/local.js @@ -2,15 +2,25 @@ const mqtt = require('mqtt'); -var dorita980 = function localV2 (user, password, host, emitIntervalTime) { +var dorita980 = function localV2 (user, password, host, emitIntervalTime, version) { if (!user) throw new Error('robotID is required.'); if (!password) throw new Error('password is required.'); if (!host) throw new Error('host is required.'); const posibleCap = ['pose', 'ota', 'multiPass', 'carpetBoost', 'pp', 'binFullDetect', 'langOta', 'maps', 'edge', 'eco', 'svcConf']; + const versionProps = { + 2: ['audio', 'soundVer', 'cleanSchedule', 'uiSwVer', 'navSwVer', 'wifiSwVer', 'mobilityVer', 'bootloaderVer', 'umiVer'], + 3: ['subModSwVer', 'cleanSchedule2'] + }; + const modelProps = { + 'roomba': ['bin'], + 'braava': ['detectedPad', 'mopReady', 'padWetness'] + }; + version = version || 2; emitIntervalTime = emitIntervalTime || 800; var robotState = {}; var cap = null; + var model = 'roomba'; var missionInterval; const url = 'tls://' + host; @@ -56,6 +66,9 @@ var dorita980 = function localV2 (user, password, host, emitIntervalTime) { cap = {}; cap = Object.assign(cap, robotState.cap); } + if (robotState.sku && robotState.sku.toLowerCase().startsWith("m6")) { + model = 'braava'; + } } catch (e) {} } }); @@ -81,6 +94,18 @@ var dorita980 = function localV2 (user, password, host, emitIntervalTime) { if (posibleCap.indexOf(properties[p]) > -1 && cap && Object.keys(cap).indexOf(properties[p]) === -1) { obj[properties[p]] = undefined; // asking for a non available capability, just set to undefined } + for (var ver in versionProps) { + if (ver != version && versionProps[ver].indexOf(properties[p]) > -1) { + obj[properties[p]] = undefined; // this is a property for a different version of API + console.log(properties[p]); + } + } + for (var mod in modelProps) { + if (mod != model && modelProps[mod].indexOf(properties[p]) > -1) { + obj[properties[p]] = undefined; // this is a property for a different model + console.log(properties[p]); + } + } if (!obj.hasOwnProperty(properties[p])) { return false; } @@ -113,15 +138,16 @@ var dorita980 = function localV2 (user, password, host, emitIntervalTime) { getTime: () => waitPreferences(false, ['utctime'], true), getBbrun: () => waitPreferences(false, ['bbrun'], true), getLangs: () => waitPreferences(false, ['langs'], true), - getSys: () => waitPreferences(false, ['bbrstinfo', 'cap', 'sku', 'batteryType', 'soundVer', 'uiSwVer', 'navSwVer', 'wifiSwVer', 'mobilityVer', 'bootloaderVer', 'umiVer', 'softwareVer', 'audio', 'bin'], true), + getSys: () => waitPreferences(false, ['bbrstinfo', 'cap', 'sku', 'batteryType', 'soundVer', 'uiSwVer', 'navSwVer', 'wifiSwVer', 'mobilityVer', 'bootloaderVer', 'umiVer', 'softwareVer', 'audio', 'bin', 'subModSwVer', 'secureBoot', 'detectedPad'], true), getWirelessLastStatus: () => waitPreferences(false, ['wifistat', 'wlcfg'], true), - getWeek: () => waitPreferences(false, ['cleanSchedule'], true), - getPreferences: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'cleanSchedule', 'name', 'vacHigh', 'signal'], false), + getWeek: () => waitPreferences(false, ['cleanSchedule', 'cleanSchedule2'], true), + getPreferences: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'cleanSchedule', 'cleanSchedule2', 'name', 'vacHigh', 'signal'], false), getRobotState: (fields) => waitPreferences(false, fields, false), - getMission: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'pose', 'bin', 'batPct'], true), - getBasicMission: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'bin', 'batPct'], true), + getMission: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'pose', 'bin', 'batPct', 'detectedPad', 'mopReady', 'padWetness'], true), + getBasicMission: (decode) => waitPreferences(decode, ['cleanMissionStatus', 'bin', 'batPct', 'detectedPad', 'mopReady', 'padWetness'], true), getWirelessConfig: () => waitPreferences(false, ['wlcfg', 'netinfo'], true), getWirelessStatus: () => waitPreferences(false, ['wifistat', 'netinfo'], true), + getModel: () => new Promise((resolve) => resolve(model)), getCloudConfig: () => waitPreferences(false, ['cloudEnv'], true), getSKU: () => waitPreferences(false, ['sku'], true), start: () => _apiCall('cmd', 'start'),