Small fixes, Add checks

This commit is contained in:
Andre Basche 2023-04-09 23:47:33 +02:00
parent 8dc6cd71cd
commit e8531f3faf
6 changed files with 58 additions and 15 deletions

39
.github/workflows/python-check.yml vendored Normal file
View File

@ -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

View File

@ -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)

View File

@ -1,2 +1,4 @@
from .connection.api import HonAPI
from hon import Hon
from .hon import Hon
__all__ = ["Hon", "HonAPI"]

1
pyhon/__main__.py Normal file → Executable file
View File

@ -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))

View File

@ -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):

View File

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