Add .env support for test scripts
- Update test_control_server.py to use python-dotenv - Read CONTROL_SERVER_URI from environment variable - Create .env.example with configuration examples - Test scripts now respect .env configuration for WebSocket URI
This commit is contained in:
11
.env.example
Normal file
11
.env.example
Normal file
@@ -0,0 +1,11 @@
|
||||
# Lighting Controller Configuration
|
||||
|
||||
# WebSocket URI for the control server
|
||||
# Used by UI client and test scripts to connect to the control server
|
||||
#
|
||||
# For local development (running on same machine as control server):
|
||||
CONTROL_SERVER_URI=ws://localhost:8765
|
||||
#
|
||||
# For remote connection (running on different machine from control server):
|
||||
# Replace with your control server's IP address
|
||||
# CONTROL_SERVER_URI=ws://10.1.1.117:8765
|
@@ -18,6 +18,11 @@ import asyncio
|
||||
import json
|
||||
import websockets
|
||||
import re
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
|
||||
def build_messages(args):
|
||||
@@ -77,7 +82,8 @@ async def run_test(uri: str, messages: list[dict], sleep_s: float):
|
||||
|
||||
def parse_args():
|
||||
p = argparse.ArgumentParser(description="Send UI commands to control_server WebSocket")
|
||||
p.add_argument("--uri", default="ws://localhost:8765", help="WebSocket URI (default ws://localhost:8765)")
|
||||
default_uri = os.getenv("CONTROL_SERVER_URI", "ws://localhost:8765")
|
||||
p.add_argument("--uri", default=default_uri, help=f"WebSocket URI (default from .env or {default_uri})")
|
||||
p.add_argument("--pattern", help="Pattern name for pattern_change")
|
||||
p.add_argument("--r", type=int, help="Red 0-255 for color_change")
|
||||
p.add_argument("--g", type=int, help="Green 0-255 for color_change")
|
||||
|
Reference in New Issue
Block a user