diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 839a988..46fed33 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,11 +21,11 @@ jobs: ${{ runner.os }}-poetry- - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.11' - name: Install poetry uses: abatilo/actions-poetry@v2.3.0 with: - poetry-version: '1.3.2' + poetry-version: '1.6.1' - name: Install pip dependencies run: poetry install - name: pre-commit @@ -34,7 +34,7 @@ jobs: strategy: matrix: python-version: ['3.11', '3.10', '3.9', '3.8', '3.7'] - poetry-version: ['1.3.2'] + poetry-version: ['1.6.1'] runs-on: ubuntu-20.04 env: IS_COVERAGE_ALLOWED: ${{ secrets.CODECOV_TOKEN != '' }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e639dd7..0b18997 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,15 +11,17 @@ jobs: - uses: actions/checkout@master - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.11' - name: Install poetry uses: abatilo/actions-poetry@v2.3.0 with: - poetry-version: '1.3.2' + poetry-version: '1.6.1' - name: Install pip dependencies run: poetry install - name: Package - run: poetry build + run: | + poetry version ${{ github.event.release.tag_name }} + poetry build - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@v1.6.4 with: diff --git a/iolite_client/client.py b/iolite_client/client.py index 8790d59..8d20102 100755 --- a/iolite_client/client.py +++ b/iolite_client/client.py @@ -4,7 +4,7 @@ from base64 import b64encode from collections import defaultdict from dataclasses import dataclass -from typing import Dict, List, Optional, Union +from typing import Dict, List, Optional, Union, Callable import websockets @@ -144,6 +144,47 @@ def __init__(self, sid: str, username: str, password: str): self.sid = sid self.username = username self.password = password + self.messages = [] + + async def _consumer_handler(self, websocket): + async for message in websocket: + + # TODO: Build up discovered + + # TODO: add handlers to getting updates + + await consumer(message) + + async def _producer_handler(self, websocket): + while True: + if len(self.messages) == 0: + # TODO: potentially send key alive each 5 seconds + await asyncio.sleep(1) + continue + + message = self.messages.pop() + await self.__send_request(message, websocket) + + + async def _handler(self, websocket): + await asyncio.gather( + self._consumer_handler(websocket), + self._producer_handler(websocket), + ) + + + async def start(self): + self.messages.append(self.request_handler.get_subscribe_request("places")) + self.messages.append(self.request_handler.get_subscribe_request("devices")) + self.messages.append(self.request_handler.get_query_request("situationProfileModel")) + + uri = f"{self.BASE_URL}/bus/websocket/application/json?SID={self.sid}" + async with websockets.connect(uri, extra_headers=self._get_default_headers()) as websocket: + self._handler(websocket) + + async def async_set_temp(self, device_id: str, temp: float): + self.messages.append(self.request_handler.get_action_request(device_id, temp)) + @staticmethod async def __send_request(request: Union[str, dict], websocket): @@ -303,10 +344,3 @@ async def async_discover(self): def discover(self): """Discovers the entities registered within the heating system.""" asyncio.run(self.async_discover()) - - async def async_set_temp(self, device, temp: float): - request = self.request_handler.get_action_request(device, temp) - await asyncio.create_task(self._fetch_application([request])) - - def set_temp(self, device, temp: float): - asyncio.run(self.async_set_temp(device, temp)) diff --git a/pyproject.toml b/pyproject.toml index 84421c9..982747e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "iolite-client" -version = "0.6.0" +version = "0.0.0" description = "API client for interacting with IOLite's remote API" authors = ["Malachi Soord "] license = "MIT"