Skip to content

Commit

Permalink
Remove explicit boolean check for smart devices
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Dec 25, 2024
1 parent 11ce3cf commit 26ad69a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3696,7 +3696,7 @@ <h1>———-Executors———-<a class="headerlink" href="#executors" title="

<dl class="py function">
<dt class="sig sig-object py" id="jarvis.executors.files.get_smart_devices">
<span class="sig-prename descclassname"><span class="pre">jarvis.executors.files.</span></span><span class="sig-name descname"><span class="pre">get_smart_devices</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">dict</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">bool</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.executors.files.get_smart_devices" title="Permalink to this definition">¶</a></dt>
<span class="sig-prename descclassname"><span class="pre">jarvis.executors.files.</span></span><span class="sig-name descname"><span class="pre">get_smart_devices</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">dict</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.executors.files.get_smart_devices" title="Permalink to this definition">¶</a></dt>
<dd><p>Load smart devices’ data from feed file.</p>
</dd></dl>

Expand Down
17 changes: 2 additions & 15 deletions jarvis/executors/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 7 additions & 8 deletions jarvis/executors/lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 6 additions & 8 deletions jarvis/executors/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 26ad69a

Please sign in to comment.