Skip to content

Commit

Permalink
Add product endpoint and align function names with API names (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob authored Apr 15, 2022
1 parent b5e2c1e commit d3b1ba1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 23 additions & 3 deletions pyevilgenius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

0 comments on commit d3b1ba1

Please sign in to comment.