Skip to content

Commit

Permalink
[Improve] A user specifies the wrong service name of the value of the…
Browse files Browse the repository at this point in the history
… 'service' element.
  • Loading branch information
Patineboot committed Jun 28, 2022
1 parent 216396e commit 5db5318
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ I am tired of updating my command to only fit his CMD4 anymore.

1. Update
1. Update the value of 'version' on `package.json`.
1. Update the value of 'version' on `package-lock.json`.
1. Update the `package-lock.json`.
```bash
rm -rf node_modules
rm package-lock.json
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Homebridge RunnablePlatform",
"name": "homebridge-runnable-platform",
"version": "0.9.6",
"version": "0.9.7",
"description": "RunnablePlatform provide connections using your Custom-Command command between infrared devices and Homebridge.",
"license": "CC BY-NC-ND 4.0",
"repository": {
Expand Down
24 changes: 15 additions & 9 deletions src/RunnableAccessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ export class RunnableAccessory {
constructor(accessoryConfig) {
LOG.debug(`Enter ${this.constructor.name}: ${accessoryConfig} -> name: ${accessoryConfig.name}`);

this.#lock = new Lock();
try {
this.#lock = new Lock();

this.#accessoryConfig = accessoryConfig;
this.#accessoryConfig = accessoryConfig;

const comm = Communicator.getInstance();
comm.on('message', (message) => {
if (message.name !== this.name) {
return;
}
this.updateCharacteristic(message.characteristic, message.value);
});
const comm = Communicator.getInstance();
comm.on('message', (message) => {
if (message.name !== this.name) {
return;
}
this.updateCharacteristic(message.characteristic, message.value);
});
}
catch (error) {
LOG.info(`${this.constructor.name}: ${accessoryConfig} -> name: ${accessoryConfig.name}`);
throw error;
}
}

/**
Expand Down
68 changes: 43 additions & 25 deletions src/RunnablePlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,36 @@ export class RunnablePlatform {
* registering any new accessories.
*/
HAPI.on('didFinishLaunching', () => {
if (this.#skeletonMode) {
LOG.warn('RunnablePlatform Plugin is running on the Skelton mode.');
try {
if (this.#skeletonMode) {
LOG.warn('RunnablePlatform Plugin is running on the Skelton mode.');
return;
}
this.#didFinishLaunching();
}
catch (error) {
LOG.error('Unexpected error occurs.', error);
return;
}
this.#didFinishLaunching();
});

/**
* This event is fired when homebridge got shutdown.
*/
HAPI.on('shutdown', () => {
if (this.#skeletonMode) {
LOG.warn('RunnablePlatform Plugin is running on the Skelton mode.');
try {
if (this.#skeletonMode) {
LOG.warn('RunnablePlatform Plugin is running on the Skelton mode.');
return;
}
const comm = Communicator.getInstance();
comm.disconnect();
LOG.info('Bye.');
}
catch (error) {
LOG.error('Unexpected error occurs.', error);
return;
}
const comm = Communicator.getInstance();
comm.disconnect();
});

// verify the my 'platform' element on the config.json file.
Expand All @@ -124,24 +137,30 @@ export class RunnablePlatform {
* @param {import("homebridge").PlatformAccessory<import("homebridge").UnknownContext>} accessory
*/
configureAccessory(accessory) {
if (this.#skeletonMode) {
LOG.warn('RunnablePlatform Plugin is running on the Skelton mode.');
return;
}
try {
if (this.#skeletonMode) {
LOG.warn('RunnablePlatform Plugin is running on the Skelton mode.');
return;
}

// check the restored accessory is not described on the config file
let valid = '';
const found = this.#findConfigAccessory(accessory.UUID);
if (found) {
this.#accessories.push(accessory);
valid = 'restored';
// check the restored accessory is not described on the config file
let valid = '';
const found = this.#findConfigAccessory(accessory.UUID);
if (found) {
this.#accessories.push(accessory);
valid = 'restored';
}
else {
// remove the accessory from cache later.
this.#invalidAccessories.push(accessory);
valid = 'disposed';
}
LOG.info(`Saved accessory: ${accessory.displayName} is ${valid}`);
}
else {
// remove the accessory from cache later.
this.#invalidAccessories.push(accessory);
valid = 'VOID';
catch (error) {
LOG.error('Unexpected error occurs.', error);
return;
}
LOG.info(`Configure Accessory ${valid}: ${accessory.displayName}`);
}

/**
Expand Down Expand Up @@ -224,8 +243,6 @@ export class RunnablePlatform {
runnable.startService(accessory);
// update the new platform accessory
HAPI.updatePlatformAccessories([accessory]);

LOG.info(`Cached Accessory name:[${runnable.name}] type:[${runnable.serviceType}]`);
}
// otherwise, we create a new platform accessory
else {
Expand All @@ -236,8 +253,9 @@ export class RunnablePlatform {
// register the new platform accessory
HAPI.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);

LOG.info(`New Accessory name:[${runnable.name}] type:[${runnable.serviceType}]`);
LOG.info(`New accessory is added: name:[${runnable.name}] service:[${runnable.serviceType}]`);
}
LOG.info(`accessory started. name:[${runnable.name}] service:[${runnable.serviceType}]`);
}
}
}

0 comments on commit 5db5318

Please sign in to comment.