Skip to content

Commit

Permalink
fix: binary image updated sensors not working
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 committed Nov 13, 2024
1 parent a17df24 commit ed2c905
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 5 additions & 5 deletions custom_components/mail_and_packages/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
DOMAIN,
VERSION,
)
from .helpers import hash_file
from .helpers import default_image_path, hash_file

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -88,8 +88,8 @@ def is_on(self) -> bool:
attributes = (ATTR_IMAGE_NAME, ATTR_IMAGE_PATH)
if set(attributes).issubset(self.coordinator.data.keys()):
image = self.coordinator.data[ATTR_IMAGE_NAME]
path = self.coordinator.data[ATTR_IMAGE_PATH]
usps_image = f"{self.hass.config.path()}/{path}{image}"
path = default_image_path(self.hass, self._config)
usps_image = f"{path}/{image}"
usps_none = f"{os.path.dirname(__file__)}/mail_none.gif"
usps_check = os.path.exists(usps_image)
_LOGGER.debug("USPS Check: %s", usps_check)
Expand All @@ -108,8 +108,8 @@ def is_on(self) -> bool:
attributes = (ATTR_AMAZON_IMAGE, ATTR_IMAGE_PATH)
if set(attributes).issubset(self.coordinator.data.keys()):
image = self.coordinator.data[ATTR_AMAZON_IMAGE]
path = f"{self.coordinator.data[ATTR_IMAGE_PATH]}amazon/"
amazon_image = f"{self.hass.config.path()}/{path}{image}"
path = f"{default_image_path(self.hass, self._config)}/amazon/"
amazon_image = f"{path}{image}"
amazon_none = f"{os.path.dirname(__file__)}/no_deliveries.jpg"
amazon_check = os.path.exists(amazon_image)
_LOGGER.debug("Amazon Check: %s", amazon_check)
Expand Down
7 changes: 6 additions & 1 deletion custom_components/mail_and_packages/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ def default_image_path(
Returns the default path based on logic
"""
storage = config_entry.get(CONF_STORAGE)
storage = None
try:
storage = config_entry.get(CONF_STORAGE)
except AttributeError:
storage = config_entry.data[CONF_STORAGE]

if storage:
return storage
return "custom_components/mail_and_packages/images/"
Expand Down
1 change: 1 addition & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,4 +922,5 @@
"scan_interval": 20,
"username": "user@fake.email",
"verify_ssl": False,
"storage": "custom_components/mail_and_packages/images/",
}

0 comments on commit ed2c905

Please sign in to comment.