18
18
from homeassistant .helpers .event import async_track_utc_time_change
19
19
from homeassistant .helpers .storage import STORAGE_DIR
20
20
21
- from .coordinator import MY_KEY
21
+ from .coordinator import MY_KEY , BatteryNotesDomainConfig
22
22
from .discovery import DiscoveryManager
23
23
24
24
_LOGGER = logging .getLogger (__name__ )
@@ -38,7 +38,9 @@ def __init__(self, hass: HomeAssistant):
38
38
"""Initialize the library updater."""
39
39
self .hass = hass
40
40
41
- domain_config = self .hass .data [MY_KEY ]
41
+ domain_config = self .hass .data .get (MY_KEY )
42
+ if not domain_config :
43
+ domain_config = BatteryNotesDomainConfig ()
42
44
43
45
library_url = domain_config .library_url
44
46
schema_url = domain_config .schema_url
@@ -61,7 +63,7 @@ async def timer_update(self, now: datetime):
61
63
62
64
domain_config = self .hass .data [MY_KEY ]
63
65
64
- if domain_config .enable_autodiscovery :
66
+ if domain_config and domain_config .enable_autodiscovery :
65
67
discovery_manager = DiscoveryManager (self .hass , domain_config )
66
68
await discovery_manager .start_discovery ()
67
69
else :
@@ -90,7 +92,9 @@ def _update_library_json(library_file: str, content: str) -> None:
90
92
_update_library_json , json_path , content
91
93
)
92
94
93
- self .hass .data [MY_KEY ].library_last_update = datetime .now ()
95
+ domain_config = self .hass .data .get (MY_KEY )
96
+ if domain_config :
97
+ self .hass .data [MY_KEY ].library_last_update = datetime .now ()
94
98
95
99
_LOGGER .debug ("Updated library" )
96
100
else :
@@ -117,6 +121,10 @@ async def copy_schema(self):
117
121
async def time_to_update_library (self , hours : int ) -> bool :
118
122
"""Check when last updated and if OK to do a new library update."""
119
123
try :
124
+ domain_config = self .hass .data .get (MY_KEY )
125
+ if not domain_config :
126
+ return True
127
+
120
128
if library_last_update := self .hass .data [MY_KEY ].library_last_update :
121
129
time_since_last_update = (
122
130
datetime .now () - library_last_update
0 commit comments