hsakoh / switchbot-mqtt

SwitchBot MQTT Home Assistant add-on
MIT License
41 stars 1 forks source link

Fetch Devices By SwitchBotAPI fails, logged error: System.InvalidOperationException: Sequence contains no matching element #8

Closed pvince closed 9 months ago

pvince commented 9 months ago

Steps:

  1. Installed the integration via the store
  2. Started it
  3. Opened the web UI and clicked 'Fetch devices by SwitchBotApi'
  4. Nothing appeared to happen so I checked the integration's logs and saw the logs below

Other info:

Error section of the log that looks interesting is:

20:28:12 info: SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] device configuration file missing.
20:28:16 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Send GET,devices
20:28:16 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Response GET,https://api.switch-bot.com/v1.1/devices,{"statusCode":100,"body":{"deviceList":[{"device"deviceId":"REDACTED","deviceName":"Bedwarmer","deviceType":"Bot","enableCloudService":true,"hubDevice"deviceId":"REDACTED"},{"device"deviceId":"REDACTED","deviceName":"Paul's Curtain ","enableCloudService":true,"hubDevice"deviceId":"REDACTED","calibrate":true,"master":true,"openDirection":"left"},{"device"deviceId":"REDACTED","deviceName":"Emily's Curtain ","enableCloudService":true,"hubDevice"deviceId":"REDACTED","calibrate":true,"master":true,"openDirection":"left"},{"device"deviceId":"REDACTED","deviceName":"Hub Mini","deviceType":"Hub Mini","enableCloudService":false,"hubDeviceId":""}],"infraredRemoteList":[]},"message":"success"}
20:28:16 fail: SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] LoadDevicesAsync error. System.InvalidOperationException: Sequence contains no matching element    at System.Linq.ThrowHelper.ThrowNoMatchException()    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)    at SwitchBotMqttApp.Logics.DeviceConfigurationManager.<>c__DisplayClass9_0.<LoadDevicesAsync>b__0(Devicelist d) in C:\github\hsakoh\switchbot-mqtt\src\SwitchBotMqttApp\Logics\DeviceConfigurationManager.cs:line 86    at System.Linq.Enumerable.SelectArrayIterator`2.ToList()    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)    at SwitchBotMqttApp.Logics.DeviceConfigurationManager.LoadDevicesAsync(DevicesConfig currentData, CancellationToken cancellationToken)

Full Logs, some potentially sensitive information replaced with REDACTED, let me know if that info is actually important and I can include it:

20:27:37 warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35] No XML encryptor configured. Key {UUID_REDACTED} may be persisted to storage in unencrypted form.
20:27:37 info: Microsoft.Hosting.Lifetime[14] Now listening on: http://[::]:8098
20:27:37 info: Microsoft.Hosting.Lifetime[14] Now listening on: http://[::]:8099
20:27:37 dbug: SwitchBotMqttApp.Services.AutomatedHostedService[0] Application has started - will start services
20:27:37 info: SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] device configuration file missing.
20:27:37 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down.
20:27:37 info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production
20:27:37 info: Microsoft.Hosting.Lifetime[0] Content root path: /app/
20:27:37 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Send GET,scenes
20:27:38 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Response GET,https://api.switch-bot.com/v1.1/scenes,{"statusCode":100,"body":[],"message":"success"}
20:27:38 info: SwitchBotMqttApp.Services.MqttCoreService[0] started
20:27:38 info: SwitchBotMqttApp.Services.PollingService[0] started
20:27:38 info: FluffySpoon.Ngrok.NgrokProcess[0] Starting Ngrok process
20:27:39 info: FluffySpoon.Ngrok.NgrokApiClient[0] Creating tunnel SwitchBotMqttApp
20:27:39 info: FluffySpoon.Ngrok.NgrokApiClient[0] Tunnel FluffySpoon.Ngrok.Models.TunnelResponse created
20:27:39 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Send POST,webhook/queryWebhook
20:27:39 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Response POST,https://api.switch-bot.com/v1.1/webhook/queryWebhook,{"statusCode":190,"body":{},"message":""}
20:27:39 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Send POST,webhook/setupWebhook
20:27:39 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Response POST,https://api.switch-bot.com/v1.1/webhook/setupWebhook,{"statusCode":100,"body":{},"message":"success"}
20:27:39 info: SwitchBotMqttApp.Services.WebhookService[0] start listen https://9254-MY-IP-ADRESS-REDACTED.ngrok-free.app/webhook
20:28:12 info: SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] device configuration file missing.
20:28:16 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Send GET,devices
20:28:16 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Response GET,https://api.switch-bot.com/v1.1/devices,{"statusCode":100,"body":{"deviceList":[{"device"deviceId":"REDACTED","deviceName":"Bedwarmer","deviceType":"Bot","enableCloudService":true,"hubDevice"deviceId":"REDACTED"},{"device"deviceId":"REDACTED","deviceName":"Paul's Curtain ","enableCloudService":true,"hubDevice"deviceId":"REDACTED","calibrate":true,"master":true,"openDirection":"left"},{"device"deviceId":"REDACTED","deviceName":"Emily's Curtain ","enableCloudService":true,"hubDevice"deviceId":"REDACTED","calibrate":true,"master":true,"openDirection":"left"},{"device"deviceId":"REDACTED","deviceName":"Hub Mini","deviceType":"Hub Mini","enableCloudService":false,"hubDeviceId":""}],"infraredRemoteList":[]},"message":"success"}
20:28:16 fail: SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] LoadDevicesAsync error. System.InvalidOperationException: Sequence contains no matching element    at System.Linq.ThrowHelper.ThrowNoMatchException()    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)    at SwitchBotMqttApp.Logics.DeviceConfigurationManager.<>c__DisplayClass9_0.<LoadDevicesAsync>b__0(Devicelist d) in C:\github\hsakoh\switchbot-mqtt\src\SwitchBotMqttApp\Logics\DeviceConfigurationManager.cs:line 86    at System.Linq.Enumerable.SelectArrayIterator`2.ToList()    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)    at SwitchBotMqttApp.Logics.DeviceConfigurationManager.LoadDevicesAsync(DevicesConfig currentData, CancellationToken cancellationToken)
hsakoh commented 9 months ago

Please refer to the following issue.

3

It seems that some devices, such as Curtain 3, are not returning DeviceType as per the API interface specifications.

Please try defining the device ID and device type in the EnforceDeviceTypes option.

pvince commented 9 months ago

Thanks, that was exactly the push I needed to fix the issue.