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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log warning when entities referenced in service call not found #31427
Conversation
homeassistant/helpers/service.py
Outdated
found.append(entity) | ||
|
||
if entity_ids: | ||
raise EntitiesNotFound(entity_ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like this. But only in the case of all integration support unique_id
and are restored on startup. Without this perfect world scenario, you will break automation/action/scripts after startup until everything is set up and the latest retry was successful.
I can tell you that this will cause a lot of breakage. I've seen and been involved in many discussions on the forum where the solution to a tricky problem is to use a non-existing Granted, this is not documented behavior, but it's been that way so long that it has become a de facto solution. Maybe to allow that same use case accept a new keyword for |
@pnbruckner I don't understand the use case. Why would you specify an entity ID if you also have a data_template to specify it? Edit: Oh I understand it now. You are trying to pick a script to run, but sometimes none apply and you want to do nothing. |
Alright, so I will change it to a warning now. @pnbruckner I think that the solution for the use case that you brought up is that people create a |
Oof, will this affect set states for non-existing entities? |
@balloob, yes, for scripts that is an acceptable solution and one that I've often suggested. However, maybe I used a poor example, because I've seen the same scenario with other entities, like lights, switches, etc., when you need to determine the entity to act upon via a |
I'm pretty much in agreement with @pnbruckner. Without an option like 'none' or 'no-entity' for entity_id, people would have to create many 'dummy' objects. Imagine trying to do that for media_player. Template media_player doesn't exist, so it would be impossible. |
I've added support for passing |
@Petro31 this will not affect setting states for non-existing entities. The state machine doesn't know about entities, just states and so is not affected. This only affects picking entities in service calls. |
Ignore as the logger: config can take care of my concern. |
EDIT: As pointed out by Petro, we can remove items from logging as require, so amendment request revoked |
Besides using the logger, why not just set it to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I was surprised, though, how many files had to be changed to implement this. But after looking at the changes, I guess I shouldn't have been. Sounds like an opportunity for some refactoring someday. 馃槄
Yeah, lots of places doing their own entity extraction. They won't work with area selectors or anything else that we add in the future. I added a bunch of nice new helpers in 105 that should solve this (home-assistant/developers.home-assistant#401). |
I think that is good now. So if you change entity ids, it will not break instantly a lot of automation/service calls 馃憤 |
Breaking change
Service calls that reference non-existing entities will now log warning instead of silently being omitted. If you are using a template and want to select no entities, pass
none
instead.The TTS integration will no longer target all media players if no entity ID passed in. Specify
all
instead.Proposed change
Now that we restore entities on boot, we can be sure that entities will exist. This means that we can start
raising errorsprint warnings when referenced entities are not found instead of silently omitting them.This is a RFC because the impact is unknown. If we want to move on with this idea, we could start with just printing a warning instead of failing.
Tests will be added if functionality approved.AddedType of change
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale: