Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/quickstart/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def slowly_increase_counter(self) -> None:
server = lt.ThingServer({"counter": TestThing})

# We run the server using `uvicorn`:
uvicorn.run(server.app, port=5000)
uvicorn.run(server.app, port=5000, ws="websockets-sansio")
2 changes: 1 addition & 1 deletion docs/source/tutorial/writing_a_thing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Our first Thing will pretend to be a light: we can set its brightness and turn i
if __name__ == "__main__":
import uvicorn
# We run the server using `uvicorn`:
uvicorn.run(server.app, port=5000)
uvicorn.run(server.app, port=5000, ws="websockets-sansio")

If you visit `http://localhost:5000/light`, you will see the Thing Description. You can also interact with it using the OpenAPI documentation at `http://localhost:5000/docs`. If you visit `http://localhost:5000/light/brightness`, you can set the brightness of the light, and if you visit `http://localhost:5000/light/is_on`, you can see whether the light is on. Changing values on the server requires a ``PUT`` or ``POST`` request, which is easiest to do using the OpenAPI "Try it out" feature. Check that you can use a ``POST`` request to the ``toggle`` endpoint to turn the light on and off.

Expand Down
4 changes: 2 additions & 2 deletions src/labthings_fastapi/server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"""
if args.config:
if args.json:
raise RuntimeError("Can't use both --config and --json simultaneously.")

Check warning on line 102 in src/labthings_fastapi/server/cli.py

View workflow job for this annotation

GitHub Actions / coverage

102 line is not covered with tests
try:
with open(args.config) as f:
return ThingServerConfig.model_validate_json(f.read())
Expand Down Expand Up @@ -161,7 +161,7 @@
server = ThingServer.from_config(config, True if args.debug else False)
if dry_run:
return server
uvicorn.run(server.app, host=args.host, port=args.port)
uvicorn.run(server.app, host=args.host, port=args.port, ws="websockets-sansio")
except BaseException as e:
if args.fallback:
print(f"Error: {e}")
Expand All @@ -174,11 +174,11 @@
)
)

uvicorn.run(app, host=args.host, port=args.port)
uvicorn.run(app, host=args.host, port=args.port, ws="websockets-sansio")
else:
if isinstance(e, (ValidationError, ThingImportFailure)):
print(f"Error reading LabThings configuration:\n{e}")
sys.exit(3)
else:
raise e
return None # This is required as we sometimes return the server

Check warning on line 184 in src/labthings_fastapi/server/cli.py

View workflow job for this annotation

GitHub Actions / coverage

184 line is not covered with tests
2 changes: 1 addition & 1 deletion tests/test_fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_actual_server_fallback():

# Starting the server is a SystemExit
with pytest.raises(SystemExit, match="3") as excinfo:
uvicorn.run(server.app, port=5000)
uvicorn.run(server.app, port=5000, ws="websockets-sansio")
server_error = excinfo.value
assert server.startup_failure is not None
assert server.startup_failure["thing"] == "bad_thing"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mjpeg_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ def test_mjpeg_stream(client):
assert isinstance(telly, Telly)
telly.framerate = 6
telly.frame_limit = -1
uvicorn.run(server.app, port=5000)
uvicorn.run(server.app, port=5000, ws="websockets-sansio")
Loading