jeffsf / pyDE1

Controller for the Decent Espresso DE1
GNU General Public License v3.0
77 stars 16 forks source link

Scan docs refer to older API; null raises exception #36

Closed jeffsf closed 1 year ago

jeffsf commented 1 year ago

Update the Bluetooth Scanning doc to match https://pyde1.readthedocs.io/en/latest/CHANGELOG.html#b1-2022-03-19

Make sure null, as per those docs, doesn't raise

$ curl -X PATCH --data '{"begin": null}' http://localhost:1234/scan
Traceback (most recent call last):
  File "/home/pyde1/venv/pyde1/lib/python3.9/site-packages/pyDE1/dispatcher/dispatcher.py", line 179, in _request_queue_processor
    results_list = await patch_resource_from_dict(got.resource,
  File "/home/pyde1/venv/pyde1/lib/python3.9/site-packages/pyDE1/dispatcher/implementation.py", line 408, in patch_resource_from_dict
    await _patch_dict_to_mapping_inner(values_dict,
  File "/home/pyde1/venv/pyde1/lib/python3.9/site-packages/pyDE1/dispatcher/implementation.py", line 514, in _patch_dict_to_mapping_inner
    retval = await scan_from_api(new_value)
  File "/home/pyde1/venv/pyde1/lib/python3.9/site-packages/pyDE1/scanner.py", line 308, in scan_from_api
    elif timeout <= 0:
TypeError: '<=' not supported between instances of 'NoneType' and 'int'
jeffsf commented 1 year ago
diff --git a/src/pyDE1/scanner.py b/src/pyDE1/scanner.py
index 0e0423a..660bc6e 100644
--- a/src/pyDE1/scanner.py
+++ b/src/pyDE1/scanner.py
@@ -305,7 +305,7 @@ async def scan_from_api(timeout: Optional[Union[int, float, bool]]=None):
             "Passing false for 'begin' is deprecated. "
             "Pass a timeout in seconds or null to accept the default.")
         return None
-    elif timeout <= 0:
+    elif timeout is not None and timeout <= 0:
         raise DE1ValueError(
             f"Timeout must be greater than zero {timeout}")