Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling status 500 from SwitchBot servers #36

Closed
MrXANA91 opened this issue Mar 17, 2024 · 1 comment · Fixed by #43
Closed

Handling status 500 from SwitchBot servers #36

MrXANA91 opened this issue Mar 17, 2024 · 1 comment · Fixed by #43

Comments

@MrXANA91
Copy link
Contributor

Some rare requests to the SwitchBot servers return status 500 and fail.

Would it be possible to handle those? Either by resending the request after some delays, or setting an error entity?


Here are the long logs I got :

Logger: homeassistant.components.automation.planning_chauffage
Source: helpers/script.py:485
integration: Automation (documentation, issues)
First occurred: 23:00:00 (2 occurrences)
Last logged: 23:00:00

Planning chauffage: Choose at step 1: choice 2: Error executing script. Unexpected error for call_service at pos 1: SwitchBot API server returns status 500
Planning chauffage: Error executing script. Unexpected error for choose at pos 1: SwitchBot API server returns status 500
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 723, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2319, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call
single_response = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 783, in async_turn_off
await self.async_set_hvac_mode(HVACMode.OFF)
File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 696, in async_set_hvac_mode
await self.hass.async_add_executor_job(self.set_hvac_mode, hvac_mode)
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/switchbotremote/climate.py", line 213, in set_hvac_mode
self.sb.turn("off")
File "/config/custom_components/switchbotremote/client/remote.py", line 65, in turn
self.command(humps.camelize(f"turn
{state}"))
File "/config/custom_components/switchbotremote/client/remote.py", line 53, in command
self.client.post(f"devices/{self.id}/commands", json=payload)
File "/config/custom_components/switchbotremote/client/client.py", line 63, in post
return self.request("POST", path, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/switchbotremote/client/client.py", line 49, in request
raise RuntimeError(f"SwitchBot API server returns status {response.status_code}")
RuntimeError: SwitchBot API server returns status 500

And probably a duplicate :

Logger: homeassistant.components.automation.planning_chauffage
Source: components/automation/init.py:666
integration: Automation (documentation, issues)
First occurred: 23:00:00 (1 occurrences)
Last logged: 23:00:00

While executing automation automation.planning_chauffage
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/automation/init.py", line 666, in async_trigger
return await self.action_script.async_run(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1600, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 435, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 487, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 512, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 943, in _async_choose_step
await self._async_run_script(script)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1100, in _async_run_script
result = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1600, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 435, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 487, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 512, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 723, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2319, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call
single_response = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 783, in async_turn_off
await self.async_set_hvac_mode(HVACMode.OFF)
File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 696, in async_set_hvac_mode
await self.hass.async_add_executor_job(self.set_hvac_mode, hvac_mode)
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/switchbotremote/climate.py", line 213, in set_hvac_mode
self.sb.turn("off")
File "/config/custom_components/switchbotremote/client/remote.py", line 65, in turn
self.command(humps.camelize(f"turn
{state}"))
File "/config/custom_components/switchbotremote/client/remote.py", line 53, in command
self.client.post(f"devices/{self.id}/commands", json=payload)
File "/config/custom_components/switchbotremote/client/client.py", line 63, in post
return self.request("POST", path, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/switchbotremote/client/client.py", line 49, in request
raise RuntimeError(f"SwitchBot API server returns status {response.status_code}")
RuntimeError: SwitchBot API server returns status 500

@KiraPC
Copy link
Owner

KiraPC commented Mar 19, 2024

@MrXANA91 would you like to work on it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants