boschshc-hass icon indicating copy to clipboard operation
boschshc-hass copied to clipboard

call_service throws 503

Open zimjjan opened this issue 3 years ago • 2 comments

In an automation, I'm currently setting eight covers at once to a custom position. Sometimes, the automation dies with an HTTP-503 error (see log attached). Unfortunately, this is not reproducible in a reliable manner.

I'm not sure, if I'm using too many "calls" at once. Does the integration queue the requests and sends them one by one or are they sent as soon as they "arrive"? I'd guess that this sometimes ends in an overload of the SHC.

Source: custom_components/bosch_shc/cover.py:104 
Integration: Automatisierung (documentation, issues) 
First occurred: 7:31:48 (2 occurrences) 
Last logged: 7:31:48

Bis später (Rolladen): Error executing script. Unexpected error for call_service at pos 7: API call returned non-OK result (code 503)!: b'{"@type":"JsonRestExceptionResponseEntity","errorCode":"SERVICE_INVOCATION_FAILED","statusCode":503}'
While executing automation automation.bis_spater
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 359, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 562, in _async_call_service_step
    await self._async_run_long_action(service_task)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 523, in _async_run_long_action
    long_task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 264, in service_handler
    await script_entity.async_turn_on(
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 375, in async_turn_on
    await coro
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 392, in _async_run
    return await self.script.async_run(variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1200, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 341, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 359, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 206, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 649, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 692, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/cover/__init__.py", line 281, in async_set_cover_position
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/bosch_shc/cover.py", line 104, in set_cover_position
    self._device.level = position / 100.0
  File "/usr/local/lib/python3.8/site-packages/boschshcpy/models_impl.py", line 182, in level
    self._service.put_state_element("level", level)
  File "/usr/local/lib/python3.8/site-packages/boschshcpy/device_service.py", line 49, in put_state_element
    self.put_state({key: value})
  File "/usr/local/lib/python3.8/site-packages/boschshcpy/device_service.py", line 44, in put_state
    self._api.put_device_service_state(
  File "/usr/local/lib/python3.8/site-packages/boschshcpy/api.py", line 164, in put_device_service_state
    self._put_api_or_fail(api_url, state_update)
  File "/usr/local/lib/python3.8/site-packages/boschshcpy/api.py", line 102, in _put_api_or_fail
    self._process_nok_result(result)
  File "/usr/local/lib/python3.8/site-packages/boschshcpy/api.py", line 123, in _process_nok_result
    raise SHCSessionError(
boschshcpy.exceptions.SHCSessionError: API call returned non-OK result (code 503)!: b'{"@type":"JsonRestExceptionResponseEntity","errorCode":"SERVICE_INVOCATION_FAILED","statusCode":503}'```

zimjjan avatar Jul 20 '21 08:07 zimjjan

I'll have a look on this. I am currently working on an async version, maybe this solves the issue. At my home, I control up to 11 covers (opening/closing). I will test what happens if I execute a custom position call to all covers at once.

tschamm avatar Jul 22 '21 07:07 tschamm

This occurs fairly often due to automations I use. Some of my lights may turn on and off quickly and then suddenly non of those lights are available for some time receiving 503. Is the plan building this async still valid?

Lyr3x avatar May 22 '22 17:05 Lyr3x