Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shelly] Script oh-blu-scanner.js crashes in Shelly Plus when receiving buffer contains data of "undefined" type #16344

Closed
JochemLindemannSchunk opened this issue Jan 30, 2024 · 2 comments · Fixed by #16371
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@JochemLindemannSchunk
Copy link

JochemLindemannSchunk commented Jan 30, 2024

Expected Behavior

Script should handle "undefined" type in receiving buffer without crashing.

Current Behavior

let _bth;
let _value;
while (buffer.length > 0) {
_bth = BTH[buffer.at(0)];
if (_bth === "undefined") {
console.log("BTH: unknown type");
break;
}
buffer = buffer.slice(1);
_value = this.getBufValue(_bth.t, buffer);
if (_value === null) break;
if (typeof _bth.f !== "undefined") _value = _value * _bth.f;
result[_bth.n] = _value;
buffer = buffer.slice(getByteSize(_bth.t));
}

Accessing _bth.t in line 102 causes an exception when _bth is undefined.

Error: Error: Cannot read property 't' of undefined

Jan 28 15:29:36 shellyplusi4-xxxxxxxxxxx 908 386984.546 1 0|in function "unpack" called from ...ice_data[BTHOME_SVC_ID_STR]);
Jan 28 15:29:36 shellyplusi4-xxxxxxxxxxx 909 386984.550 1 0| ^
Jan 28 15:29:36 shellyplusi4-xxxxxxxxxxx 910 386984.560 1 0|in function "getData" called from ...ShellyBLUParser.getData(res); // skip if parsing failed
Jan 28 15:29:36 shellyplusi4-xxxxxxxxxxx 911 386984.563 1 0| ^
Jan 28 15:29:36 shellyplusi4-xxxxxxxxxxx 912 386984.566 1 0|in function called from system
Jan 28 15:29:36 shellyplusi4-xxxxxxxxxxx 913 386984.567 1 0|
Jan 28 15:29:36 shellyplusi4-xxxxxxxxxxx 914 386984.572 1 1|shelly_user_script.:397 error: Error in EjsCall

Reason is that line 97 does not handle check for "undefined" properly.

Possible Solution

Use if (typeof _bth === "undefined") { instead of if (_bth === "undefined") { in line 97.
Without "typeof" this check does not work properly.

Steps to Reproduce (for Bugs)

  1. Use Shelly device with "BLU Gateway Support" activated in thing configuration e.g. Shelly PlusI4.
  2. Wait until periodical bluetooth data is received from Shelly BLU device e.g. Shelly BLU Door/Window (May take some hours).
  3. Script stops working automatically in Shelly due to occuring exception.

Context

Your Environment

  • Version used: openHAB 4.1.1 with Shelly Binding 4.1.1
  • Shelly PlusI4 (SNSN-0024X) with FW 1.1.0
  • Shelly BLU Door/Window (SBDW-002C) with FW 20240115-142209/v1.0.9
@JochemLindemannSchunk JochemLindemannSchunk added the bug An unexpected problem or unintended behavior of an add-on label Jan 30, 2024
@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/shelly-binding/56862/3685

@JochemLindemannSchunk
Copy link
Author

Fixed with #16371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants