From 26ad69ac7dd34b658c96a42afe205cf776b28fa1 Mon Sep 17 00:00:00 2001 From: Vignesh Rao Date: Tue, 24 Dec 2024 22:00:43 -0600 Subject: [PATCH] Remove explicit boolean check for smart devices --- docs/index.html | 2 +- jarvis/executors/files.py | 17 ++--------------- jarvis/executors/lights.py | 15 +++++++-------- jarvis/executors/tv.py | 14 ++++++-------- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/docs/index.html b/docs/index.html index 5b10f3ff..a3a0c543 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3696,7 +3696,7 @@

———-Executors———-
-jarvis.executors.files.get_smart_devices() dict | bool | None
+jarvis.executors.files.get_smart_devices() dict | None

Load smart devices’ data from feed file.

diff --git a/jarvis/executors/files.py b/jarvis/executors/files.py index 584ad8b0..5609601a 100644 --- a/jarvis/executors/files.py +++ b/jarvis/executors/files.py @@ -190,22 +190,9 @@ def put_automation( _dumper(models.fileio.automation, sorted_data) -def get_smart_devices() -> dict | bool | None: +def get_smart_devices() -> dict | None: """Load smart devices' data from feed file.""" - # fixme: Change the logic to NOT look for False specifically - try: - with open(models.fileio.smart_devices) as file: - if smart_devices := yaml.load(stream=file, Loader=yaml.FullLoader): - return smart_devices - else: - logger.warning("'%s' is empty.", models.fileio.smart_devices) - except (yaml.YAMLError, FileNotFoundError) as error: - if isinstance(error, FileNotFoundError): - logger.warning("%s not found.", models.fileio.smart_devices) - return - else: - logger.debug(error) - return False + return _loader(models.fileio.smart_devices) def put_smart_devices(data: dict) -> None: diff --git a/jarvis/executors/lights.py b/jarvis/executors/lights.py index 86dd8f5b..60b7c98f 100644 --- a/jarvis/executors/lights.py +++ b/jarvis/executors/lights.py @@ -123,16 +123,15 @@ def lights(phrase: str) -> None: if not internet.vpn_checker(): return - smart_devices = files.get_smart_devices() - if smart_devices is False: - speaker.speak( - text=f"I'm sorry {models.env.title}! I wasn't able to read the source information." - ) - return - if smart_devices and (lights_map := get_lights(data=smart_devices)): + if (smart_devices := files.get_smart_devices()) and ( + lights_map := get_lights(data=smart_devices) + ): logger.debug(lights_map) else: - logger.warning("%s is empty for lights.", models.fileio.smart_devices) + logger.warning( + "Smart devices are not configured for lights in %s", + models.fileio.smart_devices, + ) support.no_env_vars() return diff --git a/jarvis/executors/tv.py b/jarvis/executors/tv.py index 06531862..4701a824 100644 --- a/jarvis/executors/tv.py +++ b/jarvis/executors/tv.py @@ -101,17 +101,15 @@ def television(phrase: str) -> None: if not internet.vpn_checker(): return - smart_devices = files.get_smart_devices() - if smart_devices is False: - speaker.speak( - text=f"I'm sorry {models.env.title}! I wasn't able to read the source information." - ) - return - if smart_devices and (tv_mapping := get_tv(data=smart_devices)): + if (smart_devices := files.get_smart_devices()) and ( + tv_mapping := get_tv(data=smart_devices) + ): tv_map, key = tv_mapping logger.debug("%s stored with key: '%s'", tv_map, key) else: - logger.warning("%s is empty for tv.", models.fileio.smart_devices) + logger.warning( + "Smart devices are not configured for tv in %s", models.fileio.smart_devices + ) support.no_env_vars() return