Skip to content

Commit

Permalink
Handle missing device config
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Dec 13, 2023
1 parent ee7a95a commit d04b92e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions custom_components/battery_notes/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ class Library: # pylint: disable=too-few-public-methods

def __init__(self, hass: HomeAssistant) -> None:
"""Init."""
json_path = os.path.join(
BUILT_IN_DATA_DIRECTORY,
hass.data[DOMAIN][DOMAIN_CONFIG].get(CONF_LIBRARY, "library.json"),
)

if DOMAIN_CONFIG not in hass.data[DOMAIN]:
json_path = os.path.join(
BUILT_IN_DATA_DIRECTORY,
"library.json",
)
else:
json_path = os.path.join(
BUILT_IN_DATA_DIRECTORY,
hass.data[DOMAIN][DOMAIN_CONFIG].get(CONF_LIBRARY, "library.json"),
)

_LOGGER.debug("Using library file at %s", json_path)

Expand Down

0 comments on commit d04b92e

Please sign in to comment.