Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions homeassistant/components/config/entity_registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""HTTP views to interact with the entity registry."""
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.components import websocket_api
from homeassistant.components.websocket_api.const import ERR_NOT_FOUND
from homeassistant.components.websocket_api.decorators import (
Expand Down Expand Up @@ -114,6 +115,15 @@ async def websocket_update_entity(hass, connection, msg):
websocket_api.error_message(msg["id"], "invalid_info", str(err))
)
else:

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

result = websocket_api.result_message(msg["id"], _entry_ext_dict(entry))
if "disabled_by" in changes and changes["disabled_by"] is None:
config_entry = hass.config_entries.async_get_entry(entry.config_entry_id)
if entry and not config_entry.supports_unload:
result["result"]["requires_restart"] = True
else:
result["result"][
"reload_delay"
] = config_entries.RELOAD_AFTER_UPDATE_DELAY

@emontnemery emontnemery Oct 31, 2020

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, fixed.

connection.send_message(
websocket_api.result_message(msg["id"], _entry_ext_dict(entry))
)
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
CONN_CLASS_ASSUMED = "assumed"
CONN_CLASS_UNKNOWN = "unknown"

RELOAD_AFTER_UPDATE_DELAY = 30


class ConfigError(HomeAssistantError):
"""Error while configuring an account."""
Expand Down Expand Up @@ -1109,8 +1111,6 @@ def as_dict(self) -> Dict[str, Any]:
class EntityRegistryDisabledHandler:
"""Handler to handle when entities related to config entries updating disabled_by."""

RELOAD_AFTER_UPDATE_DELAY = 30

def __init__(self, hass: HomeAssistant) -> None:
"""Initialize the handler."""
self.hass = hass
Expand Down Expand Up @@ -1167,7 +1167,7 @@ async def _handle_entry_updated(self, event: Event) -> None:
self._remove_call_later()

self._remove_call_later = self.hass.helpers.event.async_call_later(
self.RELOAD_AFTER_UPDATE_DELAY, self._handle_reload
RELOAD_AFTER_UPDATE_DELAY, self._handle_reload
)

async def _handle_reload(self, _now: Any) -> None:
Expand Down