Skip to content

Commit d69dcf0

Browse files
committed
Reduce info logging so the plugin is a lot quieter when not in debug logging mode
1 parent 7c51d8b commit d69dcf0

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

.changeset/brave-mice-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"homebridge-roomba2": patch
3+
---
4+
5+
Reduce info logging so the plugin is a lot quieter when not in debug logging mode

src/accessory.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ export default class RoombaAccessory implements AccessoryPlugin {
220220
}
221221

222222
public identify() {
223-
this.log("Identify requested");
223+
this.log.info("Identify requested");
224224
this.connect(async(error, roomba) => {
225225
if (error || !roomba) {
226226
return;
227227
}
228228
try {
229229
await roomba.find();
230230
} catch (error) {
231-
this.log("Roomba failed to locate: %s", (error as Error).message);
231+
this.log.warn("Roomba failed to locate: %s", (error as Error).message);
232232
}
233233
});
234234
}
@@ -269,7 +269,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
269269

270270
this.connect(async(error, roomba) => {
271271
if (error || !roomba) {
272-
this.log("Failed to connect to Roomba to refresh state: %s", error ? error.message : "Unknown");
272+
this.log.warn("Failed to connect to Roomba to refresh state: %s", error ? error.message : "Unknown");
273273
return;
274274
}
275275

@@ -430,7 +430,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
430430

431431
private setRunningState(powerOn: CharacteristicValue, callback: CharacteristicSetCallback) {
432432
if (powerOn) {
433-
this.log("Starting Roomba");
433+
this.log.info("Starting Roomba");
434434

435435
this.connect(async(error, roomba) => {
436436
if (error || !roomba) {
@@ -445,7 +445,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
445445
await roomba.clean();
446446
await roomba.resume();
447447

448-
this.log("Roomba is running");
448+
this.log.debug("Roomba is running");
449449

450450
callback();
451451

@@ -455,13 +455,13 @@ export default class RoombaAccessory implements AccessoryPlugin {
455455
/* After sending an action to Roomba, we start watching to ensure HomeKit has up to date status */
456456
this.startWatching();
457457
} catch (error) {
458-
this.log("Roomba failed: %s", (error as Error).message);
458+
this.log.warn("Roomba failed: %s", (error as Error).message);
459459

460460
callback(error as Error);
461461
}
462462
});
463463
} else {
464-
this.log("Stopping Roomba");
464+
this.log.info("Stopping Roomba");
465465

466466
this.connect(async(error, roomba) => {
467467
if (error || !roomba) {
@@ -474,7 +474,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
474474
const state = this.parseState(response);
475475

476476
if (state.running) {
477-
this.log("Roomba is pausing");
477+
this.log.debug("Roomba is pausing");
478478

479479
await roomba.pause();
480480

@@ -484,32 +484,32 @@ export default class RoombaAccessory implements AccessoryPlugin {
484484
this.refreshState();
485485

486486
if (this.stopBehaviour === "home") {
487-
this.log("Roomba paused, returning to Dock");
487+
this.log.debug("Roomba paused, returning to Dock");
488488
await this.dockWhenStopped(roomba, 3000);
489489
} else {
490-
this.log("Roomba is paused");
490+
this.log.debug("Roomba is paused");
491491
}
492492
} else if (state.docking) {
493-
this.log("Roomba is docking");
493+
this.log.debug("Roomba is docking");
494494
await roomba.pause();
495495

496496
callback();
497497

498498
/* Force a refresh of state so we pick up the new state quickly */
499499
this.refreshState();
500500

501-
this.log("Roomba paused");
501+
this.log.debug("Roomba paused");
502502
} else if (state.charging) {
503-
this.log("Roomba is already docked");
503+
this.log.debug("Roomba is already docked");
504504
callback();
505505
} else {
506-
this.log("Roomba is not running");
506+
this.log.debug("Roomba is not running");
507507
callback();
508508
}
509509

510510
this.startWatching();
511511
} catch (error) {
512-
this.log("Roomba failed: %s", (error as Error).message);
512+
this.log.warn("Roomba failed: %s", (error as Error).message);
513513

514514
callback(error as Error);
515515
}
@@ -518,7 +518,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
518518
}
519519

520520
private setDockingState(docking: CharacteristicValue, callback: CharacteristicSetCallback) {
521-
this.log("Setting docking state to %s", JSON.stringify(docking));
521+
this.log.debug("Setting docking state to %s", JSON.stringify(docking));
522522

523523
this.connect(async(error, roomba) => {
524524
if (error || !roomba) {
@@ -529,10 +529,10 @@ export default class RoombaAccessory implements AccessoryPlugin {
529529
try {
530530
if (docking) {
531531
await roomba.dock();
532-
this.log("Roomba is docking");
532+
this.log.debug("Roomba is docking");
533533
} else {
534534
await roomba.pause();
535-
this.log("Roomba is paused");
535+
this.log.debug("Roomba is paused");
536536
}
537537

538538
callback();
@@ -543,7 +543,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
543543
/* After sending an action to Roomba, we start watching to ensure HomeKit has up to date status */
544544
this.startWatching();
545545
} catch (error) {
546-
this.log("Roomba failed: %s", (error as Error).message);
546+
this.log.warn("Roomba failed: %s", (error as Error).message);
547547

548548
callback(error as Error);
549549
}
@@ -556,18 +556,18 @@ export default class RoombaAccessory implements AccessoryPlugin {
556556

557557
switch (state.cleanMissionStatus!.phase) {
558558
case "stop":
559-
this.log("Roomba has stopped, issuing dock request");
559+
this.log.debug("Roomba has stopped, issuing dock request");
560560

561561
await roomba.dock();
562562

563-
this.log("Roomba docking");
563+
this.log.debug("Roomba docking");
564564

565565
/* Force a refresh of state so we pick up the new state quickly */
566566
this.refreshState();
567567

568568
break;
569569
case "run":
570-
this.log("Roomba is still running. Will check again in %is", pollingInterval / 1000);
570+
this.log.debug("Roomba is still running. Will check again in %is", pollingInterval / 1000);
571571

572572
await delay(pollingInterval);
573573

@@ -576,7 +576,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
576576

577577
break;
578578
default:
579-
this.log("Roomba is not running");
579+
this.log.debug("Roomba is not running");
580580

581581
break;
582582
}
@@ -593,10 +593,10 @@ export default class RoombaAccessory implements AccessoryPlugin {
593593
const returnCachedStatus = (status: Status) => {
594594
const value = extractValue(status);
595595
if (value === undefined) {
596-
this.log("%s: Returning no value (%ims old)", name, Date.now() - status.timestamp!);
596+
this.log.debug("%s: Returning no value (%ims old)", name, Date.now() - status.timestamp!);
597597
callback(NO_VALUE);
598598
} else {
599-
this.log("%s: Returning %s (%ims old)", name, String(value), Date.now() - status.timestamp!);
599+
this.log.debug("%s: Returning %s (%ims old)", name, String(value), Date.now() - status.timestamp!);
600600
callback(null, value);
601601
}
602602
};
@@ -612,7 +612,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
612612
if (Date.now() - this.cachedStatus.timestamp < MAX_CACHED_STATUS_AGE_MILLIS) {
613613
returnCachedStatus(this.cachedStatus);
614614
} else {
615-
this.log("%s: Returning no value due to timeout", name);
615+
this.log.debug("%s: Returning no value due to timeout", name);
616616
callback(NO_VALUE);
617617
}
618618
}, 500);
@@ -688,7 +688,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
688688

689689
break;
690690
default:
691-
this.log.info("Unsupported phase: %s", state.cleanMissionStatus!.phase);
691+
this.log.warn("Unsupported phase: %s", state.cleanMissionStatus!.phase);
692692

693693
status.running = false;
694694
status.charging = false;
@@ -792,7 +792,7 @@ export default class RoombaAccessory implements AccessoryPlugin {
792792

793793
private startLongWatch() {
794794
const checkStatus = () => {
795-
this.log.info("Refreshing Roomba's status (repeating in %im)", LONG_WATCH_INTERVAL_MILLIS / 60_000);
795+
this.log.debug("Refreshing Roomba's status (repeating in %im)", LONG_WATCH_INTERVAL_MILLIS / 60_000);
796796

797797
this.refreshState();
798798

0 commit comments

Comments
 (0)