Skip to content

Commit 8b52fce

Browse files
Do not throw warning on initial library update
1 parent b973cab commit 8b52fce

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

custom_components/battery_notes/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
128128

129129
library_updater = LibraryUpdater(hass)
130130
await library_updater.copy_schema()
131-
await library_updater.get_library_updates(dt_util.utcnow())
131+
await library_updater.get_library_updates(startup=True)
132132

133133
if domain_config.enable_autodiscovery:
134134
discovery_manager = DiscoveryManager(hass, domain_config)
@@ -180,7 +180,8 @@ async def async_remove_entry(hass: HomeAssistant, config_entry: BatteryNotesConf
180180
if coordinator.source_entity_id:
181181
store.async_delete_entity(coordinator.source_entity_id)
182182
else:
183-
store.async_delete_device(coordinator.device_id)
183+
if coordinator.device_id:
184+
store.async_delete_device(coordinator.device_id)
184185

185186
_LOGGER.debug("Removed battery note %s", config_entry.entry_id)
186187

custom_components/battery_notes/config_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async def async_step_device(
162162

163163
library_updater = LibraryUpdater(self.hass)
164164
if await library_updater.time_to_update_library(1):
165-
await library_updater.get_library_updates(dt_util.utcnow())
165+
await library_updater.get_library_updates()
166166

167167
device_registry = dr.async_get(self.hass)
168168
device_entry = device_registry.async_get(device_id)
@@ -250,7 +250,7 @@ async def async_step_entity(
250250

251251
library_updater = LibraryUpdater(self.hass)
252252
if await library_updater.time_to_update_library(1):
253-
await library_updater.get_library_updates(dt_util.utcnow())
253+
await library_updater.get_library_updates()
254254

255255
device_registry = dr.async_get(self.hass)
256256
device_entry = device_registry.async_get(entity_entry.device_id)

custom_components/battery_notes/coordinator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ def __init__(
188188
last_replaced,
189189
)
190190

191-
self.last_replaced = (
192-
datetime.fromisoformat(last_replaced) if last_replaced else None
193-
)
191+
if last_replaced:
192+
self.last_replaced = datetime.fromisoformat(last_replaced)
194193

195194
# If there is not a last_reported set to now
196195
if not self.last_reported:

custom_components/battery_notes/library_updater.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def timer_update(self, now: datetime):
5757
if await self.time_to_update_library(23) is False:
5858
return
5959

60-
await self.get_library_updates(now)
60+
await self.get_library_updates()
6161

6262
domain_config = self.hass.data[MY_KEY]
6363

@@ -68,7 +68,7 @@ async def timer_update(self, now: datetime):
6868
_LOGGER.debug("Auto discovery disabled")
6969

7070
@callback
71-
async def get_library_updates(self, now: datetime):
71+
async def get_library_updates(self, startup: bool = False) -> None:
7272
# pylint: disable=unused-argument
7373
"""Make a call to get the latest library.json."""
7474

@@ -97,9 +97,10 @@ def _update_library_json(library_file: str, content: str) -> None:
9797
_LOGGER.error("Library file is invalid, not updated")
9898

9999
except LibraryUpdaterClientError:
100-
_LOGGER.warning(
101-
"Unable to update library, will retry later."
102-
)
100+
if not startup:
101+
_LOGGER.warning(
102+
"Unable to update library, will retry later."
103+
)
103104

104105
async def copy_schema(self):
105106
"""Copy schema file to storage to be relative to downloaded library."""

0 commit comments

Comments
 (0)