Skip to content

Extend WS API result when enabling an entity#42667

Merged
bramkragten merged 6 commits intohome-assistant:devfrom
emontnemery:enable_entity_extend_result
Nov 9, 2020
Merged

Extend WS API result when enabling an entity#42667
bramkragten merged 6 commits intohome-assistant:devfrom
emontnemery:enable_entity_extend_result

Conversation

@emontnemery
Copy link
Contributor

Proposed change

Extend WS API result when enabling an entity.
The purpose is to improve user experience:

  • Some entities won't be enabled until HA is restarted
  • Entities won't be enabled until after a long delay

Note: A frontend PR is also needed.

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)
  • 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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

Comment on lines +122 to +126
result["result"]["requires_restart"] = True
else:
result["result"][
"reload_delay"
] = config_entries.RELOAD_AFTER_UPDATE_DELAY
Copy link
Contributor Author

@emontnemery emontnemery Oct 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better move the entry to a dict to not conflate keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, fixed.

@@ -114,9 +115,18 @@ async def websocket_update_entity(hass, connection, msg):
websocket_api.error_message(msg["id"], "invalid_info", str(err))
)
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop this else and instead do a return inside the except.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

else:
connection.send_message(
websocket_api.result_message(msg["id"], _entry_ext_dict(entry))
result = websocket_api.result_message(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can be merged when frontend is 👍

@bramkragten bramkragten merged commit 5694e41 into home-assistant:dev Nov 9, 2020
Thomas55555 pushed a commit to Thomas55555/core that referenced this pull request Feb 24, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants