diff --git a/examples/wsmock.py b/examples/wsmock.py index ac8794c..bb03310 100644 --- a/examples/wsmock.py +++ b/examples/wsmock.py @@ -6,15 +6,22 @@ import asyncio import aiohttp.web from datetime import datetime, timezone +import string +import random +HOST = "127.0.0.1" +PORT = 8080 +DEFAULT_PIN = "123456" RECEIVE_TIMEOUT = 1 class ChargePoint: - def __init__(self): - self.pin = "123456" - self.serial = "1908000575A" - self.url = "ws://127.0.0.1:8080/" + def __init__(self, serial: str | None = None, pin: str | None = None): + self.serial = ( + serial or "".join(random.choice(string.digits) for _ in range(10)) + "A" + ) + self.pin = pin or DEFAULT_PIN + self.url = f"ws://{HOST}:{PORT}/" self.connected = False async def send_status(self, ws) -> None: @@ -94,7 +101,7 @@ async def websocket_handler(request): def main() -> None: app = aiohttp.web.Application() app.router.add_route("GET", "/", websocket_handler) - aiohttp.web.run_app(app, host="127.0.0.1", port=8080) + aiohttp.web.run_app(app, host=HOST, port=PORT) if __name__ == "__main__":