Skip to content

Commit

Permalink
Properly support ResourceYAMLCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 committed Mar 6, 2024
1 parent 10616f9 commit 2c93963
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions custom_components/lock_code_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,24 @@ async def async_setup(hass: HomeAssistant, config: Config) -> bool:
if data[CONF_URL] == STRATEGY_PATH
)
except StopIteration:
# Register strategy module
data = await resources.async_create_item(
{CONF_RESOURCE_TYPE_WS: "module", CONF_URL: STRATEGY_PATH}
)
_LOGGER.debug("Registered strategy module (resource ID %s)", data[CONF_ID])
hass.data[DOMAIN]["resources"] = True
if isinstance(resources, ResourceYAMLCollection):
_LOGGER.warning(

Check warning on line 95 in custom_components/lock_code_manager/__init__.py

View check run for this annotation

Codecov / codecov/patch

custom_components/lock_code_manager/__init__.py#L95

Added line #L95 was not covered by tests
"Strategy module can't automatically be registered because this "
"Home Assistant instance is running in YAML mode for resources. "
"Please add a new entry in the list under the resources key in "
"the lovelace section of your config as follows:\n - url: %s"
"\n type: module",
STRATEGY_PATH,
)
else:
# Register strategy module
data = await resources.async_create_item(
{CONF_RESOURCE_TYPE_WS: "module", CONF_URL: STRATEGY_PATH}
)
_LOGGER.debug(
"Registered strategy module (resource ID %s)", data[CONF_ID]
)
hass.data[DOMAIN]["resources"] = True
else:
_LOGGER.debug(
"Strategy module already registered with resource ID %s", res_id
Expand Down

0 comments on commit 2c93963

Please sign in to comment.