Skip to content

Commit

Permalink
Use poetry, add pre-commit hooks & mass format to modern standards, a…
Browse files Browse the repository at this point in the history
…dd CI (#47)

* Use poetry, add pre-commit hooks & mass format to modern standards, add CI

* Remove requirements.txt, add codecov dep

* Add construct dep

* Remove mac & windows builds as bluepy is linux-only
  • Loading branch information
rytilahti authored Mar 3, 2022
1 parent 9946ff4 commit 4e19f27
Show file tree
Hide file tree
Showing 14 changed files with 378 additions and 193 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
workflow_dispatch: # to allow manual re-runs


jobs:
linting:
name: "Perform linting checks"
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: |
python -m pip install --upgrade pip poetry tox
poetry install
- name: "Run pre-commit -a"
run: |
poetry run pre-commit run -a
tests:
name: "Python ${{ matrix.python-version}} on ${{ matrix.os }}"
needs: linting
runs-on: ${{ matrix.os }}

strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.7"]
os: [ubuntu-latest]

steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: |
python -m pip install --upgrade pip poetry
poetry install
- name: "Run tests"
run: |
poetry run pytest --cov eq3bt --cov-report xml
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: check-ast

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args: ['--py37-plus']

- repo: https://github.com/python/black
rev: 22.1.0
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
additional_dependencies: [toml]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
hooks:
- id: mypy
2 changes: 0 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,3 @@ Changelog
- Initial Commit Version 0.2.0. [Markus Peter]

- Initial commit. [Markus Peter]


Empty file removed __init__.py
Empty file.
4 changes: 2 additions & 2 deletions eq3bt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# flake8: noqa
from .eq3btsmart import Thermostat, TemperatureException, Mode
from .structures import *
from .eq3btsmart import Mode, TemperatureException, Thermostat
from .structures import *
22 changes: 16 additions & 6 deletions eq3bt/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
A simple wrapper for bluepy's btle.Connection.
Handles Connection duties (reconnecting etc.) transparently.
"""
import logging
import codecs
import logging

from bluepy import btle

Expand Down Expand Up @@ -36,7 +36,9 @@ def __enter__(self):
try:
self._conn.connect(self._mac, iface=self._iface)
except btle.BTLEException as ex:
_LOGGER.debug("Unable to connect to the device %s, retrying: %s", self._mac, ex)
_LOGGER.debug(
"Unable to connect to the device %s, retrying: %s", self._mac, ex
)
try:
self._conn.connect(self._mac, iface=self._iface)
except Exception as ex2:
Expand All @@ -53,7 +55,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def handleNotification(self, handle, data):
"""Handle Callback from a Bluetooth (GATT) request."""
_LOGGER.debug("Got notification from %s: %s", handle, codecs.encode(data, 'hex'))
_LOGGER.debug(
"Got notification from %s: %s", handle, codecs.encode(data, "hex")
)
if handle in self._callbacks:
self._callbacks[handle](data)

Expand All @@ -70,12 +74,18 @@ def make_request(self, handle, value, timeout=DEFAULT_TIMEOUT, with_response=Tru
"""Write a GATT Command without callback - not utf-8."""
try:
with self:
_LOGGER.debug("Writing %s to %s with with_response=%s", codecs.encode(value, 'hex'), handle, with_response)
self._conn.writeCharacteristic(handle, value, withResponse=with_response)
_LOGGER.debug(
"Writing %s to %s with with_response=%s",
codecs.encode(value, "hex"),
handle,
with_response,
)
self._conn.writeCharacteristic(
handle, value, withResponse=with_response
)
if timeout:
_LOGGER.debug("Waiting for notifications for %s", timeout)
self._conn.waitForNotifications(timeout)
except btle.BTLEException as ex:
_LOGGER.debug("Got exception from bluepy while making a request: %s", ex)
raise

Loading

0 comments on commit 4e19f27

Please sign in to comment.