mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-02 06:40:42 -07:00
api: allow lights.read() to be filtered by light names (#271)
## Link to GitHub Issue, if one exists Fixes https://github.com/spice2x/spice2x.github.io/issues/179 ## Description of change Previously, lights.read() did not accept any parameters, instead it returned all lights implemented by the current game. Problem is that this is too large for some embedded implementations; also just inefficient. Add code to accept light names as strings and only return those in the result. For performance, use `robin_hood::unordered_map` to speed up the lookup operation, which was previously a linear search. Add this to Python wrapper library. Did not bother with others. Also, as a bonus - update lights.write_reset() to also accept a flat list of strings, as opposed to array containing a string, which was silly. ## Compiling ➕ ## Testing Tested using spiceremote and writing a short Python program.
This commit is contained in:
@@ -2,8 +2,14 @@ from .connection import Connection
|
||||
from .request import Request
|
||||
|
||||
|
||||
def lights_read(con: Connection):
|
||||
res = con.request(Request("lights", "read"))
|
||||
def lights_read(con: Connection, light_names=None):
|
||||
req = Request("lights", "read")
|
||||
|
||||
if light_names:
|
||||
for light_name in light_names:
|
||||
req.add_param(light_name)
|
||||
|
||||
res = con.request(req)
|
||||
return res.get_data()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user