Skip to content

Commit

Permalink
Added support for FW version 3 and Braava m6
Browse files Browse the repository at this point in the history
  • Loading branch information
peci1 committed Dec 29, 2019
1 parent 54be883 commit aaf6c14
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
36 changes: 30 additions & 6 deletions lib/v2/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {}
}
});
Expand All @@ -81,6 +94,16 @@ 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
}
}
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
}
}
if (!obj.hasOwnProperty(properties[p])) {
return false;
}
Expand Down Expand Up @@ -113,15 +136,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'),
Expand Down

0 comments on commit aaf6c14

Please sign in to comment.