Skip to content

Commit 2437e37

Browse files
committed
Fix refresh on first run offline
1 parent 37d900b commit 2437e37

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

simvue/eco/emissions_monitor.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ def check_refresh(self) -> bool:
187187
with self._data_file_path.open("r") as in_f:
188188
self._local_data = json.load(in_f)
189189

190+
if not self._client or not self._local_data:
191+
return False
192+
190193
if (
191-
self._client
192-
and not self._local_data.setdefault(self._client.country_code, {})
193-
) or self.outdated:
194+
not self._local_data.setdefault(self._client.country_code, {})
195+
or self.outdated
196+
):
194197
self._logger.info("🌍 CO2 emission outdated, calling API.")
195198
_data: CO2SignalResponse = self._client.get()
196199
self._local_data[self._client.country_code] = _data.model_dump(mode="json")

0 commit comments

Comments
 (0)