Skip to content

Commit d04b92e

Browse files
Handle missing device config
1 parent ee7a95a commit d04b92e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

custom_components/battery_notes/library.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@ class Library: # pylint: disable=too-few-public-methods
2727

2828
def __init__(self, hass: HomeAssistant) -> None:
2929
"""Init."""
30-
json_path = os.path.join(
31-
BUILT_IN_DATA_DIRECTORY,
32-
hass.data[DOMAIN][DOMAIN_CONFIG].get(CONF_LIBRARY, "library.json"),
33-
)
30+
31+
if DOMAIN_CONFIG not in hass.data[DOMAIN]:
32+
json_path = os.path.join(
33+
BUILT_IN_DATA_DIRECTORY,
34+
"library.json",
35+
)
36+
else:
37+
json_path = os.path.join(
38+
BUILT_IN_DATA_DIRECTORY,
39+
hass.data[DOMAIN][DOMAIN_CONFIG].get(CONF_LIBRARY, "library.json"),
40+
)
3441

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

0 commit comments

Comments
 (0)