custom-components / grocy

Custom Grocy integration for Home Assistant
Apache License 2.0
163 stars 50 forks source link

Error Completing Chores via Custom Component - GrocyError: <Response [400]> #316

Closed audeen closed 16 hours ago

audeen commented 1 day ago

Description: I am experiencing an issue when trying to mark chores as complete using the Grocy custom component and Grocy Chore Cards in Home Assistant. While the API appears to be working correctly (data is fetched and displayed on the dashboard), clicking on "Complete" fails to update the Grocy database and results in the following error:

Error Log:

Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:526
First occurred: 6:07:19 PM (3 occurrences)
Last logged: 6:07:28 PM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: <Response [400]>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/grocy/services.py", line 173, in async_call_grocy_service
    await async_complete_task_service(hass, coordinator, service_data)
  File "/config/custom_components/grocy/services.py", line 274, in async_complete_task_service
    await hass.async_add_executor_job(wrapper)
  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/grocy/services.py", line 272, in wrapper
    coordinator.grocy_api.complete_task(task_id)
  File "/usr/local/lib/python3.12/site-packages/pygrocy/grocy.py", line 330, in complete_task
    return self._api_client.complete_task(task_id, done_time)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pygrocy/grocy_api_client.py", line 747, in complete_task
    self._do_post_request(url, data)
  File "/usr/local/lib/python3.12/site-packages/pygrocy/grocy_api_client.py", line 375, in _do_post_request
    raise GrocyError(resp)
pygrocy.errors.grocy_error.GrocyError: <Response [400]>

Environment Details:

Home Assistant version: 2024.11.3
Grocy custom component version: 4.11.1
Grocy Chore Cards version: 3.8.2
Grocy version: 0.22.1

Steps to Reproduce:

Install Grocy, Grocy custom components, and Grocy Chore Cards.
Configure the integration and confirm that data is retrieved successfully (chores are visible on the dashboard).
Attempt to complete a chore via the dashboard by clicking "Complete."
Observe that the chore is not marked as complete in the Grocy database, and the error described above is logged.

Expected Behavior: Clicking "Complete" should successfully update the chore status in the Grocy database without errors.

Additional Context:

API data retrieval is functioning correctly, as I can see the chores listed on the dashboard.

Please let me know if additional logs, configurations, or testing details are required.

audeen commented 16 hours ago

Solution Found:

The issue was caused by a missing or incorrect user_id mapping in the YAML configuration for the Grocy Chores and Tasks Card.

This is also stated in the Documentation. I did not expect that to be the problem.

Here is the working configuration that resolved the problem:

type: custom:grocy-chores-card entity:

Explanation:

The user_id mapping is essential when multiple users exist in Home Assistant and Grocy.
This configuration ensures that actions are properly assigned to the correct Grocy user based on the currently logged-in Home Assistant user.
The default ID ensures that actions are always assigned to a default user if no specific user mapping is found.

After adding this mapping, the card works as expected, and chores and tasks can be marked as complete without any issues.