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

Report missing entities/areas instead of failing to match in Assist #107151

Merged
merged 5 commits into from
Jan 4, 2024

Conversation

synesthesiam
Copy link
Contributor

Breaking change

Proposed change

This PR:

  • Bumps hassil to 1.5.2: home-assistant/hassil@v1.5.1...v1.5.2
  • Adds better error messages for unmatched names and areas
  • Cleans up conversation tests to use snapshots instead of literal comparisons where appropriate

Hassil, the intent matching library behind Assist, will report an intent match failure if the names of entities or areas are not what it expects by default ("Sorry, I couldn't understand that").

This PR uses a new feature of hassil 1.5.2 to produce more useful error messages. If a match fails, hassil is run again with "unmatched entities" enabled (slower), and the "best" match is used to determine the error message.

Choosing the "best" match is tricky. For example, "turn on the overhead light" could be interpreted as:

  • turn on the <name> with name = "overhead light"
  • turn on the <area> <name> with area = "overhead", name = "light"

In fact, there are many more possible matches, some including "the" in the entity or area name, etc.
The "best" match is the one with:

  1. The fewest matching slots, so <name> or <area> will be preferred to <area> <name>
  2. The most literal text matching the sentence template, so "the" will not be part of <name>

Only errors relating to unmatched <name> and <area> slots are currently supported. Errors for unmatched domains and device classes require more changes, and will be done in a future PR.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Jan 4, 2024

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

Code owner commands

Code owners of conversation can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign conversation Removes the current integration label and assignees on the pull request, 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 pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@synesthesiam synesthesiam marked this pull request as ready for review January 4, 2024 16:49
@synesthesiam synesthesiam requested a review from a team as a code owner January 4, 2024 16:49
@synesthesiam synesthesiam requested review from balloob and removed request for a team January 4, 2024 16:49
@synesthesiam synesthesiam force-pushed the synesthesiam-20240103-better-errors branch from 73dc81c to e857103 Compare January 4, 2024 21:18
@synesthesiam synesthesiam merged commit 269500c into dev Jan 4, 2024
53 checks passed
@synesthesiam synesthesiam deleted the synesthesiam-20240103-better-errors branch January 4, 2024 23:09
@tetele
Copy link
Contributor

tetele commented Jan 5, 2024

@synesthesiam should we make the error messages a bit more friendly, more user-readable, while we're at it? Something like "Sorry, I am not aware of any area named dungeon" or "Sorry, I am not aware of any entity called floodlights"?

raman325 added a commit to raman325/home-assistant that referenced this pull request Jan 5, 2024
* upstream/dev: (2071 commits)
  Set zwave_js voltage sensor suggested precision (home-assistant#107116)
  Bump bluetooth-adapters to 0.17.0 (home-assistant#107195)
  Disable IPv6 in the opower integration to fix AEP utilities (home-assistant#107203)
  Fix conversation snapshots (home-assistant#107196)
  Report missing entities/areas instead of failing to match in Assist (home-assistant#107151)
  Bump to PyTado 0.17.3 (home-assistant#107181)
  Fix switch states in AVM FRITZ!Box Tools (home-assistant#107183)
  Fix tplink overloading power strips (home-assistant#104208)
  Update sensorpush-ble library to 1.6.1 (home-assistant#107168)
  Bump aiohomekit to 3.1.2 (home-assistant#107177)
  Introduce base entity in streamlabs water (home-assistant#107095)
  Clean up outdated entity replacement logic in Guardian (home-assistant#107160)
  Add conversation_id parameter to conversation.process service (home-assistant#106078)
  Pass aiohttp clientsession to tedee integration (home-assistant#107089)
  Update Home Assistant base image to 2024.01.0 - Python 3.12 (home-assistant#107175)
  Remove precision in streamlabs water (home-assistant#107096)
  Pass down language to hassil (home-assistant#106490)
  Use snapshots in Glances sensor tests (home-assistant#107159)
  Cache homekit_controller supported features (home-assistant#106702)
  Migrate AVM FRITZ!Box Call monitor to has entity name (home-assistant#99752)
  ...
@synesthesiam
Copy link
Contributor Author

Yes, we need the errors to say that something couldn't be found, not that it isn't there.

I was thinking something like "Sorry, I couldn't find an area named X".

@tetele
Copy link
Contributor

tetele commented Jan 5, 2024

Correct me if i'm wrong: there are 2 possible reasons for which an entity can't be handled - either it doesn't exist with that name/alias or it's not exposed.

For areas, the only possible reason is that it doesn't exist with that name/alias.

I was thinking something like "Sorry, I couldn't find an area named X".

For me personally, it seems like "couldn't find" (traditionally, in UIs) hints more towards inexistence and less towards lack of exposure, whereas "I am not aware" is vague enough to hint to both. Shall we ask the Discord community? Do you want to take an executive decision? :D

@github-actions github-actions bot locked and limited conversation to collaborators Jan 6, 2024
@synesthesiam
Copy link
Contributor Author

I do like the "not aware" terminology" better than "couldn't find".

This question gets trickier with domain and device class constraints. A failure with "turn on lights in the kitchen" could be a missing area, no lights in the kitchen, or just no exposed lights. I think for this case, we may want to have an extra definitive error: "there are no lights in the kitchen".

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

Successfully merging this pull request may close these issues.

3 participants