From e8531f3fafe02a6edfe01d7e59a0a8e25bbc9083 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 9 Apr 2023 23:47:33 +0200 Subject: [PATCH] Small fixes, Add checks --- .github/workflows/python-check.yml | 39 ++++++++++++++++++++++++++++++ README.md | 16 ++++++------ pyhon/__init__.py | 4 ++- pyhon/__main__.py | 1 - pyhon/connection/api.py | 9 ++++--- pyhon/connection/handler.py | 4 +-- 6 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/python-check.yml mode change 100644 => 100755 pyhon/__main__.py diff --git a/.github/workflows/python-check.yml b/.github/workflows/python-check.yml new file mode 100644 index 0000000..b5b6b8f --- /dev/null +++ b/.github/workflows/python-check.yml @@ -0,0 +1,39 @@ +name: Python check + +on: + push: + branches: [ "main", "refactor" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements.txt + python -m pip install flake8 pylint black + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics + # - name: Analysing the code with pylint + # run: | + # pylint --max-line-length 88 $(git ls-files '*.py') + - name: Check black style + run: | + black . --check diff --git a/README.md b/README.md index 46cfb42..b28df60 100644 --- a/README.md +++ b/README.md @@ -47,28 +47,28 @@ settings: ### List devices ```python import asyncio -from pyhon import HonConnection +from pyhon import Hon async def devices_example(): - async with HonConnection(USER, PASSWORD) as hon: - for device in hon.devices: - print(device.nick_name) + async with Hon(USER, PASSWORD) as hon: + for appliance in hon.appliances: + print(appliance.nick_name) asyncio.run(devices_example()) ``` ### Execute a command ```python -async with HonConnection(USER, PASSWORD) as hon: - washing_machine = hon.devices[0] +async with Hon(USER, PASSWORD) as hon: + washing_machine = hon.appliances[0] pause_command = washing_machine.commands["pauseProgram"] await pause_command.send() ``` ### Set command parameter ```python -async with HonConnection(USER, PASSWORD) as hon: - washing_machine = hon.devices[0] +async with Hon(USER, PASSWORD) as hon: + washing_machine = hon.appliances[0] start_command = washing_machine.commands["startProgram"] for name, setting in start_command.settings: print("Setting", name) diff --git a/pyhon/__init__.py b/pyhon/__init__.py index e2b5e87..93728b7 100644 --- a/pyhon/__init__.py +++ b/pyhon/__init__.py @@ -1,2 +1,4 @@ from .connection.api import HonAPI -from hon import Hon +from .hon import Hon + +__all__ = ["Hon", "HonAPI"] diff --git a/pyhon/__main__.py b/pyhon/__main__.py old mode 100644 new mode 100755 index 7eac5b6..a7afac8 --- a/pyhon/__main__.py +++ b/pyhon/__main__.py @@ -6,7 +6,6 @@ import logging import sys from getpass import getpass from pathlib import Path -from pprint import pprint if __name__ == "__main__": sys.path.insert(0, str(Path(__file__).parent.parent)) diff --git a/pyhon/connection/api.py b/pyhon/connection/api.py index c67a7e7..afe8591 100644 --- a/pyhon/connection/api.py +++ b/pyhon/connection/api.py @@ -10,12 +10,13 @@ _LOGGER = logging.getLogger() class HonAPI: - def __init__(self, email="", password="") -> None: + def __init__(self, email="", password="", anonymous=False) -> None: super().__init__() self._email = email self._password = password + self._anonymous = anonymous self._hon = None - self._hon_anonymous = HonAnonymousConnectionHandler() + self._hon_anonymous = None async def __aenter__(self): return await self.create() @@ -24,7 +25,9 @@ class HonAPI: await self._hon.close() async def create(self): - self._hon = await HonConnectionHandler(self._email, self._password).create() + self._hon_anonymous = HonAnonymousConnectionHandler() + if not self._anonymous: + self._hon = await HonConnectionHandler(self._email, self._password).create() return self async def load_appliances(self): diff --git a/pyhon/connection/handler.py b/pyhon/connection/handler.py index 428e52d..a239a69 100644 --- a/pyhon/connection/handler.py +++ b/pyhon/connection/handler.py @@ -27,11 +27,11 @@ class HonBaseConnectionHandler: @asynccontextmanager async def get(self, *args, **kwargs): - raise NotImplemented + raise NotImplementedError @asynccontextmanager async def post(self, *args, **kwargs): - raise NotImplemented + raise NotImplementedError async def close(self): await self._session.close()