homebridge-switchbot: Bug: Failed to Discover Devices after adding/updating the devices

Describe the Bug

The devices are not able to be found after adding/updating the children’s devices.

I updated the existing device “switchbot bot” with different “device refresh rate”.

I added a new device “switchbot bot” for the another new-buy bot.

After restarting the hb, the hb cannot find any devices nor hk showing any switchbot devices.

I have check the issue list, it seems that the below issue are similar

Please help solve the bug, thank you =)

To Reproduce

Not sure

Expected Behavior

The homebridge-switchbot plugin should be able to get all the devices.

Relevant Log Output

[02/08/2023, 12:17:11] [SwitchBot] Bot: Bot Light Unknown statusCode: 500, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug

[02/08/2023, 12:17:11] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "Cannot read properties of undefined (reading 'power')"

[03/08/2023, 03:19:53] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "Connect Timeout Error"

[03/08/2023, 03:20:03] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "Connect Timeout Error"

[03/08/2023, 03:20:13] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "Connect Timeout Error"

[03/08/2023, 03:20:23] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "Connect Timeout Error"

[03/08/2023, 03:20:26] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:20:33] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:20:43] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:20:53] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:21:03] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:21:13] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:21:23] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:21:33] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:21:43] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:21:53] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:22:03] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "getaddrinfo ENOTFOUND api.switch-bot.com"

[03/08/2023, 03:22:13] [SwitchBot] Child bridge process ended

[03/08/2023, 03:22:13] [SwitchBot] Process Ended. Code: 1, Signal: null

[03/08/2023, 03:22:30] [SwitchBot] Initializing SwitchBot platform...

[03/08/2023, 03:22:30] [SwitchBot] Initializing child bridge 0E:84:DC:C8:E2:AF

[03/08/2023, 03:22:31] [SwitchBot] Launched child bridge with PID 4131

[03/08/2023, 03:22:35] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.6.2 child bridge successfully

[03/08/2023, 03:22:35] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[04/08/2023, 01:15:57] [SwitchBot] Initializing SwitchBot platform...

[04/08/2023, 01:15:57] [SwitchBot] Initializing child bridge 0E:84:DC:C8:E2:AF

[04/08/2023, 01:15:59] [SwitchBot] Launched child bridge with PID 6361

[04/08/2023, 01:16:02] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[04/08/2023, 01:16:02] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[04/08/2023, 01:16:07] [SwitchBot] Total SwitchBot Devices Found: 2

[04/08/2023, 01:16:07] [SwitchBot] Restoring existing accessory from cache: Air Conditioner DeviceID: 02-202307122218-42893239

[04/08/2023, 01:16:07] [SwitchBot] Air Conditioner: Air Conditioner Config: {"connectionType":"OpenAPI"}

[04/08/2023, 01:16:07] [SwitchBot] Total IR Devices Found: 1

[04/08/2023, 01:16:07] [SwitchBot] Restoring existing accessory from cache: Bot Light DeviceID: C13832304461

[04/08/2023, 01:16:07] [SwitchBot] Bot: Bot Light Config: {"mode":"press","deviceType":"switch","connectionType":"OpenAPI","logging":"standard","refreshRate":10,"offline":false}

[04/08/2023, 01:16:07] [SwitchBot] Bot: Bot Light Displaying as Switch

[04/08/2023, 01:16:14] [SwitchBot] Bot: Bot Light Set On: true

[04/08/2023, 01:16:29] [SwitchBot] Bot: Bot Light Set On: true

[04/08/2023, 01:29:04] [SwitchBot] Bot: Bot Light Set On: true

[04/08/2023, 10:41:50] [SwitchBot] Bot: Bot Light Set On: true

[04/08/2023, 22:18:28] [SwitchBot] Bot: Bot Light Set On: true

[04/08/2023, 22:50:57] [SwitchBot] Bot: Bot Light Set On: true

[06/08/2023, 00:07:39] [SwitchBot] Bot: Bot Light Set On: true

[06/08/2023, 00:17:50] [SwitchBot] Bot: Bot Light Set On: true

[06/08/2023, 10:42:14] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "Cannot read properties of undefined (reading 'power')"

[06/08/2023, 19:25:51] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "Cannot read properties of undefined (reading 'power')"

[07/08/2023, 01:29:29] [SwitchBot] Bot: Bot Light Set On: true

[08/08/2023, 22:25:06] [SwitchBot] Bot: Bot Light Set On: true

[09/08/2023, 21:00:04] [SwitchBot] Bot: Bot Light Unknown statusCode: 500, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug

[09/08/2023, 21:00:04] [SwitchBot] Bot: Bot Light failed openAPIRefreshStatus with OpenAPI Connection, Error Message: "Cannot read properties of undefined (reading 'power')"

[11/08/2023, 01:32:33] [SwitchBot] Bot: Bot Light Set On: true

[11/08/2023, 09:55:28] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 09:55:28] [SwitchBot] Initializing child bridge 0E:84:DC:C8:E2:AF

[11/08/2023, 09:55:30] [SwitchBot] Launched child bridge with PID 19374

[11/08/2023, 09:55:33] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 09:55:33] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[11/08/2023, 09:55:35] [SwitchBot] Total SwitchBot Devices Found: 3

[11/08/2023, 09:55:35] [SwitchBot] Restoring existing accessory from cache: Air Conditioner DeviceID: 02-202307122218-42893239

[11/08/2023, 09:55:35] [SwitchBot] Air Conditioner: Air Conditioner Config: {"connectionType":"OpenAPI"}

[11/08/2023, 09:55:35] [SwitchBot] Total IR Devices Found: 1

[11/08/2023, 09:55:35] [SwitchBot] Restoring existing accessory from cache: Bot Light DeviceID: C13832304461

[11/08/2023, 09:55:35] [SwitchBot] Adding new accessory: Bot Door Bot DeviceID: CFF4619C509D

[11/08/2023, 09:55:35] [SwitchBot] Bot: Bot Light Config: {"mode":"press","deviceType":"switch","connectionType":"OpenAPI","logging":"standard","refreshRate":10,"offline":false}

[11/08/2023, 09:55:35] [SwitchBot] Bot: Bot Light Displaying as Switch

[11/08/2023, 09:55:35] [SwitchBot] Bot: Bot Door Config: {"mode":"switch","deviceType":"switch","connectionType":"OpenAPI","refreshRate":10}

[11/08/2023, 09:55:35] [SwitchBot] Bot: Bot Door Displaying as Switch

[11/08/2023, 09:56:38] [SwitchBot] Bot: Bot Door Set On: true

[11/08/2023, 09:56:54] [SwitchBot] Bot: Bot Door Set On: false

[11/08/2023, 09:56:58] [SwitchBot] Bot: Bot Door Set On: true

[11/08/2023, 09:57:09] [SwitchBot] Bot: Bot Door Set On: false

[11/08/2023, 09:57:22] [SwitchBot] Bot: Bot Door Set On: true

[11/08/2023, 09:57:38] [SwitchBot] Bot: Bot Door Set On: false

[11/08/2023, 09:59:18] [SwitchBot] Bot: Bot Door Set On: true

[11/08/2023, 09:59:24] [SwitchBot] Bot: Bot Door Set On: false

[11/08/2023, 10:02:06] [SwitchBot] Bot: Bot Door Set On: true

[11/08/2023, 10:02:22] [SwitchBot] Bot: Bot Door Set On: false

[11/08/2023, 14:57:50] [SwitchBot] Bot: Bot Door Set On: true

[11/08/2023, 14:59:55] [SwitchBot] Bot: Bot Door Set On: false

[11/08/2023, 23:03:34] [SwitchBot] Bot: Bot Door Set On: true

[11/08/2023, 23:03:47] [SwitchBot] Bot: Bot Door Set On: false

[11/08/2023, 23:05:09] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:05:09] [SwitchBot] Initializing child bridge 0E:84:DC:C8:E2:AF

[11/08/2023, 23:05:11] [SwitchBot] Launched child bridge with PID 20503

[11/08/2023, 23:05:14] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:05:15] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[11/08/2023, 23:10:29] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:10:29] [SwitchBot] Initializing child bridge 0E:84:DC:C8:E2:AF

[11/08/2023, 23:10:31] [SwitchBot] Launched child bridge with PID 20599

[11/08/2023, 23:10:35] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:10:35] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[11/08/2023, 23:13:53] [SwitchBot] Restarting child bridge...

[11/08/2023, 23:13:58] [SwitchBot] Child bridge process ended

[11/08/2023, 23:13:58] [SwitchBot] Process Ended. Code: 143, Signal: null

[11/08/2023, 23:14:05] [SwitchBot] Restarting Process...

[11/08/2023, 23:14:06] [SwitchBot] Launched child bridge with PID 20667

[11/08/2023, 23:14:09] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:14:09] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[11/08/2023, 23:15:53] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:15:53] [SwitchBot] Initializing child bridge 0E:84:DC:C8:E2:AF

[11/08/2023, 23:15:54] [SwitchBot] Launched child bridge with PID 20841

[11/08/2023, 23:15:58] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:15:58] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[11/08/2023, 23:16:18] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:16:18] [SwitchBot] Initializing child bridge 0E:84:DC:C8:E2:AF

[11/08/2023, 23:16:19] [SwitchBot] Launched child bridge with PID 20908

[11/08/2023, 23:16:23] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:16:23] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[11/08/2023, 23:17:30] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:17:30] [SwitchBot] Initializing child bridge 0E:84:DC:C8:E2:AF

[11/08/2023, 23:17:31] [SwitchBot] Launched child bridge with PID 21004

[11/08/2023, 23:17:35] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:17:35] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[11/08/2023, 23:19:34] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:19:34] [SwitchBot] Initializing child bridge 0E:84:DC:C8:E2:AF

[11/08/2023, 23:19:35] [SwitchBot] Launched child bridge with PID 21477

[11/08/2023, 23:19:39] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:19:39] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":30}

[11/08/2023, 23:27:21] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:28:50] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:28:50] [SwitchBot] Initializing child bridge 0E:D2:C4:22:57:08

[11/08/2023, 23:28:52] [SwitchBot] Launched child bridge with PID 21790

[11/08/2023, 23:28:55] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:31:56] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:31:56] [SwitchBot] Initializing child bridge 0E:D2:C4:22:57:08

[11/08/2023, 23:31:58] [SwitchBot] Launched child bridge with PID 21871

[11/08/2023, 23:32:01] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:39:55] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:39:55] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[11/08/2023, 23:39:57] [SwitchBot] Launched child bridge with PID 22534

[11/08/2023, 23:40:00] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:41:50] [SwitchBot] Restarting child bridge...

[11/08/2023, 23:41:55] [SwitchBot] Child bridge process ended

[11/08/2023, 23:41:55] [SwitchBot] Process Ended. Code: 143, Signal: null

[11/08/2023, 23:42:02] [SwitchBot] Restarting Process...

[11/08/2023, 23:42:03] [SwitchBot] Launched child bridge with PID 22585

[11/08/2023, 23:42:06] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[11/08/2023, 23:44:11] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:44:11] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[11/08/2023, 23:44:13] [SwitchBot] Launched child bridge with PID 23104

[11/08/2023, 23:44:16] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[11/08/2023, 23:28:17] [SwitchBot] Initializing SwitchBot platform...

[11/08/2023, 23:28:17] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[11/08/2023, 23:28:18] [SwitchBot] Launched child bridge with PID 818

[11/08/2023, 23:47:10] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 00:06:47] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:06:47] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[12/08/2023, 00:06:49] [SwitchBot] Launched child bridge with PID 918

[12/08/2023, 00:06:53] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 00:18:03] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:18:03] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[12/08/2023, 00:18:05] [SwitchBot] Launched child bridge with PID 1147

[12/08/2023, 00:18:08] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 00:20:49] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:20:49] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[12/08/2023, 00:20:51] [SwitchBot] Launched child bridge with PID 1295

[12/08/2023, 00:20:54] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 00:23:28] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:23:28] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[12/08/2023, 00:23:30] [SwitchBot] Launched child bridge with PID 1470

[12/08/2023, 00:23:33] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 00:24:23] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:24:23] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[12/08/2023, 00:24:25] [SwitchBot] Launched child bridge with PID 1564

[12/08/2023, 00:24:28] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 00:25:55] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:25:55] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[12/08/2023, 00:25:57] [SwitchBot] Launched child bridge with PID 1702

[12/08/2023, 00:26:00] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 00:32:09] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:32:09] [SwitchBot] Initializing child bridge 0E:71:DC:1D:3A:41

[12/08/2023, 00:32:12] [SwitchBot] Launched child bridge with PID 1817

[12/08/2023, 00:32:15] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 00:50:22] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:50:22] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":15}

[12/08/2023, 00:53:37] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:53:37] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":15}

[12/08/2023, 00:55:25] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 00:55:25] [SwitchBot] Initializing child bridge 0E:55:D6:94:91:A4

[12/08/2023, 00:55:27] [SwitchBot] Launched child bridge with PID 3691

[12/08/2023, 00:55:30] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[12/08/2023, 00:55:30] [SwitchBot] Platform Config: {"logging":"standard","refreshRate":15}

[12/08/2023, 01:00:21] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 01:00:21] [SwitchBot] Initializing child bridge 0E:55:D6:94:91:A4

[12/08/2023, 01:00:23] [SwitchBot] Launched child bridge with PID 3825

[12/08/2023, 01:00:27] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[12/08/2023, 01:00:27] [SwitchBot] [DEBUG] Using Config Logging: debug

[12/08/2023, 01:00:27] [SwitchBot] [DEBUG] Finished initializing platform:

[12/08/2023, 01:00:27] [SwitchBot] Platform Config: {"logging":"debug","refreshRate":15}

[12/08/2023, 01:00:27] [SwitchBot] [DEBUG] Config OK

[12/08/2023, 01:00:27] [SwitchBot] [DEBUG] Using Default Push Rate.

[12/08/2023, 01:00:28] [SwitchBot] [DEBUG] Executed didFinishLaunching callback

[12/08/2023, 01:00:31] [SwitchBot] [DEBUG] Devices: {}

[12/08/2023, 01:00:31] [SwitchBot] [DEBUG] Request successful, statusCode: 200

[12/08/2023, 01:00:31] [SwitchBot] [DEBUG] Headers: {"date":"Fri, 11 Aug 2023 17:00:31 GMT","content-type":"application/json","content-length":"73","connection":"keep-alive","x-amzn-requestid":"f8c76a1c-190e-48cb-8bf7-d31a6fa2c66a","x-amz-apigw-id":"JgVfbHvMIAMEJBQ=","x-amzn-trace-id":"Root=1-64d6692f-61b99ffe79141ea3564ae157;Sampled=0;lineage=c8c2b0f2:0|bf95bacf:0"}

[12/08/2023, 01:00:31] [SwitchBot] [DEBUG] SwitchBot Device Config Set: [{"deviceId":"CF:F4:61:9C:50:9D","configDeviceName":"Bot Door","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"switch","deviceType":"switch"},"firmware":"V6.3","refreshRate":15,"logging":"debug"},{"deviceId":"C1:38:32:30:44:61","configDeviceName":"Bot Light","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"press","deviceType":"switch"},"firmware":"V6.5","refreshRate":15,"external":false,"logging":"debug"}]

[12/08/2023, 01:00:31] [SwitchBot] [DEBUG] Failed to Discover Devices, Error Message: "Cannot read property 'map' of undefined", Submit Bugs Here: https://tinyurl.com/SwitchBotBug

[12/08/2023, 01:00:31] [SwitchBot] [DEBUG] Failed to Discover Devices, Error: TypeError: Cannot read property 'map' of undefined

[12/08/2023, 01:05:43] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 01:05:43] [SwitchBot] Initializing child bridge 0E:55:D6:94:91:A4

[12/08/2023, 01:05:44] [SwitchBot] Launched child bridge with PID 4018

[12/08/2023, 01:05:48] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[12/08/2023, 01:05:48] [SwitchBot] [DEBUG] Finished initializing platform:

[12/08/2023, 01:05:48] [SwitchBot] [DEBUG] Using Config Logging: debug

[12/08/2023, 01:05:48] [SwitchBot] Platform Config: {"logging":"debug","refreshRate":6}

[12/08/2023, 01:05:48] [SwitchBot] [DEBUG] Using Default Push Rate.

[12/08/2023, 01:05:48] [SwitchBot] [DEBUG] Config OK

[12/08/2023, 01:05:49] [SwitchBot] [DEBUG] Executed didFinishLaunching callback

[12/08/2023, 01:05:50] [SwitchBot] [DEBUG] Devices: {}

[12/08/2023, 01:05:50] [SwitchBot] [DEBUG] Request successful, statusCode: 200

[12/08/2023, 01:05:50] [SwitchBot] [DEBUG] Headers: {"date":"Fri, 11 Aug 2023 17:05:50 GMT","content-type":"application/json","content-length":"73","connection":"keep-alive","x-amzn-requestid":"56d969ef-a617-455a-bfc2-af2d4628a82c","x-amz-apigw-id":"JgWRSG56IAMEB7A=","x-amzn-trace-id":"Root=1-64d66a6e-28d5985205ff8f7b0b948d3a;Sampled=0;lineage=c8c2b0f2:0|bf95bacf:0"}

[12/08/2023, 01:05:50] [SwitchBot] [DEBUG] SwitchBot Device Config Set: [{"deviceId":"CF:F4:61:9C:50:9D","configDeviceName":"Bot Door","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"switch","deviceType":"switch"},"firmware":"V6.3","refreshRate":6,"logging":"debug"},{"deviceId":"C1:38:32:30:44:61","configDeviceName":"Bot Light","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"press","deviceType":"switch"},"firmware":"V6.5","refreshRate":15,"external":false,"logging":"debug"}]

[12/08/2023, 01:05:50] [SwitchBot] [DEBUG] Failed to Discover Devices, Error Message: "Cannot read property 'map' of undefined", Submit Bugs Here: https://tinyurl.com/SwitchBotBug

[12/08/2023, 01:05:50] [SwitchBot] [DEBUG] Failed to Discover Devices, Error: TypeError: Cannot read property 'map' of undefined

[12/08/2023, 01:07:30] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 01:07:30] [SwitchBot] Initializing child bridge 0E:55:D6:94:91:A4

[12/08/2023, 01:07:32] [SwitchBot] Launched child bridge with PID 4153

[12/08/2023, 01:07:35] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[12/08/2023, 01:07:35] [SwitchBot] [DEBUG] Using Config Logging: debug

[12/08/2023, 01:07:35] [SwitchBot] [DEBUG] Finished initializing platform:

[12/08/2023, 01:07:35] [SwitchBot] Platform Config: {"logging":"debug","refreshRate":6}

[12/08/2023, 01:07:35] [SwitchBot] [DEBUG] Using Default Push Rate.

[12/08/2023, 01:07:35] [SwitchBot] [DEBUG] Config OK

[12/08/2023, 01:07:36] [SwitchBot] [DEBUG] Executed didFinishLaunching callback

[12/08/2023, 01:07:39] [SwitchBot] [DEBUG] Devices: {}

[12/08/2023, 01:07:39] [SwitchBot] [DEBUG] Request successful, statusCode: 200

[12/08/2023, 01:07:39] [SwitchBot] [DEBUG] Headers: {"date":"Fri, 11 Aug 2023 17:07:39 GMT","content-type":"application/json","content-length":"73","connection":"keep-alive","x-amzn-requestid":"5a6586c7-8f35-4fbf-b95d-ca62fe871743","x-amz-apigw-id":"JgWiXGH-IAMEJ8A=","x-amzn-trace-id":"Root=1-64d66adb-1cf5dc35044e47695c5d835c;Sampled=0;lineage=c8c2b0f2:0|bf95bacf:0"}

[12/08/2023, 01:07:39] [SwitchBot] [DEBUG] SwitchBot Device Config Set: [{"deviceId":"CF:F4:61:9C:50:9D","configDeviceName":"Bot Door","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"switch","deviceType":"switch"},"firmware":"V6.3","refreshRate":6,"logging":"debug"},{"deviceId":"C1:38:32:30:44:61","configDeviceName":"Bot Light","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"press","deviceType":"switch"},"firmware":"V6.5","refreshRate":15,"external":false,"logging":"debug"}]

[12/08/2023, 01:07:39] [SwitchBot] [DEBUG] Failed to Discover Devices, Error Message: "Cannot read property 'map' of undefined", Submit Bugs Here: https://tinyurl.com/SwitchBotBug

[12/08/2023, 01:07:39] [SwitchBot] [DEBUG] Failed to Discover Devices, Error: TypeError: Cannot read property 'map' of undefined

[12/08/2023, 01:10:32] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 01:10:32] [SwitchBot] Initializing child bridge 0E:55:D6:94:91:A4

[12/08/2023, 01:10:34] [SwitchBot] Launched child bridge with PID 5406

[12/08/2023, 01:10:37] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.7.1 child bridge successfully

[12/08/2023, 01:10:37] [SwitchBot] [DEBUG] Using Config Logging: debug

[12/08/2023, 01:10:37] [SwitchBot] [DEBUG] Finished initializing platform:

[12/08/2023, 01:10:37] [SwitchBot] Platform Config: {"logging":"debug","refreshRate":6}

[12/08/2023, 01:10:37] [SwitchBot] [DEBUG] Using Default Push Rate.

[12/08/2023, 01:10:37] [SwitchBot] [DEBUG] Config OK

[12/08/2023, 01:10:38] [SwitchBot] [DEBUG] Executed didFinishLaunching callback

[12/08/2023, 01:10:40] [SwitchBot] [DEBUG] Devices: {}

[12/08/2023, 01:10:40] [SwitchBot] [DEBUG] Request successful, statusCode: 200

[12/08/2023, 01:10:40] [SwitchBot] [DEBUG] Headers: {"date":"Fri, 11 Aug 2023 17:10:40 GMT","content-type":"application/json","content-length":"73","connection":"keep-alive","x-amzn-requestid":"ac52f94e-ee4c-446e-8c9b-78aa99a4ce66","x-amz-apigw-id":"JgW-iHJKIAMETRw=","x-amzn-trace-id":"Root=1-64d66b8f-396ff15e39a11ed262b961e4;Sampled=0;lineage=c8c2b0f2:0|bf95bacf:0"}

[12/08/2023, 01:10:40] [SwitchBot] [DEBUG] SwitchBot Device Config Set: [{"deviceId":"CF:F4:61:9C:50:9D","configDeviceName":"Bot Door","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"switch","deviceType":"switch"},"firmware":"V6.3","refreshRate":6,"logging":"debug"},{"deviceId":"C1:38:32:30:44:61","configDeviceName":"Bot Light","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"press","deviceType":"switch"},"firmware":"V6.5","refreshRate":15,"external":false,"logging":"debug"}]

[12/08/2023, 01:10:40] [SwitchBot] [DEBUG] Failed to Discover Devices, Error Message: "Cannot read properties of undefined (reading 'map')", Submit Bugs Here: https://tinyurl.com/SwitchBotBug

[12/08/2023, 01:10:40] [SwitchBot] [DEBUG] Failed to Discover Devices, Error: TypeError: Cannot read properties of undefined (reading 'map')

[12/08/2023, 01:13:54] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 01:13:54] [SwitchBot] Initializing child bridge 0E:55:D6:94:91:A4

[12/08/2023, 01:13:56] [SwitchBot] Launched child bridge with PID 6654

[12/08/2023, 01:13:59] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 01:13:59] [SwitchBot] [DEBUG] Using Config Logging: debug

[12/08/2023, 01:13:59] [SwitchBot] [DEBUG] Finished initializing platform:

[12/08/2023, 01:13:59] [SwitchBot] [DEBUG] Platform Config: {"logging":"debug","refreshRate":6}

[12/08/2023, 01:13:59] [SwitchBot] [DEBUG] Using Default Push Rate.

[12/08/2023, 01:13:59] [SwitchBot] [DEBUG] Config OK

[12/08/2023, 01:14:00] [SwitchBot] [DEBUG] Executed didFinishLaunching callback

[12/08/2023, 01:14:02] [SwitchBot] [DEBUG] Devices: {}

[12/08/2023, 01:14:02] [SwitchBot] [DEBUG] Request successful, statusCode: 200

[12/08/2023, 01:14:02] [SwitchBot] [DEBUG] Headers: {"date":"Fri, 11 Aug 2023 17:14:02 GMT","content-type":"application/json","content-length":"73","connection":"keep-alive","x-amzn-requestid":"fc342878-cd12-4741-8da2-b83625fb834f","x-amz-apigw-id":"JgXeIF-7oAMFWyQ=","x-amzn-trace-id":"Root=1-64d66c5a-6efaa0f031f9a9b81e746a35;Sampled=0;lineage=c8c2b0f2:0|bf95bacf:0"}

[12/08/2023, 01:14:02] [SwitchBot] [DEBUG] SwitchBot Device Config Set: [{"deviceId":"CF:F4:61:9C:50:9D","configDeviceName":"Bot Door","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"switch","deviceType":"switch"},"firmware":"V6.3","refreshRate":6,"logging":"debug"},{"deviceId":"C1:38:32:30:44:61","configDeviceName":"Bot Light","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"press","deviceType":"switch"},"firmware":"V6.5","refreshRate":15,"external":false,"logging":"debug"}]

[12/08/2023, 01:14:02] [SwitchBot] [DEBUG] Failed to Discover Devices, Error Message: "Cannot read properties of undefined (reading 'map')", Submit Bugs Here: https://tinyurl.com/SwitchBotBug

[12/08/2023, 01:14:02] [SwitchBot] [DEBUG] Failed to Discover Devices, Error: TypeError: Cannot read properties of undefined (reading 'map')

[12/08/2023, 01:15:12] [SwitchBot] Initializing SwitchBot platform...

[12/08/2023, 01:15:12] [SwitchBot] Initializing child bridge 0E:55:D6:94:91:A4

[12/08/2023, 01:15:14] [SwitchBot] Launched child bridge with PID 6808

[12/08/2023, 01:15:17] [SwitchBot] Loaded @switchbot/homebridge-switchbot v2.8.0-beta.12 child bridge successfully

[12/08/2023, 01:15:17] [SwitchBot] [DEBUG] Using Config Logging: debug

[12/08/2023, 01:15:17] [SwitchBot] [DEBUG] Finished initializing platform:

[12/08/2023, 01:15:17] [SwitchBot] [DEBUG] Platform Config: {"logging":"debug","refreshRate":6}

[12/08/2023, 01:15:17] [SwitchBot] [DEBUG] Using Default Push Rate.

[12/08/2023, 01:15:17] [SwitchBot] [DEBUG] Config OK

[12/08/2023, 01:15:18] [SwitchBot] [DEBUG] Executed didFinishLaunching callback

[12/08/2023, 01:15:21] [SwitchBot] [DEBUG] Devices: {}

[12/08/2023, 01:15:21] [SwitchBot] [DEBUG] Request successful, statusCode: 200

[12/08/2023, 01:15:21] [SwitchBot] [DEBUG] Headers: {"date":"Fri, 11 Aug 2023 17:15:21 GMT","content-type":"application/json","content-length":"73","connection":"keep-alive","x-amzn-requestid":"df281bbc-a423-418b-a3a4-f7ba0e8f93d1","x-amz-apigw-id":"JgXqeE00IAMErWw=","x-amzn-trace-id":"Root=1-64d66ca9-162845ec48b225120501fd7b;Sampled=0;lineage=c8c2b0f2:0|bf95bacf:0"}

[12/08/2023, 01:15:21] [SwitchBot] [DEBUG] SwitchBot Device Config Set: [{"deviceId":"CF:F4:61:9C:50:9D","configDeviceName":"Bot Door","configDeviceType":"Bot","connectionType":"BLE/OpenAPI","bot":{"mode":"switch","deviceType":"switch"},"firmware":"V6.3","refreshRate":6,"logging":"debug"},{"deviceId":"C1:38:32:30:44:61","configDeviceName":"Bot Light","configDeviceType":"Bot","connectionType":"OpenAPI","bot":{"mode":"press","deviceType":"switch"},"firmware":"V6.5","refreshRate":15,"external":false,"logging":"debug"}]

[12/08/2023, 01:15:21] [SwitchBot] [DEBUG] Failed to Discover Devices, Error Message: "Cannot read properties of undefined (reading 'map')", Submit Bugs Here: https://tinyurl.com/SwitchBotBug

[12/08/2023, 01:15:21] [SwitchBot] [DEBUG] Failed to Discover Devices, Error: TypeError: Cannot read properties of undefined (reading 'map')

Config for homebridge-switchbot

{
    "bridge": {
        "name": "Bill Homebridge",
        "username": "0E:89:49:64:91:86",
        "port": 51430,
        "pin": "630-27-655"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "auth": "form",
            "theme": "auto",
            "tempUnits": "c",
            "lang": "auto",
            "platform": "config"
        },
        {
            "name": "SwitchBot",
            "credentials": {
                "token": "<hidden>",
                "secret": "<hidden>",
                "notice": "Keep your Token & Secret a secret!"
            },
            "options": {
                "devices": [
                    {
                        "deviceId": "CF:F4:61:9C:50:9D",
                        "configDeviceName": "Bot Door",
                        "configDeviceType": "Bot",
                        "connectionType": "BLE/OpenAPI",
                        "bot": {
                            "mode": "switch",
                            "deviceType": "switch"
                        },
                        "firmware": "V6.3",
                        "refreshRate": 6,
                        "logging": "debug"
                    },
                    {
                        "deviceId": "C1:38:32:30:44:61",
                        "configDeviceName": "Bot Light",
                        "configDeviceType": "Bot",
                        "connectionType": "OpenAPI",
                        "bot": {
                            "mode": "press",
                            "deviceType": "switch"
                        },
                        "firmware": "V6.5",
                        "refreshRate": 15,
                        "external": false,
                        "logging": "debug"
                    }
                ],
                "refreshRate": 6,
                "logging": "debug"
            },
            "_bridge": {
                "username": "0E:55:D6:94:91:A4",
                "port": 57234
            },
            "platform": "SwitchBot"
        }
    ],
    "disabledPlugins": []
}

Screenshots

image

image

image

Device and Model

SwitchBot Bot

Node.js Version

v20.5.0

NPM Version

v9.8.0

Homebridge Version

v1.6.1

Homebridge Switchbot Plugin Version

v2.8.0-beta.12

Homebridge Config UI X Plugin Version

v4.50.4

Operating System

Raspbian

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 25 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I have 1 bot and I’ve set it to poll 30 seconds and so far so good!

v2.8.0 is released

Sounds like your theory is plausible! Mine stop working again and I have set it to 5 second API refresh rate, which would incur at least 17,280 calls per day.

I wonder if this could be caused by the request limit? Since I have a short pull time period, I could reach 1000 times API calls per day which caused the error.

image

Hey @donavanbecker thanks for the latest beta! It is now working again!

The batteries in my bots are all dead so I haven’t encountered this, but the API is pretty flakey and the culprit seems to be:

[02/08/2023, 12:17:11] [SwitchBot] Bot: Bot Light Unknown statusCode: 500, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug

You’ll probably want to assert the status code is 200 or throw an error around here to avoid the undefined message: https://github.com/OpenWonderLabs/homebridge-switchbot/blob/09ff2520b0e2c7409a371e5c5c264aee17823a7e/src/device/bot.ts#L563-L566

or at the end of the statusCode()?

something like:

    if (statusCode !== 200) {
      throw new Error(`Unexpected status code: ${statusCode}`);
    }

As for discoverDevices, that one seems to return a 200, so maybe check the length of deviceLists instead of devicesAPI.body?

https://github.com/OpenWonderLabs/homebridge-switchbot/blob/472aef8bf69434f757c7cc573dc29d2b81d7bdf6/src/platform.ts#L295-L298

Probably a good idea to also throw an error if the status code is not 200.