Skip to content

Commit

Permalink
Fix KeyError for sourceTimes sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
cloneofghosts committed Sep 21, 2024
1 parent cff8abe commit 6936adb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ venv
.HA_VERSION
config/.storage/*
config/blueprints/*
.ruff_cache
.ruff_cache
config/deps/*
15 changes: 9 additions & 6 deletions custom_components/pirateweather/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,12 +1076,15 @@ def native_value(self) -> StateType:
"gfs_update_time",
"gefs_update_time",
]:
model_time_string = self._weather_coordinator.data.json["flags"][
"sourceTimes"
][self.entity_description.key]
native_val = datetime.datetime.strptime(
model_time_string[0:-1], "%Y-%m-%d %H"
).replace(tzinfo=datetime.UTC)
try:
model_time_string = self._weather_coordinator.data.json["flags"][
"sourceTimes"
][self.entity_description.key]
native_val = datetime.datetime.strptime(
model_time_string[0:-1], "%Y-%m-%d %H"
).replace(tzinfo=datetime.UTC)
except KeyError:
native_val = None

elif self.type == "minutely_summary":
native_val = getattr(
Expand Down

0 comments on commit 6936adb

Please sign in to comment.