Skip to content

Commit abd251c

Browse files
Refactor entity validation and error handling in async_setup_entry
1 parent e51e58f commit abd251c

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

custom_components/calendar_event/__init__.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
5656

5757
entity_registry = er.async_get(hass)
5858

59-
# try:
60-
# entity_id = er.async_validate_entity_id( # noqa: F841
61-
# entity_registry, entry.options[CONF_CALENDAR_ENTITY_ID]
62-
63-
if (
64-
calendar_entity := entity_registry.entities.get_entry(
65-
entry.options[CONF_CALENDAR_ENTITY_ID]
59+
try:
60+
_ = er.async_validate_entity_id(
61+
entity_registry, entry.options[CONF_CALENDAR_ENTITY_ID]
6662
)
67-
) is None:
63+
except vol.Invalid:
6864
async_create_issue(
6965
hass,
7066
DOMAIN,
@@ -97,13 +93,7 @@ def set_source_entity_id_or_uuid(source_entity_id: str) -> None:
9793
)
9894

9995
async def source_entity_removed() -> None:
100-
# The source entity has been removed.
101-
LOGGER.error(
102-
"Failed to setup calendar_event for unknown entity %s",
103-
entry.options[CONF_CALENDAR_ENTITY_ID],
104-
)
105-
106-
# Create a repair issue for the removed calendar entity
96+
# The source entity has been removed, create a repair issue for the removed calendar entity.
10797
async_create_issue(
10898
hass,
10999
DOMAIN,

0 commit comments

Comments
 (0)