bwp91 / homebridge-meross

Homebridge plugin to integrate Meross devices into HomeKit.
MIT License
197 stars 32 forks source link

Crash (Cannot read property of undefined on device.deviceType) with manually configured lights #515

Closed grrowl closed 1 year ago

grrowl commented 1 year ago

What issue do you have? Please be as thorough and explicit as possible.

Manually configured two devices through the plugin UI

[Meross] [undefined] could not be initialised as Cannot read properties of undefined (reading 'toUpperCase') at default.initialiseDevice (file:///homebridge/node_modules/homebridge-meross/lib/platform.js:434:42).

here's that line in the code

      // Generate a unique id for the accessory
      const hbUUID = this.api.hap.uuid.generate(device.uuid);
      device.firmware = deviceConf.firmwareRevision || device.fmwareVersion;
      device.hbDeviceId = device.uuid;
      device.model = device.deviceType.toUpperCase().replace(/-+/g, '');

Details of your setup.

Homebridge v.1.6.0 homebridge-config-ui-x v4.50.2 Nodejs v18.13.0 Docker homebridge-meross v9.0.2 (also happens in v9.0.1)

Two Meross Light Bulbs configured, both MSL120DR

Config

with the attempted workaround (below) included

        {
            "name": "Meross",
            "username": "xxx",
            "password": "xxx",
            "lightDevices": [
                {
                    "name": "Splash Lamp",
                    "serialNumber": "2103259766383090847348e1e967557e",
                    "connection": "local",
                    "deviceUrl": "192.168.2.113",
                    "deviceType": "msl120dr"
                },
                {
                    "name": "Desk Lamp",
                    "serialNumber": "2103259309682490847348e1e96757c9",
                    "connection": "local",
                    "deviceUrl": "192.168.2.11",
                    "deviceType": "msl120dr"
                }
            ],
            "_bridge": {
                "username": "xxx",
                "port": 0000
            },
            "platform": "Meross"
        }

Logs

[4/6/2023, 11:32:52 AM] [Meross] [Splash Lamp] not initialising cloud device as ignored or configured locally.
[4/6/2023, 11:32:52 AM] [Meross] [Desk Lamp] not initialising cloud device as ignored or configured locally.
[4/6/2023, 11:32:52 AM] [Meross] [undefined] could not be initialised as Cannot read properties of undefined (reading 'toUpperCase') at default.initialiseDevice (file:///homebridge/node_modules/homebridge-meross/lib/platform.js:433:42).
[4/6/2023, 11:32:52 AM] [Meross] [undefined] could not be initialised as Cannot read properties of undefined (reading 'toUpperCase') at default.initialiseDevice (file:///homebridge/node_modules/homebridge-meross/lib/platform.js:433:42).
[4/6/2023, 11:32:52 AM] [Meross] ✓ Setup complete. This plugin has been made with ♥ by bwp91, please consider a ☆ on GitHub if you are finding it useful!

attempted workaround

manually adding deviceType: "msl120dr" to each light's config doesnt work:

[4/6/2023, 11:34:16 AM] [Meross] Initialising plugin v9.0.2 | System linux | Node v18.13.0 | HB v1.6.0 | HAPNodeJS v0.11.0...
[4/6/2023, 11:34:16 AM] [Meross] Config entry [lightDevices.2103259766383090847348e1e967557e.deviceType] is unused and can be removed.
[4/6/2023, 11:34:16 AM] [Meross] Config entry [lightDevices.2103259309682490847348e1e96757c9.deviceType] is unused and can be removed.
[4/6/2023, 11:34:16 AM] [Meross] Plugin initialised. Setting up accessories....
[4/6/2023, 11:34:16 AM] Homebridge v1.6.0 (HAP v0.11.0) (Meross) is running on port 41911.
[4/6/2023, 11:34:18 AM] [Meross] [Splash Lamp] not initialising cloud device as ignored or configured locally.
[4/6/2023, 11:34:18 AM] [Meross] [Desk Lamp] not initialising cloud device as ignored or configured locally.
[4/6/2023, 11:34:18 AM] [Meross] [undefined] could not be initialised as Cannot read properties of undefined (reading 'toUpperCase') at default.initialiseDevice (file:///homebridge/node_modules/homebridge-meross/lib/platform.js:433:42).
[4/6/2023, 11:34:18 AM] [Meross] [undefined] could not be initialised as Cannot read properties of undefined (reading 'toUpperCase') at default.initialiseDevice (file:///homebridge/node_modules/homebridge-meross/lib/platform.js:433:42).
[4/6/2023, 11:34:18 AM] [Meross] ✓ Setup complete. This plugin has been made with ♥ by bwp91, please consider a ☆ on GitHub if you are finding it useful!
grrowl commented 1 year ago

misread the code, the config actually needs to specify model, not deviceType. manually specifying this in the config does work, not sure why the field isn't in the plugin config UI or being set internally.

[4/6/2023, 11:43:23 AM] [Meross] [Desk Lamp] not initialising cloud device as ignored or configured locally.
[4/6/2023, 11:43:23 AM] [Meross] [Splash Lamp] has been added to Homebridge.
[4/6/2023, 11:43:23 AM] [Meross] [Splash Lamp] initialising with options {"adaptiveLightingShift":0,"brightnessStep":1,"connection":"local"}.
[4/6/2023, 11:43:23 AM] [Meross] [Splash Lamp] initialised with id [2103259766383090847348e1e967557e}].
[4/6/2023, 11:43:23 AM] [Meross] [Desk Lamp] has been added to Homebridge.
[4/6/2023, 11:43:23 AM] [Meross] [Desk Lamp] initialising with options {"adaptiveLightingShift":0,"brightnessStep":1,"connection":"local"}.
[4/6/2023, 11:43:23 AM] [Meross] [Desk Lamp] initialised with id [2103259309682490847348e1e96757c9}].
bwp91 commented 1 year ago

If you have your Meross username and password configured, the plugin will take the model from the cloud information, therefore not needed to be configured (and does not appear in the settings UI).

The option will appear in the settings UI when you specify a user key instead of user+pass.

I believe I have fixed the error you produced in a new beta version of the plugin. It was a particular mix of config entries that was a case I had not thought about! I know you have got this working yourself, I mean if you were to how you had your config when the error was appearing, with the beta it should no longer show this error.

Thanks for finding this!