Closed MrXANA91 closed 7 months ago
Currently testing this version on my HA instance.
I have tested by forcing a returned status to 500 at random, and it effectively resends the same request after 0.5s repeatedly, until the return status is 200. If the 5 tries all failed with 500, then it aborts and raise a SwitchbotInternal500Error
exception to the Home Assistant core.
And of course, since I started testing this fix, the 500 error status no longer appear for me ...
Making it ready for review anyway, still testing
Going back to draft during testing
Not tested yet, I'll let you know
A few minutes ago, when trying to send a turn_off
command, i've noticed a unusual slightly longer delay between me pressing the button and the AC signaling a received command.
When checking the logs, here is what I've found :
...
2024-04-08 19:35:00.318 DEBUG (SyncWorker_27) [custom_components.switchbotremote.client.remote] Sending command turnOff
2024-04-08 19:35:00.318 DEBUG (SyncWorker_27) [custom_components.switchbotremote.client.remote] Command payload {'commandType': 'command', 'command': 'turnOff', 'parameter': 'default'}
2024-04-08 19:35:00.318 DEBUG (SyncWorker_27) [custom_components.switchbotremote.client.client] Calling service https://api.switch-bot.com/v1.1/devices/01-202404032246-40583347/commands
2024-04-08 19:35:00.662 DEBUG (SyncWorker_27) [custom_components.switchbotremote.client.client] Received http error 500 {"message": "Internal server error"}
2024-04-08 19:35:00.662 WARNING (SyncWorker_27) [custom_components.switchbotremote.client.client] Caught returned status 500 from SwitchBot API server
2024-04-08 19:35:00.662 DEBUG (SyncWorker_27) [custom_components.switchbotremote.client.client] tryNumber = 0, waiting 500 ms
2024-04-08 19:35:01.164 DEBUG (SyncWorker_27) [custom_components.switchbotremote.client.client] Calling service https://api.switch-bot.com/v1.1/devices/01-202404032246-40583347/commands
2024-04-08 19:35:01.694 DEBUG (SyncWorker_27) [custom_components.switchbotremote.client.client] Call service https://api.switch-bot.com/v1.1/devices/01-202404032246-40583347/commands OK
...
So the fix is actually working properly. Marking it as ready!
Great, merging
This PR aims to fix #36 and to generally improve the exceptions potentially raised by the integration using the Home Assistant exception classes
If the Switchbot servers return a 500 status, the integration will send a warning to the Home Assistant logs. It will wait 0.5s and will then try to resend the same command. After 5 consecutive 500 status failures, it will (should ?) abort and raise an error to Home Assistant.