add LED blink and Morse code scripts
This commit is contained in:
54
blink_led.py
Normal file
54
blink_led.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import argparse
|
||||
import os
|
||||
import time
|
||||
|
||||
import httpx
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
HOST = os.environ["HOST"]
|
||||
BASE = f"https://{HOST}/proxy/protect/integration/v1"
|
||||
HEADERS = {"X-API-Key": os.environ["API_KEY"]}
|
||||
CAMERA_NAME = "G6 Pro 360"
|
||||
|
||||
|
||||
def set_led(client: httpx.Client, camera_id: str, enabled: bool):
|
||||
client.patch(
|
||||
f"{BASE}/cameras/{camera_id}",
|
||||
json={"ledSettings": {"isEnabled": enabled}},
|
||||
).raise_for_status()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Blink the G6 Pro 360 status LED")
|
||||
parser.add_argument("--count", type=int, default=10, help="Number of blink cycles (default: 10)")
|
||||
parser.add_argument("--interval", type=float, default=0.5, help="Seconds per on/off half-cycle (default: 0.5)")
|
||||
args = parser.parse_args()
|
||||
|
||||
with httpx.Client(headers=HEADERS, verify=False) as client:
|
||||
cameras = client.get(f"{BASE}/cameras").raise_for_status().json()
|
||||
camera = next(c for c in cameras if CAMERA_NAME in c["name"])
|
||||
camera_id = camera["id"]
|
||||
original_led = camera["ledSettings"]["isEnabled"]
|
||||
print(f"Camera: {camera['name']} ({camera_id})")
|
||||
print(f"LED was: {'on' if original_led else 'off'}")
|
||||
print(f"Blinking {args.count} times, {args.interval}s interval — Ctrl+C to stop early")
|
||||
|
||||
try:
|
||||
for i in range(args.count):
|
||||
set_led(client, camera_id, True)
|
||||
print(f" [{i+1}/{args.count}] ON", flush=True)
|
||||
time.sleep(args.interval)
|
||||
set_led(client, camera_id, False)
|
||||
print(f" [{i+1}/{args.count}] OFF", flush=True)
|
||||
time.sleep(args.interval)
|
||||
except KeyboardInterrupt:
|
||||
print("\nInterrupted.")
|
||||
finally:
|
||||
set_led(client, camera_id, original_led)
|
||||
print(f"Restored LED to: {'on' if original_led else 'off'}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user