Skip to content

Commit

Permalink
slightly cleaned the functions and changed os by platform, that seem …
Browse files Browse the repository at this point in the history
…a more robust solution
  • Loading branch information
eolus87 committed Jun 13, 2023
1 parent 7e5de94 commit c66b1d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions control/control_functions.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
__author__ = "Nicolas Gutierrez"

# Standard libraries
import os
import time
import platform
import asyncio
from typing import Tuple
# Third party libraries
import kasa
# Custom libraries

if os.name == 'nt':
if platform.system() == 'Windows':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())


async def switch_on(target: str) -> bool:
plug = kasa.SmartPlug(target)
try:
await plug.turn_on()
await asyncio.sleep(0.1)
await plug.update()
await asyncio.sleep(0.1)
await plug.turn_on()
is_successful = plug.is_on
except Exception as inst:
print(f"Switch on function failed with error: {inst}")
Expand All @@ -35,9 +33,9 @@ def switch_on_function(target: str) -> bool:
async def switch_off(target: str) -> bool:
plug = kasa.SmartPlug(target)
try:
await plug.turn_off()
await asyncio.sleep(0.1)
await plug.update()
await asyncio.sleep(0.1)
await plug.turn_off()
is_successful = plug.is_off
except Exception as inst:
print(f"Switch off function failed with error: {inst}")
Expand Down
4 changes: 2 additions & 2 deletions power/power_function.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
__author__ = "Nicolas Gutierrez"

# Standard libraries
import os
import platform
import asyncio
from typing import Tuple
# Third party libraries
import kasa
# Custom libraries

if os.name == 'nt':
if platform.system() == 'Windows':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())


Expand Down

0 comments on commit c66b1d6

Please sign in to comment.