From ed2c905886b6f9012a1eed154feed9d317f34329 Mon Sep 17 00:00:00 2001 From: "firstof9@gmail.com" Date: Wed, 13 Nov 2024 10:00:44 -0700 Subject: [PATCH] fix: binary image updated sensors not working --- custom_components/mail_and_packages/binary_sensor.py | 10 +++++----- custom_components/mail_and_packages/helpers.py | 7 ++++++- tests/const.py | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/custom_components/mail_and_packages/binary_sensor.py b/custom_components/mail_and_packages/binary_sensor.py index 2919c098..573984ce 100644 --- a/custom_components/mail_and_packages/binary_sensor.py +++ b/custom_components/mail_and_packages/binary_sensor.py @@ -23,7 +23,7 @@ DOMAIN, VERSION, ) -from .helpers import hash_file +from .helpers import default_image_path, hash_file _LOGGER = logging.getLogger(__name__) @@ -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) @@ -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) diff --git a/custom_components/mail_and_packages/helpers.py b/custom_components/mail_and_packages/helpers.py index 8aae808c..647f7c22 100644 --- a/custom_components/mail_and_packages/helpers.py +++ b/custom_components/mail_and_packages/helpers.py @@ -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/" diff --git a/tests/const.py b/tests/const.py index 8bcce29d..ace20f47 100644 --- a/tests/const.py +++ b/tests/const.py @@ -922,4 +922,5 @@ "scan_interval": 20, "username": "user@fake.email", "verify_ssl": False, + "storage": "custom_components/mail_and_packages/images/", }