eslint compliance
This commit is contained in:
parent
9a9789328f
commit
82808d7850
@ -1,7 +1,9 @@
|
||||
import type { Characteristic, WithUUID } from 'homebridge';
|
||||
import { Formats, Perms } from 'homebridge';
|
||||
|
||||
export default function spotHeight(CustomCharacteristic: typeof Characteristic): WithUUID<new () => Characteristic> {
|
||||
export default function spotHeight(
|
||||
CustomCharacteristic: typeof Characteristic,
|
||||
): WithUUID<new () => Characteristic> {
|
||||
return class SpotHeight extends CustomCharacteristic {
|
||||
static readonly UUID = 'CA282DB2-62BF-4325-A1BE-F8BB5478781A';
|
||||
|
||||
@ -12,7 +14,7 @@ export default function spotHeight(CustomCharacteristic: typeof Characteristic):
|
||||
maxValue: 400,
|
||||
minValue: 100,
|
||||
minStep: 50,
|
||||
perms: [Perms.PAIRED_READ, Perms.PAIRED_WRITE]
|
||||
perms: [Perms.PAIRED_READ, Perms.PAIRED_WRITE],
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,14 +1,16 @@
|
||||
import type { Characteristic, WithUUID } from 'homebridge';
|
||||
import { Formats, Perms } from 'homebridge';
|
||||
|
||||
export default function spotRepeat(CustomCharacteristic: typeof Characteristic): WithUUID<new () => Characteristic> {
|
||||
export default function spotRepeat(
|
||||
CustomCharacteristic: typeof Characteristic,
|
||||
): WithUUID<new () => Characteristic> {
|
||||
return class SpotRepeat extends CustomCharacteristic {
|
||||
static readonly UUID = '1E79C603-63B8-4E6A-9CE1-D31D67981831';
|
||||
|
||||
constructor() {
|
||||
super('Spot 2x', SpotRepeat.UUID, {
|
||||
format: Formats.BOOL,
|
||||
perms: [Perms.PAIRED_READ, Perms.PAIRED_WRITE]
|
||||
perms: [Perms.PAIRED_READ, Perms.PAIRED_WRITE],
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,7 +1,9 @@
|
||||
import type { Characteristic, WithUUID } from 'homebridge';
|
||||
import { Formats, Perms } from 'homebridge';
|
||||
|
||||
export default function spotWidth(CustomCharacteristic: typeof Characteristic): WithUUID<new () => Characteristic> {
|
||||
export default function spotWidth(
|
||||
CustomCharacteristic: typeof Characteristic,
|
||||
): WithUUID<new () => Characteristic> {
|
||||
return class SpotWidth extends CustomCharacteristic {
|
||||
static readonly UUID = 'A7889A9A-2F27-4293-BEF8-3FE805B36F4E';
|
||||
|
||||
@ -12,7 +14,7 @@ export default function spotWidth(CustomCharacteristic: typeof Characteristic):
|
||||
maxValue: 400,
|
||||
minValue: 100,
|
||||
minStep: 50,
|
||||
perms: [Perms.PAIRED_READ, Perms.PAIRED_WRITE]
|
||||
perms: [Perms.PAIRED_READ, Perms.PAIRED_WRITE],
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { RobotService } from "./models/services";
|
||||
import { RobotService } from './models/services';
|
||||
|
||||
export const BACKGROUND_INTERVAL = 30;
|
||||
export const PREFIX = false;
|
||||
export const ALL_SERVICES = new Set(Object.values(RobotService));
|
||||
export const LOCALE = "en"
|
||||
export const LOCALE = 'en';
|
||||
|
@ -1,17 +1,25 @@
|
||||
import {API, Characteristic, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service} from "homebridge";
|
||||
import KoboldApi from "node-kobold-control";
|
||||
import {PLATFORM_NAME, PLUGIN_NAME} from "./settings";
|
||||
import {KoboldVacuumRobotAccessory} from "./accessories/koboldVacuumRobot";
|
||||
import {
|
||||
API,
|
||||
Characteristic,
|
||||
DynamicPlatformPlugin,
|
||||
Logger,
|
||||
PlatformAccessory,
|
||||
PlatformConfig,
|
||||
Service,
|
||||
} from 'homebridge';
|
||||
import KoboldApi from 'node-kobold-control';
|
||||
import { PLATFORM_NAME, PLUGIN_NAME } from './settings';
|
||||
import { KoboldVacuumRobotAccessory } from './accessories/koboldVacuumRobot';
|
||||
|
||||
/**
|
||||
* HomebridgePlatform
|
||||
* This class is the main constructor for your plugin, this is where you should
|
||||
* parse the user config and discover/register accessories with Homebridge.
|
||||
*/
|
||||
export class HomebridgeKoboldPlatform implements DynamicPlatformPlugin
|
||||
{
|
||||
export class HomebridgeKoboldPlatform implements DynamicPlatformPlugin {
|
||||
public readonly Service: typeof Service = this.api.hap.Service;
|
||||
public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic;
|
||||
public readonly Characteristic: typeof Characteristic =
|
||||
this.api.hap.Characteristic;
|
||||
|
||||
// this is used to track restored cached accessories
|
||||
public readonly cachedRobotAccessories: PlatformAccessory[] = [];
|
||||
@ -19,9 +27,9 @@ export class HomebridgeKoboldPlatform implements DynamicPlatformPlugin
|
||||
constructor(
|
||||
public readonly log: Logger,
|
||||
public readonly config: PlatformConfig,
|
||||
public readonly api: API)
|
||||
{
|
||||
this.api.on("didFinishLaunching", () => {
|
||||
public readonly api: API,
|
||||
) {
|
||||
this.api.on('didFinishLaunching', () => {
|
||||
this.discoverRobots();
|
||||
});
|
||||
}
|
||||
@ -30,25 +38,24 @@ export class HomebridgeKoboldPlatform implements DynamicPlatformPlugin
|
||||
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
||||
* It should be used to setup event handlers for characteristics and update respective values.
|
||||
*/
|
||||
configureAccessory(accessory: PlatformAccessory)
|
||||
{
|
||||
configureAccessory(accessory: PlatformAccessory) {
|
||||
// add the restored accessory to the accessories cache so we can track if it has already been registered
|
||||
this.cachedRobotAccessories.push(accessory);
|
||||
}
|
||||
|
||||
|
||||
discoverRobots()
|
||||
{
|
||||
discoverRobots() {
|
||||
const client = new KoboldApi.Client();
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
// Login
|
||||
client.authorize((this.config)["token"], (error) => {
|
||||
if (error)
|
||||
{
|
||||
this.log.error("Cannot connect to Vorwerk server. No new robots will be found and existing robots will be unresponsive. Retrying in 5 minutes.");
|
||||
this.log.error("Error: " + error);
|
||||
client.authorize(this.config['token'], (error) => {
|
||||
if (error) {
|
||||
this.log.error(
|
||||
`Cannot connect to Vorwerk server.
|
||||
No new robots will be found and existing robots will be unresponsive.
|
||||
Retrying in 5 minutes.`,
|
||||
);
|
||||
this.log.error('Error: ' + error);
|
||||
|
||||
setTimeout(() => {
|
||||
this.discoverRobots();
|
||||
@ -58,10 +65,11 @@ export class HomebridgeKoboldPlatform implements DynamicPlatformPlugin
|
||||
|
||||
// Get all robots from account
|
||||
client.getRobots((error, robots) => {
|
||||
if (error)
|
||||
{
|
||||
this.log.error("Successful login but can't list the robots in your Vorwerk robots. Retrying in 5 minutes.");
|
||||
this.log.error("Error: " + error);
|
||||
if (error) {
|
||||
this.log.error(
|
||||
'Successful login but can\'t list the robots in your Vorwerk robots. Retrying in 5 minutes.',
|
||||
);
|
||||
this.log.error('Error: ' + error);
|
||||
|
||||
setTimeout(() => {
|
||||
this.discoverRobots();
|
||||
@ -70,89 +78,133 @@ export class HomebridgeKoboldPlatform implements DynamicPlatformPlugin
|
||||
}
|
||||
|
||||
// Vorwerk robots in account
|
||||
if (robots.length === 0)
|
||||
{
|
||||
this.log.error("Vorwerk account has no robots.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.log.info("Vorwerk account has " + robots.length + " robot" + (robots.length === 1 ? "" : "s"));
|
||||
if (robots.length === 0) {
|
||||
this.log.error('Vorwerk account has no robots.');
|
||||
} else {
|
||||
this.log.info(
|
||||
'Vorwerk account has ' +
|
||||
robots.length +
|
||||
' robot' +
|
||||
(robots.length === 1 ? '' : 's'),
|
||||
);
|
||||
}
|
||||
|
||||
// Vorwerk robots in cache
|
||||
this.log.debug("Plugin Cache has " + this.cachedRobotAccessories.length + " robot" + (this.cachedRobotAccessories.length === 1 ? "" : "s"));
|
||||
for (let cachedRobot of this.cachedRobotAccessories)
|
||||
{
|
||||
let accountRobot = robots.find(robot => this.api.hap.uuid.generate(robot._serial) === cachedRobot.UUID);
|
||||
if (accountRobot)
|
||||
{
|
||||
this.log.debug("[" + cachedRobot.displayName + "] Cached robot found in Vorwerk account.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.log.error("[" + cachedRobot.displayName + "] Cached robot not found in Vorwerk account. Robot will now be removed from homebridge.");
|
||||
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [cachedRobot]);
|
||||
this.log.debug(
|
||||
'Plugin Cache has ' +
|
||||
this.cachedRobotAccessories.length +
|
||||
' robot' +
|
||||
(this.cachedRobotAccessories.length === 1 ? '' : 's'),
|
||||
);
|
||||
for (const cachedRobot of this.cachedRobotAccessories) {
|
||||
const accountRobot = robots.find(
|
||||
(robot) =>
|
||||
this.api.hap.uuid.generate(robot._serial) === cachedRobot.UUID,
|
||||
);
|
||||
if (accountRobot) {
|
||||
this.log.debug(
|
||||
'[' +
|
||||
cachedRobot.displayName +
|
||||
'] Cached robot found in Vorwerk account.',
|
||||
);
|
||||
} else {
|
||||
this.log.error(
|
||||
'[' +
|
||||
cachedRobot.displayName +
|
||||
'] Cached robot not found in Vorwerk account. Robot will now be removed from homebridge.',
|
||||
);
|
||||
this.api.unregisterPlatformAccessories(
|
||||
PLUGIN_NAME,
|
||||
PLATFORM_NAME,
|
||||
[cachedRobot],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Add / Update homebridge accessories with robot information from Vorwerk. This must be done for new and existing robots to reflect changes in the name, firmware, pluginconfig etc.
|
||||
for (let robot of robots)
|
||||
{
|
||||
// Add / Update homebridge accessories with robot information from Vorwerk.
|
||||
// This must be done for new and existing robots to reflect changes in the name, firmware, pluginconfig etc.
|
||||
for (const robot of robots) {
|
||||
// Check if robot already exists as an accessory
|
||||
const uuid = this.api.hap.uuid.generate(robot._serial);
|
||||
const cachedRobot = this.cachedRobotAccessories.find(accessory => accessory.UUID === uuid);
|
||||
const cachedRobot = this.cachedRobotAccessories.find(
|
||||
(accessory) => accessory.UUID === uuid,
|
||||
);
|
||||
|
||||
if (cachedRobot)
|
||||
{
|
||||
this.log.debug("[" + robot.name + "] Connecting to cached robot and updating information.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.log.debug("[" + robot.name + "] Connecting to new robot and updating information.");
|
||||
if (cachedRobot) {
|
||||
this.log.debug(
|
||||
'[' +
|
||||
robot.name +
|
||||
'] Connecting to cached robot and updating information.',
|
||||
);
|
||||
} else {
|
||||
this.log.debug(
|
||||
'[' +
|
||||
robot.name +
|
||||
'] Connecting to new robot and updating information.',
|
||||
);
|
||||
}
|
||||
|
||||
robot.getState((error, state) => {
|
||||
if (error)
|
||||
{
|
||||
this.log.error("[" + robot.name + "] Cannot connect to robot. Is the robot connected to the internet? Retrying in 5 minutes.");
|
||||
this.log.error("Error: " + error);
|
||||
if (error) {
|
||||
this.log.error(
|
||||
'[' +
|
||||
robot.name +
|
||||
'] Cannot connect to robot. Is the robot connected to the internet? Retrying in 5 minutes.',
|
||||
);
|
||||
this.log.error('Error: ' + error);
|
||||
setTimeout(() => {
|
||||
this.discoverRobots();
|
||||
}, 5 * 60 * 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
} else {
|
||||
try {
|
||||
robot.meta = state.meta;
|
||||
robot.availableServices = state.availableServices;
|
||||
|
||||
// Update existing robot accessor
|
||||
if (cachedRobot)
|
||||
{
|
||||
if (cachedRobot) {
|
||||
// TODO update maps
|
||||
|
||||
cachedRobot.context.robot = robot;
|
||||
this.api.updatePlatformAccessories([cachedRobot]);
|
||||
new KoboldVacuumRobotAccessory(this, cachedRobot, this.config);
|
||||
this.log.info("[" + robot.name + "] Successfully loaded robot from cache");
|
||||
}
|
||||
new KoboldVacuumRobotAccessory(
|
||||
this,
|
||||
cachedRobot,
|
||||
this.config,
|
||||
);
|
||||
this.log.info(
|
||||
'[' +
|
||||
robot.name +
|
||||
'] Successfully loaded robot from cache',
|
||||
);
|
||||
} else {
|
||||
// Create new robot accessory
|
||||
else
|
||||
{
|
||||
// TODO get maps
|
||||
|
||||
const newRobot = new this.api.platformAccessory(robot.name, uuid);
|
||||
const newRobot = new this.api.platformAccessory(
|
||||
robot.name,
|
||||
uuid,
|
||||
);
|
||||
newRobot.context.robot = robot;
|
||||
new KoboldVacuumRobotAccessory(this, newRobot, this.config);
|
||||
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [newRobot]);
|
||||
this.log.info("[" + robot.name + "] Successfully created as new robot");
|
||||
this.api.registerPlatformAccessories(
|
||||
PLUGIN_NAME,
|
||||
PLATFORM_NAME,
|
||||
[newRobot],
|
||||
);
|
||||
this.log.info(
|
||||
'[' + robot.name + '] Successfully created as new robot',
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
this.log.error("[" + robot.name + "] Creating accessory failed. Error: " + error);
|
||||
throw new this.api.hap.HapStatusError(this.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
||||
} catch (error) {
|
||||
this.log.error(
|
||||
'[' +
|
||||
robot.name +
|
||||
'] Creating accessory failed. Error: ' +
|
||||
error,
|
||||
);
|
||||
throw new this.api.hap.HapStatusError(
|
||||
this.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,10 +262,12 @@ export class HomebridgeKoboldPlatform implements DynamicPlatformPlugin
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
this.log.error("Can't log on to Vorwerk cloud. Please check your internet connection and your credentials. Try again later if the neato servers have issues. Error: " + error);
|
||||
} catch (error) {
|
||||
this.log.error(
|
||||
`Can't log on to Vorwerk cloud. Please check your internet connection and your credentials.
|
||||
Try again later if the neato servers have issues. Error: ` +
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
import {API} from "homebridge";
|
||||
import { API } from 'homebridge';
|
||||
|
||||
import {PLATFORM_NAME} from "./settings";
|
||||
import {HomebridgeKoboldPlatform} from "./homebridgeKoboldPlatform";
|
||||
import { PLATFORM_NAME } from './settings';
|
||||
import { HomebridgeKoboldPlatform } from './homebridgeKoboldPlatform';
|
||||
|
||||
/**
|
||||
* This method registers the platform with Homebridge
|
||||
*/
|
||||
export = (api: API) =>
|
||||
{
|
||||
export = (api: API) => {
|
||||
api.registerPlatform(PLATFORM_NAME, HomebridgeKoboldPlatform);
|
||||
};
|
||||
|
@ -1,5 +1,4 @@
|
||||
export class Options
|
||||
{
|
||||
export class Options {
|
||||
public eco: boolean;
|
||||
public extraCare: boolean;
|
||||
public noGoLines: boolean;
|
||||
@ -8,8 +7,7 @@ export class Options
|
||||
public spotWidth: number;
|
||||
public spotHeight: number;
|
||||
|
||||
constructor()
|
||||
{
|
||||
constructor() {
|
||||
this.eco = false;
|
||||
this.extraCare = false;
|
||||
this.noGoLines = false;
|
||||
|
@ -4,16 +4,16 @@ export enum CleanType {
|
||||
}
|
||||
|
||||
export enum RobotService {
|
||||
CLEAN = "clean",
|
||||
CLEAN_SPOT = "cleanSpot",
|
||||
CLEAN_ZONE = "cleanZone",
|
||||
GO_TO_DOCK = "goToDock",
|
||||
DOCKED = "dockState",
|
||||
BIN_FULL = "binFull",
|
||||
FIND_ME = "findMe",
|
||||
SCHEDULE = "schedule",
|
||||
ECO = "eco",
|
||||
NOGO_LINES = "noGoLines",
|
||||
EXTRA_CARE = "extraCare",
|
||||
BATTERY = "battery",
|
||||
CLEAN = 'clean',
|
||||
CLEAN_SPOT = 'cleanSpot',
|
||||
CLEAN_ZONE = 'cleanZone',
|
||||
GO_TO_DOCK = 'goToDock',
|
||||
DOCKED = 'dockState',
|
||||
BIN_FULL = 'binFull',
|
||||
FIND_ME = 'findMe',
|
||||
SCHEDULE = 'schedule',
|
||||
ECO = 'eco',
|
||||
NOGO_LINES = 'noGoLines',
|
||||
EXTRA_CARE = 'extraCare',
|
||||
BATTERY = 'battery',
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user