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

grocy.delete_generic returns Error 400 for chores #300

Open
droans opened this issue Dec 19, 2023 · 0 comments
Open

grocy.delete_generic returns Error 400 for chores #300

droans opened this issue Dec 19, 2023 · 0 comments

Comments

@droans
Copy link

droans commented Dec 19, 2023

Unless all relevant information is provided, I can't help you

Describe the bug
The current implementation does not work when deleting chores and possibly more.

Expected behavior
grocy.delete_generic should properly delete chores.

To Reproduce
Steps to reproduce the behavior:

  1. Get the ID of a chore to be deleted.
  2. In the Service Tab of Developer Tools, select "Grocy: Delete Generic". Set Entity Type to "chores" and Object ID to the ID from step 1.
  3. HA returns Error 400. Logs do not provide much more information.

General information to help debugging:

The service call does not work when the object ID is set to either a string or an integer.

Service call YAML:

service: grocy.delete_generic
data:
  entity_type: chores
  object_id: 55    # Have also tried "55" to no avail.

What is your installed versions of Home Assistant, Grocy and this integration?
HA 2023.12.3, Grocy 4.0.3, Grocy custom component v4.11.1

How do you have Grocy installed? Add-on or external?
External, Docker

Have you added debugging to the log, and what does the log say?

2023-12-19 08:43:45.728 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139620577845184] Error handling message: Unknown error (unknown_error) XXXX from Y.Y.Y.Y (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 782, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1578, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2067, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2104, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/grocy/services.py", line 182, in async_call_grocy_service
    await async_delete_generic_service(hass, coordinator, service_data)
  File "/config/custom_components/grocy/services.py", line 327, in async_delete_generic_service
    await hass.async_add_executor_job(wrapper)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/grocy/services.py", line 325, in wrapper
    coordinator.grocy_api.delete_generic(entity_type, object_id)
  File "/usr/local/lib/python3.11/site-packages/pygrocy/grocy.py", line 376, in delete_generic
    return self._api_client.delete_generic(entity_type, object_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pygrocy/grocy_api_client.py", line 789, in delete_generic
    return self._do_delete_request(f"objects/{entity_type}/{object_id}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pygrocy/grocy_api_client.py", line 412, in _do_delete_request
    raise GrocyError(resp)
pygrocy.errors.grocy_error.GrocyError: <Response [400]>

JSON service data (if related to using a service)
See above.

Additional context
I have downloaded pygrocy locally and manually tested it with my details. It was properly able to delete the chore using the same details.

I am able to properly update chores using the grocy.update_generic service call. I'm not sure how the issue is occurring as the relevant code for each function appear to be the same. I have also manually run the relevant code, substituting coordinator.grocy_api with a manual client, and have also been fine running the service.

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

No branches or pull requests

1 participant