Skip to content

Commit 4e19f27

Browse files
authoredMar 3, 2022
Use poetry, add pre-commit hooks & mass format to modern standards, add CI (rytilahti#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
1 parent 9946ff4 commit 4e19f27

14 files changed

+378
-193
lines changed
 

‎.github/workflows/ci.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
pull_request:
7+
branches: ["master"]
8+
workflow_dispatch: # to allow manual re-runs
9+
10+
11+
jobs:
12+
linting:
13+
name: "Perform linting checks"
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
python-version: ["3.10"]
19+
20+
steps:
21+
- uses: "actions/checkout@v2"
22+
- uses: "actions/setup-python@v2"
23+
with:
24+
python-version: "${{ matrix.python-version }}"
25+
- name: "Install dependencies"
26+
run: |
27+
python -m pip install --upgrade pip poetry tox
28+
poetry install
29+
- name: "Run pre-commit -a"
30+
run: |
31+
poetry run pre-commit run -a
32+
33+
tests:
34+
name: "Python ${{ matrix.python-version}} on ${{ matrix.os }}"
35+
needs: linting
36+
runs-on: ${{ matrix.os }}
37+
38+
strategy:
39+
matrix:
40+
python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.7"]
41+
os: [ubuntu-latest]
42+
43+
steps:
44+
- uses: "actions/checkout@v2"
45+
- uses: "actions/setup-python@v2"
46+
with:
47+
python-version: "${{ matrix.python-version }}"
48+
- name: "Install dependencies"
49+
run: |
50+
python -m pip install --upgrade pip poetry
51+
poetry install
52+
- name: "Run tests"
53+
run: |
54+
poetry run pytest --cov eq3bt --cov-report xml

‎.pre-commit-config.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-docstring-first
8+
- id: check-yaml
9+
- id: debug-statements
10+
- id: check-ast
11+
12+
- repo: https://github.com/asottile/pyupgrade
13+
rev: v2.31.0
14+
hooks:
15+
- id: pyupgrade
16+
args: ['--py37-plus']
17+
18+
- repo: https://github.com/python/black
19+
rev: 22.1.0
20+
hooks:
21+
- id: black
22+
23+
- repo: https://gitlab.com/pycqa/flake8
24+
rev: 3.9.2
25+
hooks:
26+
- id: flake8
27+
28+
- repo: https://github.com/pre-commit/mirrors-isort
29+
rev: v5.10.1
30+
hooks:
31+
- id: isort
32+
additional_dependencies: [toml]
33+
34+
- repo: https://github.com/pre-commit/mirrors-mypy
35+
rev: v0.931
36+
hooks:
37+
- id: mypy

‎CHANGELOG

-2
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,3 @@ Changelog
205205
- Initial Commit Version 0.2.0. [Markus Peter]
206206

207207
- Initial commit. [Markus Peter]
208-
209-

‎__init__.py

Whitespace-only changes.

‎eq3bt/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# flake8: noqa
2-
from .eq3btsmart import Thermostat, TemperatureException, Mode
3-
from .structures import *
2+
from .eq3btsmart import Mode, TemperatureException, Thermostat
3+
from .structures import *

‎eq3bt/connection.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
A simple wrapper for bluepy's btle.Connection.
33
Handles Connection duties (reconnecting etc.) transparently.
44
"""
5-
import logging
65
import codecs
6+
import logging
77

88
from bluepy import btle
99

@@ -36,7 +36,9 @@ def __enter__(self):
3636
try:
3737
self._conn.connect(self._mac, iface=self._iface)
3838
except btle.BTLEException as ex:
39-
_LOGGER.debug("Unable to connect to the device %s, retrying: %s", self._mac, ex)
39+
_LOGGER.debug(
40+
"Unable to connect to the device %s, retrying: %s", self._mac, ex
41+
)
4042
try:
4143
self._conn.connect(self._mac, iface=self._iface)
4244
except Exception as ex2:
@@ -53,7 +55,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
5355

5456
def handleNotification(self, handle, data):
5557
"""Handle Callback from a Bluetooth (GATT) request."""
56-
_LOGGER.debug("Got notification from %s: %s", handle, codecs.encode(data, 'hex'))
58+
_LOGGER.debug(
59+
"Got notification from %s: %s", handle, codecs.encode(data, "hex")
60+
)
5761
if handle in self._callbacks:
5862
self._callbacks[handle](data)
5963

@@ -70,12 +74,18 @@ def make_request(self, handle, value, timeout=DEFAULT_TIMEOUT, with_response=Tru
7074
"""Write a GATT Command without callback - not utf-8."""
7175
try:
7276
with self:
73-
_LOGGER.debug("Writing %s to %s with with_response=%s", codecs.encode(value, 'hex'), handle, with_response)
74-
self._conn.writeCharacteristic(handle, value, withResponse=with_response)
77+
_LOGGER.debug(
78+
"Writing %s to %s with with_response=%s",
79+
codecs.encode(value, "hex"),
80+
handle,
81+
with_response,
82+
)
83+
self._conn.writeCharacteristic(
84+
handle, value, withResponse=with_response
85+
)
7586
if timeout:
7687
_LOGGER.debug("Waiting for notifications for %s", timeout)
7788
self._conn.waitForNotifications(timeout)
7889
except btle.BTLEException as ex:
7990
_LOGGER.debug("Got exception from bluepy while making a request: %s", ex)
8091
raise
81-

0 commit comments

Comments
 (0)
Please sign in to comment.