Skip to content

Commit

Permalink
Add support for calling LW3 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jalle19 committed Sep 10, 2024
1 parent 688b3f0 commit de2b9bb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions custom_components/vinx/lw3.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ async def _run_get_all(self, path: str) -> Response:

return await self._read_and_parse_response()

async def _run_call(self, path: str, method: str) -> Response:
async with self._semaphore:
self._writer.write(f"0000#CALL {path}:{method}\r\n".encode())
await self._writer.drain()

return await self._read_and_parse_response()

async def get_property(self, path: str) -> PropertyResponse:
response = await asyncio.wait_for(self._run_get(path), self._timeout)

Expand All @@ -192,6 +199,14 @@ async def set_property(self, path: str, value: str) -> PropertyResponse:
async def get_all(self, path: str) -> Response:
return await asyncio.wait_for(self._run_get_all(path), self._timeout)

async def call(self, path: str, method: str) -> MethodResponse:
response = await asyncio.wait_for(self._run_call(path, method), self._timeout)

if not isinstance(response, MethodResponse):
raise ValueError(f"Called method {path}:{method} does not return a method response")

return response


class LW3ConnectionContext:
def __init__(self, lw3: LW3):
Expand Down

0 comments on commit de2b9bb

Please sign in to comment.