1
0
Fork 0

add tapo cli

This commit is contained in:
Maurice Debray 2026-02-10 16:30:26 +01:00
parent ea3f8f01bb
commit efbd8d26f7
7 changed files with 166 additions and 25 deletions

47
powercut.py Normal file
View 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 = "10.1.1.79"
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(1)
while True:
ans, unans = sr(IP(dst="10.1.1.79") / 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")