icanos / hassio-plejd

Hass.io add-on for Plejd home automation devices
Apache License 2.0
126 stars 36 forks source link

Non-existing fields of connectedDevice are accessed in PlejdBLEHandler.js breaking time sync #265

Closed Flole998 closed 1 year ago

Flole998 commented 1 year ago

In PlejdBLEHandler.js there are cases where fields of the variable this.connectedDevice are accessed. For example logger.info(`BLE Connected to ${this.connectedDevice.name}`); which will always return "undefined" as the type is a Device (from types/ApiSite.d.ts) and not an InputDevice or OutputDevice.

Also syncing the time is broken due to this, this.connectedDevice.id is needed there but that doesn't exist, so 0 is assumed there which doesn't work if there is no device with mesh index 0.

SweVictor commented 1 year ago

Hmm, alright. Could you post some more logs on what happens? What's the device in question? Why does it not have a name? How does the Plejd app look?

SweVictor commented 1 year ago

@Flole998: After an in-depth code review I get the issue you're talking about. You're indeed right that the specific part of the code lacks typing and (incorrectly) assumes that id and name exists.

I've clarified the typing, changed name to title and created a lookup to go from device id (which we have) to BLE id (which we don't have).

This is part of the latest commit in the https://github.com/icanos/hassio-plejd/tree/develop branch and planned for 0.11