home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.02k stars 31.05k forks source link

Matter integration raises MatterError instead of HomeAssistantError for failed action calls #128246

Open PaulSD opened 1 month ago

PaulSD commented 1 month ago

The problem

Per the integration developer docs, Integrations should raise HomeAssistantError exceptions for device communication failures on action calls.

The Matter Integration does not do that. More specifically, it does not catch/translate MatterError exceptions raised by python-matter-server, so it effectively raises MatterError instead of HomeAssistantError for device errors.

One impact of this is that an Automation (which calls an action on a Matter device) will terminate if a Matter device error occurs, even if continue_on_error is set in the Automation. (Because continue_on_error only ignores HomeAssistantError exceptions.)

I think this should be fairly easy to fix, but there are a number of different ways to fix it and it isn't clear to me which would fit best into the current design / coding style, so I don't want to attempt a fix without some guidance, and you might find that fixing it is easier than providing guidance. (eg. Would it make sense to add a wrapper around matter_client.send_device_command() to MatterEntity and translate exceptions there? Should there be a single generic MatterHomeAssistantError, or should different MatterError classes from python-matter-server be translated to different HomeAssistantError classes?)

What version of Home Assistant Core has the issue?

2024.10.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Matter

Link to integration documentation on our website

https://www.home-assistant.io/integrations/matter/

Diagnostics information

No response

Example YAML snippet

actions:
  - repeat:
      sequence:
        - target:
          action: light.turn_on
          entity_id: light.test
          continue_on_error: true

Anything in the logs that might be useful for us?

Example partial stack trace of an Automation (with `continue_on_error` set on the `action`) failing after a transient Matter device timeout:

  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 742, in async_trigger
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1795, in async_run
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 463, in async_run
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 580, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1021, in entity_service_call
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1610, in async_request_call
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
  File "/usr/src/homeassistant/homeassistant/components/matter/light.py", line 308, in async_turn_on
    await self.send_device_command(
  File "/usr/src/homeassistant/homeassistant/components/matter/light.py", line 276, in send_device_command
    await self.matter_client.send_device_command(
  File "/usr/local/lib/python3.12/site-packages/matter_server/client/client.py", line 454, in send_device_command
  File "/usr/local/lib/python3.12/site-packages/matter_server/client/client.py", line 583, in send_command
matter_server.common.errors.UnknownError: src/app/CommandSender.cpp:328: CHIP Error 0x00000032: Timeout

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @home-assistant/matter, mind taking a look at this issue as it has been labeled with an integration (matter) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `matter` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign matter` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


matter documentation matter source (message by IssueLinks)