Skip to content

Commit

Permalink
add log success polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Apr 20, 2024
1 parent 0a739b2 commit 6b24bc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin {
) {
this.log.debug('Finished initializing platform:', this.config.name);

// Homebridge 1.8.0 introduced a `log.success` method that can be used to log success messages
// For users that are on a version prior to 1.8.0, we need a 'polyfill' for this method
if (!log.success) {
log.success = log.info;
}

// When this event is fired it means Homebridge has restored all cached accessories from disk.
// Dynamic Platform plugins should only register new accessories after this event was fired,
// in order to ensure they weren't added to homebridge already. This event can also be used
Expand All @@ -35,12 +41,12 @@ export class ExampleHomebridgePlatform 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.
* It should be used to set up event handlers for characteristics and update respective values.
*/
configureAccessory(accessory: PlatformAccessory) {
this.log.info('Loading accessory from cache:', accessory.displayName);

// add the restored accessory to the accessories cache so we can track if it has already been registered
// add the restored accessory to the accessories cache, so we can track if it has already been registered
this.accessories.push(accessory);
}

Expand Down Expand Up @@ -81,15 +87,15 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin {
// the accessory already exists
this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName);

// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. e.g.:
// existingAccessory.context.device = device;
// this.api.updatePlatformAccessories([existingAccessory]);

// create the accessory handler for the restored accessory
// this is imported from `platformAccessory.ts`
new ExamplePlatformAccessory(this, existingAccessory);

// it is possible to remove platform accessories at any time using `api.unregisterPlatformAccessories`, eg.:
// it is possible to remove platform accessories at any time using `api.unregisterPlatformAccessories`, e.g.:
// remove platform accessories when no longer present
// this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory]);
// this.log.info('Removing existing accessory from cache:', existingAccessory.displayName);
Expand Down
4 changes: 2 additions & 2 deletions src/platformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class ExamplePlatformAccessory {
* this.accessory.getService('NAME') || this.accessory.addService(this.platform.Service.Lightbulb, 'NAME', 'USER_DEFINED_SUBTYPE_ID');
*
* The USER_DEFINED_SUBTYPE must be unique to the platform accessory (if you platform exposes multiple accessories, each accessory
* can use the same sub type id.)
* can use the same subtype id.)
*/

// Example: add two "motion sensor" services to the accessory
Expand Down Expand Up @@ -106,7 +106,7 @@ export class ExamplePlatformAccessory {
* Handle the "GET" requests from HomeKit
* These are sent when HomeKit wants to know the current state of the accessory, for example, checking if a Light bulb is on.
*
* GET requests should return as fast as possbile. A long delay here will result in
* GET requests should return as fast as possible. A long delay here will result in
* HomeKit being unresponsive and a bad user experience in general.
*
* If your device takes time to respond you should update the status of your device
Expand Down

0 comments on commit 6b24bc5

Please sign in to comment.