Failures with initialization, control, feedback, and during idle: various Cannot read properties of undefined
Hello! This is a great plugin, thank you for your work, it is amazing!

# Summary

I am reporting a few issues I faced when setting up a bare new Homebridge server with this plugin, no customization, no playing around with JSONs, just following the quick start guides. I think they are interconnected, hence reporting at once. What I have is several Zigbee and Wi-Fi SONOFF devices operated previously through eWeLink: some of them work as expected, while others fail to initialize or update their state.

# Issues

Some of my devices successfully initialized and showed information in HomeKit, such as temperature and humidity sensors SNZB-02 and RGB light strip L3-5M-P (PRO version). However, others either A) cannot initialize at all, such as Wi-Fi smart plugs S40TPB, door/window sensors SNZB-04; or B) cannot properly update state which is happening to RGB light strip L3-5M (non-PRO version) which results in suboptimal experience. Light strip L3-5M also reports failed initialization but reacts to controls in HomeKit.

For A) this results in no control and feedback from Wi-Fi smart plugs S40TPB, and door/window sensors SNZB-04. Any external action such as closing the door/window does not result in any logs, which is expected since these devices were not initialized.

For B) light strip L3-5M shows "No Response" in HomeKit in some actions and the state becomes out of sync. External action such as turning the light on or off using the button on the strip does not result in logs either. My first impression this happens when the color changes or the light strip is turned off. Not when turned on or changed brightness.

C) After some random time with no particular external action system fails after another `Cannot read properties of undefined` and reboots, please see the logs below. Not clear which device update triggers this, but this happens sooner or later.

While I understand these issues are separate, given the seniority of the plugin and support of a wide range of devices I feel like these are all already troubleshooted, and what I faced should be something simple, cross-cutting that is missed.

D) The last thing I observed when clicking on SNZB-01 buttons that were previously configured to trigger certain scenes in eWeLink with the devices that were not initialized in Homebridge, all buttons become unresponsive. This must be something connected to the eWeLink cloud because no related logs/errors were reported in Homebridge.

I am using Libre Computer Sweet Potato AML-S905X-CC-V2 with Raspbian 12 Bookworm (regular, desktop version), again this is a bare new setup done specifically to use this plugin and Homebridge. No CPU or memory overload was observed through Homebridge, all were pretty stable: few % CPU load, ~1.3 GB memory available, ~41 C temperature.

# Setup

1. Libre Computer Sweet Potato AML-S905X-CC-V2 running Raspbian 12 Bookworm (regular, desktop version) with latest updates
2. Node.js v20.15.0
3. npm v10.7.0
4. Homebridge v1.8.3 (latest)
5. Homebridge UI v4.56.4 (latest)
6. Homebridge eWeLink v12.3.0 (latest) - the only plugin installed

Installation was done according to these guides:

* https://github.com/homebridge/homebridge/wiki/Install-Homebridge-on-Raspbian#installing-homebridge
* https://github.com/bwp91/homebridge-ewelink/wiki/Installation#homebridge-ui--hoobs

# Devices

* SONOFF Zigbee Bridge Pro - works as connected devices shown
* 3 x SONOFF SNZB-01 Button - works with issues most likely connected to scenarios (see D)
* 3 x SONOFF SNZB-02 Temp/Humidity Sensor - works
* 3 x SONOFF SNZB-04 Door/Window Sensor - do not work (see A)
* SONOFF L3-5M (non-PRO version) RGB strip - works with issues (see B)
* SONOFF L3-5M-P (PRO version) RGB strip - works
* 3 x SONOFF Smart Plug S40TPB - do not work (see A)

# Logs

Please click on `Details` to show the extended part of the logs.

## A) [X] could not be initialised as Cannot read properties of undefined

S40TPB:

```
[7/15/2024, 10:52:56 AM] [eWeLink] [TV] could not be initialised as Cannot read properties of undefined (reading 'UINT16') at new CurrentConsumption (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/eve-chars.js:22:29).
```

L3-5M:

```
[7/15/2024, 10:52:56 AM] [eWeLink] [Bedroom Light] could not be initialised as Cannot read properties of undefined (reading 'BOOL') at new FestiveScene (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/custom-chars.js:23:29).
```

SNZB-04:

```
[7/15/2024, 10:52:56 AM] [eWeLink] [Bedroom Window] could not be initialised as Cannot read properties of undefined (reading 'UINT32') at new ResetTotal (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/eve-chars.js:70:29).
```

<details>
  <summary>Details</summary>

```
[7/15/2024, 10:52:47 AM] Homebridge v1.8.3 (HAP v0.12.2) (Homebridge 5B07) is running on port 51009.
[7/15/2024, 10:52:47 AM] Homebridge v1.8.3 (HAP v0.12.2) (Homebridge 5B07) is running on port 51009.
[7/15/2024, 10:52:49 AM] [Homebridge UI] [HapClient] Discovery :: Found HAP device with username 0E:0D:BB:82:5B:07
[7/15/2024, 10:52:49 AM] [Homebridge UI] [HapClient] Discovery :: Testing 0E:0D:BB:82:5B:07 via http://127.0.0.1:51009/accessories
[7/15/2024, 10:52:50 AM] [Homebridge UI] [HapClient] Discovery :: Success 0E:0D:BB:82:5B:07 via http://127.0.0.1:51009/accessories
[7/15/2024, 10:52:50 AM] [Homebridge UI] [HapClient] Discovery :: [127.0.0.1:51009 (0E:0D:BB:82:5B:07)] Instance Registered
[7/15/2024, 10:52:50 AM] [eWeLink] Fetching devices from eWeLink home/id [My Home] [6376beefdeb588000867e25b].
[7/15/2024, 10:52:55 AM] [eWeLink] LAN monitoring started.
[7/15/2024, 10:52:55 AM] [eWeLink] [Livingroom Sensor] initialising with options {"humidityOffset":0,"logging":"standard","lowBattThreshold":25,"offset":0}.
[7/15/2024, 10:52:55 AM] [eWeLink] [Livingroom Sensor] initialised and LAN mode unavailable as not discovered/supported [1770:ZCL_HA_DEVICEID_TEMPERATURE_SENSOR].
[7/15/2024, 10:52:56 AM] [eWeLink] [Kitchen Sensor] initialising with options {"humidityOffset":0,"logging":"standard","lowBattThreshold":25,"offset":0}.
[7/15/2024, 10:52:56 AM] [eWeLink] [Kitchen Sensor] initialised and LAN mode unavailable as not discovered/supported [1770:ZCL_HA_DEVICEID_TEMPERATURE_SENSOR].
[7/15/2024, 10:52:56 AM] [eWeLink] [LEGO Light] initialising with options {"adaptiveLightingShift":0,"brightnessStep":1,"logging":"standard","offlineAsOff":false}.
[7/15/2024, 10:52:56 AM] [eWeLink] [LEGO Light] initialised and LAN mode unavailable as not discovered/supported [173:L3-5M-P].
[7/15/2024, 10:52:56 AM] [eWeLink] [Bedroom Switch] initialising with options {"logging":"standard","lowBattThreshold":25,"sensorTimeDifference":60}.
[7/15/2024, 10:52:56 AM] [eWeLink] [Bedroom Switch] initialised and LAN mode unavailable as not discovered/supported [1000:zigbee_ON_OFF_SWITCH_1000].
[7/15/2024, 10:52:56 AM] [eWeLink] [Kitchen Switch ] initialising with options {"logging":"standard","lowBattThreshold":25,"sensorTimeDifference":60}.
[7/15/2024, 10:52:56 AM] [eWeLink] [Kitchen Switch ] initialised and LAN mode unavailable as not discovered/supported [1000:zigbee_ON_OFF_SWITCH_1000].
[7/15/2024, 10:52:56 AM] [eWeLink] [ Livingroom Switch ] initialising with options {"logging":"standard","lowBattThreshold":25,"sensorTimeDifference":60}.
[7/15/2024, 10:52:56 AM] [eWeLink] [ Livingroom Switch ] initialised and LAN mode unavailable as not discovered/supported [1000:zigbee_ON_OFF_SWITCH_1000].
[7/15/2024, 10:52:56 AM] [eWeLink] [Bedroom Sensor] initialising with options {"humidityOffset":0,"logging":"standard","lowBattThreshold":25,"offset":0}.
[7/15/2024, 10:52:56 AM] [eWeLink] [Bedroom Sensor] initialised and LAN mode unavailable as not discovered/supported [1770:ZCL_HA_DEVICEID_TEMPERATURE_SENSOR].
[7/15/2024, 10:52:56 AM] [eWeLink] [TV] could not be initialised as Cannot read properties of undefined (reading 'UINT16') at new CurrentConsumption (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/eve-chars.js:22:29).
[7/15/2024, 10:52:56 AM] [eWeLink] [Fridge] could not be initialised as Cannot read properties of undefined (reading 'UINT16') at new CurrentConsumption (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/eve-chars.js:22:29).
[7/15/2024, 10:52:56 AM] [eWeLink] [A/C] could not be initialised as Cannot read properties of undefined (reading 'UINT16') at new CurrentConsumption (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/eve-chars.js:22:29).
[7/15/2024, 10:52:56 AM] [eWeLink] [Bedroom Light] could not be initialised as Cannot read properties of undefined (reading 'BOOL') at new FestiveScene (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/custom-chars.js:23:29).
[7/15/2024, 10:52:56 AM] [eWeLink] [Bedroom Window] could not be initialised as Cannot read properties of undefined (reading 'UINT32') at new ResetTotal (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/eve-chars.js:70:29).
[7/15/2024, 10:52:56 AM] [eWeLink] [Livingroom Window] could not be initialised as Cannot read properties of undefined (reading 'UINT32') at new ResetTotal (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/eve-chars.js:70:29).
[7/15/2024, 10:52:56 AM] [eWeLink] [Door] could not be initialised as Cannot read properties of undefined (reading 'UINT32') at new ResetTotal (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/eve-chars.js:70:29).
[7/15/2024, 10:52:56 AM] [eWeLink] ✓ Setup complete. This plugin has been made with ♥ by bwp91, please consider a ☆ on GitHub if you are finding it useful!
```
</details>

## B) [X] device update failed as Cannot read properties of undefined

L3-5M:

```
[7/15/2024, 11:24:54 AM] [eWeLink] [Bedroom Light] device update failed as Cannot read properties of undefined (reading 'BOOL') at new FestiveScene (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/custom-chars.js:23:29).
```

<details>
  <summary>Details</summary>

  ```
  [7/15/2024, 11:24:28 AM] [eWeLink] [Bedroom Light] current state [on].
  [7/15/2024, 11:24:38 AM] [eWeLink] [Bedroom Light] current colour [rgb 245 242 255].
  [7/15/2024, 11:24:38 AM] [eWeLink] [Bedroom Light] device update failed as Cannot read properties of undefined (reading 'BOOL') at new FestiveScene (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/custom-chars.js:23:29).
  [7/15/2024, 11:24:42 AM] [eWeLink] [Bedroom Light] current brightness [11%].
  [7/15/2024, 11:24:42 AM] [eWeLink] [Bedroom Light] current brightness [100%].
  [7/15/2024, 11:24:54 AM] [eWeLink] [Bedroom Light] current state [off].
  [7/15/2024, 11:24:54 AM] [eWeLink] [Bedroom Light] device update failed as Cannot read properties of undefined (reading 'BOOL') at new FestiveScene (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/utils/custom-chars.js:23:29).
  ```
</details>

## C) TypeError: Cannot read properties of undefined (reading 'markStatus')

```
[7/15/2024, 11:02:34 AM] TypeError: Cannot read properties of undefined (reading 'markStatus')
    at default.receiveDeviceUpdate (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/platform.js:1911:31)
    at EventEmitter.<anonymous> (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/platform.js:594:54)
    at EventEmitter.emit (node:events:519:28)
    at file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/connection/ws.js:230:25
    at Timeout._onTimeout (/var/lib/homebridge/node_modules/homebridge-ewelink/node_modules/chnl/dist/channel.cjs.js:2:4848)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7)
```

<details>
  <summary>Details</summary>

```
[7/15/2024, 10:52:56 AM] [eWeLink] ✓ Setup complete. This plugin has been made with ♥ by bwp91, please consider a ☆ on GitHub if you are finding it useful!
[7/15/2024, 10:53:41 AM] [Homebridge UI] [HapClient] Discovery :: Ended
[7/15/2024, 11:02:34 AM] TypeError: Cannot read properties of undefined (reading 'markStatus')
    at default.receiveDeviceUpdate (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/platform.js:1911:31)
    at EventEmitter.<anonymous> (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/platform.js:594:54)
    at EventEmitter.emit (node:events:519:28)
    at file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/connection/ws.js:230:25
    at Timeout._onTimeout (/var/lib/homebridge/node_modules/homebridge-ewelink/node_modules/chnl/dist/channel.cjs.js:2:4848)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7)
[7/15/2024, 11:02:34 AM] TypeError: Cannot read properties of undefined (reading 'markStatus')
    at default.receiveDeviceUpdate (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/platform.js:1911:31)
    at EventEmitter.<anonymous> (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/platform.js:594:54)
    at EventEmitter.emit (node:events:519:28)
    at file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/connection/ws.js:230:25
    at Timeout._onTimeout (/var/lib/homebridge/node_modules/homebridge-ewelink/node_modules/chnl/dist/channel.cjs.js:2:4848)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7)
[7/15/2024, 11:02:34 AM] TypeError: Cannot read properties of undefined (reading 'markStatus')
    at default.receiveDeviceUpdate (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/platform.js:1911:31)
    at EventEmitter.<anonymous> (file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/platform.js:594:54)
    at EventEmitter.emit (node:events:519:28)
    at file:///var/lib/homebridge/node_modules/homebridge-ewelink/lib/connection/ws.js:230:25
    at Timeout._onTimeout (/var/lib/homebridge/node_modules/homebridge-ewelink/node_modules/chnl/dist/channel.cjs.js:2:4848)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7)
[7/15/2024, 11:02:34 AM] Got SIGTERM, shutting down Homebridge...
[7/15/2024, 11:02:39 AM] [HB Supervisor] Homebridge Process Ended. Code: 143, Signal: null
[7/15/2024, 11:02:44 AM] [HB Supervisor] Restarting Homebridge...
```
</details>