Skip to content

Commit

Permalink
Check for "undefi" property values on update
Browse files Browse the repository at this point in the history
There was a bug where we try to pass the string "undefi" into the colorsys hex2Hsv method. The library does not handle this gracefully and it results in the error

```
TypeError: Cannot read properties of null (reading 'r')
    at Object.colorsys.hex2Hsv (/var/lib/homebridge/node_modules/homebridge-wyze-smart-home/node_modules/colorsys/colorsys.js:197:31)
    at WyzeMeshLight.updateColor (/var/lib/homebridge/node_modules/homebridge-wyze-smart-home/src/accessories/WyzeMeshLight.js:104:31)
    at WyzeMeshLight.updateCharacteristics (/var/lib/homebridge/node_modules/homebridge-wyze-smart-home/src/accessories/WyzeMeshLight.js:69:46)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
```

Here we add a check to the updateCharacteristics method (alongside two others that already existed) to ignore this invalid value rather than trying to act on it.

In my local testing the ability to set colors was not impacted as logging seems to indicate a valid color is later provided for the same device.

See: jfarmer08#251
  • Loading branch information
jakespracher committed Aug 14, 2024
1 parent ca12938 commit a5e5efd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/accessories/WyzeMeshLight.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,32 @@ module.exports = class WyzeMeshLight extends WyzeAccessory {
for (const property of propertyList.data.property_list) {
switch (property.pid) {
case WYZE_API_BRIGHTNESS_PROPERTY:
if (property.value != null) this.updateBrightness(property.value);
if (this.isValidProperty(property)) this.updateBrightness(property.value);
break;
case WYZE_API_COLOR_TEMP_PROPERTY:
if (property.value != null && property.value !== "0") this.updateColorTemp(property.value);
if (this.isValidProperty(property)) this.updateColorTemp(property.value);
break;
case WYZE_API_COLOR_PROPERTY:
if (property.value != null && property.value !== "0") this.updateColor(property.value);
if (this.isValidProperty(property)) this.updateColor(property.value);
break;
}
}
}
}

isValidProperty(property) {
if (
property.value != null &&
property.value !== "0" &&
property.value != "undefi"
) {
return true;
} else {
this.plugin.log(`Encountered invalid property value: ${JSON.stringify(property, null, 2)}`);
return false;
}
}

updateBrightness(value) {
if (this.plugin.config.pluginLoggingEnabled)
this.plugin.log(
Expand Down

0 comments on commit a5e5efd

Please sign in to comment.