Extend WS API result when enabling an entity#42667
Extend WS API result when enabling an entity#42667bramkragten merged 6 commits intohome-assistant:devfrom
Conversation
| result["result"]["requires_restart"] = True | ||
| else: | ||
| result["result"][ | ||
| "reload_delay" | ||
| ] = config_entries.RELOAD_AFTER_UPDATE_DELAY |
There was a problem hiding this comment.
Maybe the WS response should be reorganized such that the entity_entry is moved to a sub dict:
result = websocket_api.result_message(msg["id"], {"entity_entry":_entry_ext_dict(entry)})There was a problem hiding this comment.
Yes, better move the entry to a dict to not conflate keys.
| @@ -114,9 +115,18 @@ async def websocket_update_entity(hass, connection, msg): | |||
| websocket_api.error_message(msg["id"], "invalid_info", str(err)) | |||
| ) | |||
| else: | |||
There was a problem hiding this comment.
Let's drop this else and instead do a return inside the except.
| else: | ||
| connection.send_message( | ||
| websocket_api.result_message(msg["id"], _entry_ext_dict(entry)) | ||
| result = websocket_api.result_message( |
There was a problem hiding this comment.
Don't create a result and then mutate the result. It means you're assuming that the result message will stay the same.
Instead, build up your response, then wrap it. Use connection.send_result(msg['id'], result) also, don't use result_message or error_message anymore.
There was a problem hiding this comment.
Fixed to build up the response, wrap it, then use connection.send_result(msg['id'], result) to send it off.
Not using result_message or error_message would be better as a separate PR.
balloob
left a comment
There was a problem hiding this comment.
Looks good! Can be merged when frontend is 👍
Co-authored-by: Williamnumismatics <169579672+Williamnumismatics@users.noreply.github.com> Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com> Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Proposed change
Extend WS API result when enabling an entity.
The purpose is to improve user experience:
Note: A frontend PR is also needed.
Type of change
Additional information
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:
To help with the load of incoming pull requests: