Skip to content

Commit

Permalink
fake more
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Jun 27, 2024
1 parent b4eeb49 commit 81fedd9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions examples/wsmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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__":
Expand Down

0 comments on commit 81fedd9

Please sign in to comment.