Skip to content

Commit

Permalink
Merge pull request #315 from Pirate-Weather/keyerror-fix
Browse files Browse the repository at this point in the history
Fix KeyError for `sourceTimes` sensor
  • Loading branch information
cloneofghosts authored Sep 21, 2024
2 parents cff8abe + 6936adb commit 065f4be
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 065f4be

Please sign in to comment.