add tapo cli
This commit is contained in:
parent
ea3f8f01bb
commit
4638bfae0e
7 changed files with 166 additions and 25 deletions
47
powercut.py
Normal file
47
powercut.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import asyncio
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import tapo
|
||||
from dotenv import load_dotenv
|
||||
from scapy.all import ICMP, IP, sr
|
||||
|
||||
load_dotenv()
|
||||
|
||||
tapo_username = os.getenv("TAPO_USERNAME")
|
||||
tapo_password = os.getenv("TAPO_PASSWORD")
|
||||
tapoip = os.getenv("TAPO_IP")
|
||||
|
||||
|
||||
async def powercycle():
|
||||
tapoapi = tapo.ApiClient(tapo_username, tapo_password)
|
||||
tapoplug = await tapoapi.p100(tapoip)
|
||||
await tapoplug.off()
|
||||
await asyncio.sleep(1)
|
||||
await tapoplug.on()
|
||||
|
||||
|
||||
asyncio.run(powercycle())
|
||||
|
||||
print("sleeping for 80s, then ping until up")
|
||||
|
||||
time.sleep(80)
|
||||
|
||||
while True:
|
||||
ans, unans = sr(IP(dst="192.168.42.6") / ICMP(), verbose=False)
|
||||
if len(ans) > 0:
|
||||
break
|
||||
|
||||
print("Collecting :")
|
||||
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + "-powercut"
|
||||
log_dir = Path("./logs") / timestamp
|
||||
log_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
shutil.copy(Path(sys.argv[0]), log_dir / sys.argv[0])
|
||||
|
||||
print(" - [x] script.py")
|
||||
Loading…
Add table
Add a link
Reference in a new issue