This commit is contained in:
Arne Blumentritt 2021-05-04 14:08:54 +02:00
parent 7173b2ec9e
commit 552e360f6f
4 changed files with 26 additions and 21 deletions

View File

@ -13,16 +13,16 @@
"dist" "dist"
], ],
"rules": { "rules": {
"quotes": ["warn", "single"], "quotes": ["warn", "double"],
"indent": ["warn", 2, { "SwitchCase": 1 }], "indent": ["warn", "tab"],
"semi": ["off"], "semi": ["off"],
"comma-dangle": ["warn", "always-multiline"], "comma-dangle": ["warn", "always-multiline"],
"dot-notation": "off", "dot-notation": "off",
"eqeqeq": "warn", "eqeqeq": "warn",
"curly": ["warn", "all"], "curly": ["warn", "all"],
"brace-style": ["warn"], "brace-style": ["warn", "allman"],
"prefer-arrow-callback": ["warn"], "prefer-arrow-callback": ["warn"],
"max-len": ["warn", 140], "max-len": ["warn", 200],
"no-console": ["warn"], // use the provided Homebridge log method instead "no-console": ["warn"], // use the provided Homebridge log method instead
"no-non-null-assertion": ["off"], "no-non-null-assertion": ["off"],
"comma-spacing": ["error"], "comma-spacing": ["error"],

View File

@ -1,7 +1,7 @@
import {API, Characteristic, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service} from 'homebridge'; import {API, Characteristic, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service} from "homebridge";
import NeatoApi from "node-botvac"; import NeatoApi from "node-botvac";
import {PLATFORM_NAME, PLUGIN_NAME} from './settings'; import {PLATFORM_NAME, PLUGIN_NAME} from "./settings";
import {NeatoVacuumRobotAccessory} from './accessories/NeatoVacuumRobot'; import {NeatoVacuumRobotAccessory} from "./accessories/NeatoVacuumRobot";
/** /**
* HomebridgePlatform * HomebridgePlatform
@ -21,7 +21,8 @@ export class HomebridgeNeatoPlatform implements DynamicPlatformPlugin
public readonly config: PlatformConfig, public readonly config: PlatformConfig,
public readonly api: API) public readonly api: API)
{ {
this.api.on('didFinishLaunching', () => { this.api.on("didFinishLaunching", () =>
{
this.discoverRobots(); this.discoverRobots();
}); });
} }
@ -38,12 +39,13 @@ export class HomebridgeNeatoPlatform implements DynamicPlatformPlugin
discoverRobots() discoverRobots()
{ {
let client = new NeatoApi.Client(); const client = new NeatoApi.Client();
try try
{ {
// Login // Login
client.authorize((this.config)['email'], (this.config)['password'], false, (error) => { client.authorize((this.config)["email"], (this.config)["password"], false, (error) =>
{
if (error) if (error)
{ {
this.log.warn("Cannot connect to neato server. No new robots will be found and existing robots will be unresponsive."); this.log.warn("Cannot connect to neato server. No new robots will be found and existing robots will be unresponsive.");
@ -53,7 +55,8 @@ export class HomebridgeNeatoPlatform implements DynamicPlatformPlugin
} }
// Get all robots from account // Get all robots from account
client.getRobots((error, robots) => { client.getRobots((error, robots) =>
{
if (error) if (error)
{ {
this.log.error("Successful login but can't connect to your neato robot: " + error); this.log.error("Successful login but can't connect to your neato robot: " + error);
@ -67,12 +70,13 @@ export class HomebridgeNeatoPlatform implements DynamicPlatformPlugin
return; return;
} }
this.log.info("Neato account has " + robots.length + " robot " + (robots.length == 1 ? "" : "s")); this.log.info("Neato account has " + robots.length + " robot " + (robots.length === 1 ? "" : "s"));
for (let robot of robots) for (const robot of robots)
{ {
// Get additional information for the robot // Get additional information for the robot
robot.getState((error, state) => { robot.getState((error, state) =>
{
if (error) if (error)
{ {
this.log.error("Error getting robot meta information: " + error + ": " + state); this.log.error("Error getting robot meta information: " + error + ": " + state);

View File

@ -1,11 +1,12 @@
import { API } from 'homebridge'; import {API} from "homebridge";
import { PLATFORM_NAME } from './settings'; import {PLATFORM_NAME} from "./settings";
import { HomebridgeNeatoPlatform } from './homebridgeNeatoPlatform'; import {HomebridgeNeatoPlatform} from "./homebridgeNeatoPlatform";
/** /**
* This method registers the platform with Homebridge * This method registers the platform with Homebridge
*/ */
export = (api: API) => { export = (api: API) =>
{
api.registerPlatform(PLATFORM_NAME, HomebridgeNeatoPlatform); api.registerPlatform(PLATFORM_NAME, HomebridgeNeatoPlatform);
}; };

View File

@ -1,9 +1,9 @@
/** /**
* This is the name of the platform that users will use to register the plugin in the Homebridge config.json * This is the name of the platform that users will use to register the plugin in the Homebridge config.json
*/ */
export const PLATFORM_NAME = 'NeatoVacuumRobot'; export const PLATFORM_NAME = "NeatoVacuumRobot";
/** /**
* This must match the name of your plugin as defined the package.json * This must match the name of your plugin as defined the package.json
*/ */
export const PLUGIN_NAME = 'homebridge-neato'; export const PLUGIN_NAME = "homebridge-neato";