Skip to content

Commit

Permalink
fix: validate keys in coordinator data before attempting to reference…
Browse files Browse the repository at this point in the history
… them (#910)
  • Loading branch information
firstof9 authored Jun 9, 2024
1 parent 8608d22 commit 7daf255
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions custom_components/mail_and_packages/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ def update_file_path(self) -> None:

if self._type == "usps_camera":
# Update camera image for USPS informed delivery images
image = self._coordinator.data[ATTR_IMAGE_NAME]
file_path = f"{os.path.dirname(__file__)}/mail_none.gif"

if ATTR_IMAGE_PATH in self._coordinator.data.keys():
s1 = set([ATTR_IMAGE_NAME, ATTR_IMAGE_PATH])
if s1.issubset(self._coordinator.data.keys()):
image = self._coordinator.data[ATTR_IMAGE_NAME]
path = self._coordinator.data[ATTR_IMAGE_PATH]
file_path = f"{self.hass.config.path()}/{path}{image}"
else:
Expand All @@ -157,10 +157,10 @@ def update_file_path(self) -> None:

elif self._type == "amazon_camera":
# Update camera image for Amazon deliveries
image = self._coordinator.data[ATTR_AMAZON_IMAGE]
file_path = f"{os.path.dirname(__file__)}/no_deliveries.jpg"

if ATTR_IMAGE_PATH in self._coordinator.data.keys():
s1 = set([ATTR_AMAZON_IMAGE, ATTR_IMAGE_PATH])
if s1.issubset(self._coordinator.data.keys()):
image = self._coordinator.data[ATTR_AMAZON_IMAGE]
path = f"{self._coordinator.data[ATTR_IMAGE_PATH]}amazon/"
file_path = f"{self.hass.config.path()}/{path}{image}"

Expand Down

0 comments on commit 7daf255

Please sign in to comment.