From d3b1ba156fce9d66097c5f59c41617b083fbfeec Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 14 Apr 2022 22:53:49 -0700 Subject: [PATCH] Add product endpoint and align function names with API names (#7) --- example.py | 2 +- pyevilgenius/__init__.py | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/example.py b/example.py index cbb0012..fcf7bd6 100644 --- a/example.py +++ b/example.py @@ -21,7 +21,7 @@ async def run(websession): host = sys.argv[1] device = pyevilgenius.EvilGeniusDevice(host, websession) - data = await device.get_data() + data = await device.get_all() for item in data.values(): if "value" not in item: diff --git a/pyevilgenius/__init__.py b/pyevilgenius/__init__.py index 4c1ffe7..d65ebce 100644 --- a/pyevilgenius/__init__.py +++ b/pyevilgenius/__init__.py @@ -15,12 +15,17 @@ def __init__(self, host: str, session: ClientSession): self._request_lock = asyncio.Lock() async def get_info(self): - """Get the info from the Evil Genius service.""" + """Get the info.""" async with self._request_lock, self._session.get(f"{self.url}/info") as resp: return await resp.json() - async def get_data(self): - """Get the data from the Evil Genius service.""" + async def get_product(self): + """Get the product name.""" + async with self._request_lock, self._session.get(f"{self.url}/product") as resp: + return await resp.json() + + async def get_all(self): + """Get all the data.""" async with self._request_lock, self._session.get(f"{self.url}/all") as resp: data = await resp.json() @@ -39,3 +44,18 @@ async def set_rgb_color(self, red: int, green: int, blue: int) -> None: f"{self.url}/solidColor?r={red}&g={green}&b={blue}" ) as resp: resp.raise_for_status() + + async def get_field_value(self, name: str): + """Query the field value endpoint.""" + async with self._request_lock, self._session.get( + f"{self.url}/fieldValue", params={"name": name} + ) as resp: + return await resp.text() + + async def set_field_value(self, name: str, value: Any): + """Set a value using the field value endpoint.""" + async with self._request_lock, self._session.post( + f"{self.url}/fieldValue", params={"name": name, "value": value} + ) as resp: + resp.raise_for_status() + return await resp.text()