Skip to content

Commit

Permalink
get_cache_dir should only be used to set the default location
Browse files Browse the repository at this point in the history
  • Loading branch information
cereal2nd committed Jul 3, 2024
1 parent 73bde1d commit f84dd56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions velbusaio/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def __init__(
# make sure the cachedir exists
pathlib.Path(self._cache_dir).mkdir(parents=True, exist_ok=True)

def get_cache_dir(self) -> str:
return self._cache_dir

async def _on_message_received(self, msg: RawMessage) -> None:
"""On message received function."""
await self._handler.handle(msg)
Expand Down
9 changes: 5 additions & 4 deletions velbusaio/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from velbusaio.messages.module_subtype import ModuleSubTypeMessage
from velbusaio.messages.module_type import ModuleTypeMessage, ModuleType2Message
from velbusaio.raw_message import RawMessage
from velbusaio.helpers import get_cache_dir


if TYPE_CHECKING:
Expand Down Expand Up @@ -63,8 +62,8 @@ def empty_cache(self) -> bool:
len(
[
name
for name in os.listdir(f"{get_cache_dir()}")
if os.path.isfile(f"{get_cache_dir()}/{name}")
for name in os.listdir(f"{self._velbus.get_cache_dir()}")
if os.path.isfile(f"{self._velbus.get_cache_dir()}/{name}")
]
)
== 0
Expand All @@ -78,6 +77,8 @@ async def scan(self, reload_cache: bool = False) -> None:
self._scan_complete = False
# non-blocking check to see if the cache_dir is empty
loop = asyncio.get_running_loop()
print(self._velbus.get_cache_dir())
print(await loop.run_in_executor(None, self.empty_cache))
if not reload_cache and await loop.run_in_executor(None, self.empty_cache):
self._log.info("No cache yet, so forcing a bus scan")
reload_cache = True
Expand All @@ -92,7 +93,7 @@ async def scan(self, reload_cache: bool = False) -> None:

self._log.info(f"Starting handling scan {address}")

cfile = pathlib.Path(f"{get_cache_dir()}/{address}.json")
cfile = pathlib.Path(f"{self._velbus.get_cache_dir()}/{address}.json")
# cleanup the old module cache if needed
scanModule = reload_cache
if scanModule and os.path.isfile(cfile):
Expand Down

0 comments on commit f84dd56

Please sign in to comment.