Fix Here Travel Time unable to find entity on startup#27237
Conversation
|
Can't we just catch the error when a template sensor doesn't render a valid value, and not continue the update? |
|
This is exactly what I implemented here. If the value is an entity_id it will recursively try to resolve it. If the value is in the form |
|
I just implemented a feature to catch circular references. Will push this later today. |
|
I mean that instead of changing the behavior, we just catch errors and log them. The user can define a template sensor that returns coordinates as needed in the state attributes. Why do we need to nest down when looking up entity_id? |
|
I prefer to check the argument over catching an I do understand that request as it simplifies things a lot and template sensors have the tendency to be |
|
We can postpone the first update until home assistant start event. We should avoid overloading options or code as much as possible. |
|
Postponing would definitely help with the template sensors. |
|
I think the user should use a template sensor for this case. We keep the interface clear and simple. |
|
I am still trying to understand why we don't want users to have this feature but force them to create an additional entity and learn templating. When you say interface, are you referring to the function interface? What do you think should be altered? The recursive nature as such or the following part? recursion_history=NoneAs for the regex matching for correct lat/long set: If we implement it this way instead of catching the exception we don't have to rely on the implementation details of the external lib. If the version gets upgraded to use new features and this bug was caught in the lib itself we would have to test for another exception. At least that was my line of reasoning 😄 |
|
When I said interface I meant the integration config option interface that the user uses. |
|
|
||
| # Check if state is valid coordinate set | ||
| pattern = r"-?\d{1,2}\.\d+,-?\d{1,3}\.\d+" | ||
| if re.fullmatch(pattern, entity.state): |
There was a problem hiding this comment.
I would prefer if we use our validators. They are more clear.
|
|
||
| # If zone was not found in state then use the state as the location | ||
| if entity_id.startswith("sensor."): | ||
| # Resolve nested entity |
There was a problem hiding this comment.
Remove the nesting check. We should keep the options interface simple.
|
Thank you for the voluptuous hint! Haven't thought of that. The options don't change for the user. Before this PR he was allowed to use either With this PR the user can also use the domains So the user does not get a new option for configuration, this PR is rather removing the constraint on the allowed domains for |
|
The behavior of the option changes. The user needs to take this into consideration. The user needs to know what we will do with the entity_id to set up the input select. I don't think this additional complexity is necessary. Reading the docs about the existing options I think we're already too complicated. |
|
I agree that this behavior is complex and a new user will not understand it directly. He will just follow the simple example in the documentation using fixed coordinates. In my opinion that complexity is harder to understand than the handling this PR tries to implement. That being said, this is just my opinion and I thought I was on the right track because I wasn't the only one requesting this feature. If you think homeassistant will be better of without this feature please feel free to close the PR. I will implement the state parsing with voluptuous instead of regex in a new PR. |
|
I'm happy to hear more opinions from other members. |
|
I was the user requesting this change in the first place. The way @eifinger implemented was the way I expected it to work in the first place.. |
|
From the use case point of view I can only agree to this solution. I'm travelling a lot and my destination changes nearly daily during working days. An input_text or automation which reads my calendar would give the needed flexibility to decide easy, where to go now and its much faster then opening google maps or whatelse |
f7b3fad to
2e88e6b
Compare
2e88e6b to
489ddb5
Compare
489ddb5 to
4db2ba0
Compare
|
Second Opinion from balloob in discord:
Based on this I removed the nested entity resolving and will readd it as part of a travel_time integration. This PR now "only" fixes #27465. |
Description:
@MartinHjelmare we discussed to remove pattern matching for origin/destination here.
I did however find out that this leads to uncaught errors when origin or destination is a template sensor and the state at the time of the update is not a valid coordinate:
Related issue (if applicable): fixes #27465
Pull request with documentation for home-assistant.io (if applicable): N/A
Example entry for
configuration.yaml(if applicable):N/A
Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest.requirements_all.txtby runningpython3 -m script.gen_requirements_all..coveragerc.If the code does not interact with devices: