homebridge-irobot
Version:
A homebridge plugin for controlling iRobot devices
98 lines • 3.28 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRoombas = void 0;
const child_process_1 = __importDefault(require("child_process"));
function getRoombas(email, password, log, config) {
//child_process.execSync('chmod -R 755 "' + __dirname + '/scripts"');
let robots = [];
if (config.manualDiscovery) {
log.info('Using manual discovery due to config');
robots = config.roombas || [];
}
else {
log.info('Logging into iRobot...');
const Robots = child_process_1.default.execFileSync(__dirname + '/scripts/getRoombaCredentials.js', [email, password]).toString();
try {
robots = JSON.parse(Robots);
log.debug(Robots);
}
catch (e) {
log.error('Faild to login to iRobot, see below for details');
log.error(Robots);
}
}
const badRoombas = [];
robots.forEach(robot => {
if (robot.autoConfig || !config.autoDiscovery) {
log.info('Configuring roomba:', robot.name);
const robotIP = child_process_1.default.execFileSync(__dirname + '/scripts/getRoombaIP.js', [robot.blid]).toString();
try {
const robotInfo = JSON.parse(robotIP);
log.debug(robotIP);
robot.ip = robotInfo.ip;
delete robotInfo.ip;
robot.model = getModel(robotInfo.sku);
robot.multiRoom = getMultiRoom(robot.model);
robot.info = robotInfo;
if (robotInfo.sku.startsWith('m6')) {
badRoombas.push(robots.indexOf(robot));
}
}
catch (e) {
try {
log.error('Failed to configure roomba:', robot.name, 'see below for details');
log.error(robotIP);
}
finally {
badRoombas.push(robots.indexOf(robot));
}
}
}
else {
log.info('Skipping configuration for roomba:', robot.name, 'due to config');
}
});
for (const roomba of badRoombas) {
log.warn('Disabling Unconfigured Roomba:', robots[roomba].name);
try {
robots.splice(roomba);
}
catch (e) {
log.error('Failed To Disable Unconfigured Roomba:', robots[roomba].name, 'see below for details');
log.error(e);
}
}
return robots;
}
exports.getRoombas = getRoombas;
function getModel(sku) {
switch (sku.charAt(0)) {
case 'j':
case 'i':
case 's':
return sku.substring(0, 2);
case 'R':
return sku.substring(1, 4);
default:
return sku;
}
}
function getMultiRoom(model) {
switch (model.charAt(0)) {
case 's':
case 'j':
case 'i':
if (parseInt(model.charAt(1)) > 4) {
return true;
}
else {
return false;
}
default:
return false;
}
}
//# sourceMappingURL=getRoombas.js.map