Skip to content

Commit

Permalink
fix: run binary sensor hash checks in executor properly (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 authored Nov 14, 2024
1 parent b866f6b commit e6c8c4e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions custom_components/mail_and_packages/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Binary sensors for Mail and Packages."""

import asyncio
import logging
import os

Expand Down Expand Up @@ -94,8 +95,9 @@ def is_on(self) -> bool:
usps_check = os.path.exists(usps_image)
_LOGGER.debug("USPS Check: %s", usps_check)
if usps_check:
image_hash = self.hass.add_job(hash_file, usps_image)
none_hash = self.hass.add_job(hash_file, usps_none)
loop = asyncio.get_running_loop()
image_hash = loop.run_in_executor(None, hash_file, usps_image)
none_hash = loop.run_in_executor(None, hash_file, usps_none)

_LOGGER.debug("USPS Image hash: %s", image_hash)
_LOGGER.debug("USPS None hash: %s", none_hash)
Expand All @@ -114,8 +116,9 @@ def is_on(self) -> bool:
amazon_check = os.path.exists(amazon_image)
_LOGGER.debug("Amazon Check: %s", amazon_check)
if amazon_check:
image_hash = self.hass.add_job(hash_file, amazon_image)
none_hash = self.hass.add_job(hash_file, amazon_none)
loop = asyncio.get_running_loop()
image_hash = loop.run_in_executor(None, hash_file, amazon_image)
none_hash = loop.run_in_executor(None, hash_file, amazon_none)

_LOGGER.debug("Amazon Image hash: %s", image_hash)
_LOGGER.debug("Amazon None hash: %s", none_hash)
Expand Down

0 comments on commit e6c8c4e

Please sign in to comment.