Service calls with return values for platform entity services #948
-
In the discussion #777 it was decided to add return values for services. To enable more services to support return values we should add it to Pro:
Con:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 17 replies
-
I am not aware of additional concerns to address. My impression is we already have a stance on the primary concern around matching multiple entities, unless there are more implementation details i'm missing. Prior discussions:
To move this forward, I think we need the core architecture folks to weigh in on whether there is something else explicit we're missing here: Either additional concerns around platform entities missed from the original proposal, an implicit desire to support return values for multiple entities (where calendar needs an answer) or if we're on the same page with the prior work here. |
Beta Was this translation helpful? Give feedback.
-
I assume this applies for home-assistant/core#97280 as well then? |
Beta Was this translation helpful? Give feedback.
-
I'd also like to have this feature enabled. So I suggest to start with allowing responses in platform entities when only one entity is targeted. It would be a caller's responsibility to ensure that. Then we can think of extending that into multiple entities. |
Beta Was this translation helpful? Give feedback.
-
Yes, my question is more specific: what additional discussion needs to happen? What's missing from the original architecture discussion? What are the questions we need to answer or additional considerations we need to talk through for this case? IMO this has all been settled, so I can't tell if there is disagreement or misunderstanding. |
Beta Was this translation helpful? Give feedback.
-
Alright, so first of all, sorry for my late reply on this one. I've discussed this with Paulus, Erik, Martin & Robert a bit ago and this is a summary of where this can go. There are three possible paths: 1. Allow service calls with responses only on a single entityThis means that after resolving the target (including area and/or device), if only a single target entity is left, we are able to return a response. In case a call returns multiple entities, we will raise. Pro: The nice thing about this is that the response value is just as any non-entity service and thus maybe more familiar. Cons: When targeting, for example, an area, or when using a template for the target; a change in the environment (e.g., new device added to an area), may cause anything that uses the service to fail all of a sudden. Thus may break automation and script in surprising ways. 2. Return a dictionary when multiple entities are targetWhen multiple entities are resolved, return a dictionary keyed with the entity ID. For example (in YAML data format for readability in the example): light.living_room:
some_value: true
light.kitchen:
some_value: false However, when a single entity is targeted, return the normal version: some_value: true Pro: The output is kinda more expected. When targeting a single entity you'll just get data from a single entity, when targeting multiple, you'll get multiple. Cons: When targeting, for example, an area, or when using a template for the target; a change in the environment (e.g., new device added to an area) that cases the response to go from single to multiple results, may cause anything that uses the service to fail all of a sudden as the returned data format changes. This may break automation and script in surprising ways. 3. Always return a dictionary when using entity servicesSimilar to option 2, expect we will always return a dictionary: light.living_room:
some_value: true and light.living_room:
some_value: true
light.kitchen:
some_value: false Pro: Consistency Cons: A little harder to work with / process in templates. SuggestionFrom these perspectives, we lean towards the solution in option 3. The consistency (and thus avoiding breaking things all of a sudden later on), seems like an important value in this case. As it prevents surprises later on. While it is a little less friendly to use, it will be consistent in the output provided, while also maintaining the target ability feature that entity service have. ../Frenck |
Beta Was this translation helpful? Give feedback.
Discussed this today again, this time include the context on the breaking change for the services. And this is what we ended up with:
We are going with option 3 set out above.
This means two services will be breaking:
weather.get_forecast
andcalendar.list_events
.There is no way to ease this and the only solution we see is:
../Frenck