homebridge-redmond-robot
Version:
Homebridge Plugin for Redmond Robot Vacuum
69 lines • 3.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedmondRobotPlatform = void 0;
const settings_1 = require("./settings");
const switchAccessory_1 = require("./switchAccessory");
const Redmond = require('./lib/redmond.js');
class RedmondRobotPlatform {
constructor(log, config, api) {
this.log = log;
this.config = config;
this.api = api;
this.Service = this.api.hap.Service;
this.Characteristic = this.api.hap.Characteristic;
this.accessories = [];
this.log.debug('Finished initializing platform:', settings_1.PLATFORM_NAME);
this.api.on('didFinishLaunching', () => {
log.debug('Executed didFinishLaunching callback');
this.discoverDevices();
});
}
configureAccessory(accessory) {
this.log.info('Loading accessory from cache:', accessory.displayName);
this.accessories.push(accessory);
}
async discoverDevices() {
const redmond = new Redmond(this.config.username, this.config.password, this.config.country);
const startMode = this.config.startMode || 'AutoClean';
const stopMode = this.config.stopMode || 'Standby';
const accessoryType = 'Switch';
redmond.device_list().then((devices) => {
for (const device of devices) {
redmond.get_device_description(device).then((thing) => {
const nickname = thing.Thing_Nick_Name;
const uuid = this.api.hap.uuid.generate(thing.thingId);
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
if (existingAccessory) {
this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName);
existingAccessory.context.device = thing;
existingAccessory.context.nickname = nickname;
existingAccessory.context.redmond = redmond;
existingAccessory.context.modes = { startMode: startMode, stopMode: stopMode };
this.api.updatePlatformAccessories([existingAccessory]);
switch (accessoryType) {
default:
new switchAccessory_1.SwitchAccessory(this, existingAccessory, this.log);
break;
}
}
else {
this.log.info('Adding new accessory:', nickname);
const accessory = new this.api.platformAccessory(nickname, uuid);
accessory.context.device = thing;
accessory.context.nickname = nickname;
accessory.context.redmond = redmond;
accessory.context.modes = { startMode: startMode, stopMode: stopMode };
switch (accessoryType) {
default:
new switchAccessory_1.SwitchAccessory(this, accessory, this.log);
this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
break;
}
}
});
}
});
}
}
exports.RedmondRobotPlatform = RedmondRobotPlatform;
//# sourceMappingURL=platform.js.map