Skip to content

Commit de55ec3

Browse files
authored
Merge pull request #30 from plugwise/lint_flake2
Linter run on top of qualtiy-branch
2 parents d48252c + fa2a9df commit de55ec3

33 files changed

+172
-268
lines changed

.bandit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[bandit]
2+
skips: B106

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
source = plugwise
33
omit=
44
*/venv/*
5+
setup.py
56
plugwise/connections/*
67
plugwise/message.py
78
plugwise/messages/*

.github/workflows/verify.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ jobs:
7777
uses: actions/setup-python@v2
7878
with:
7979
python-version: ${{ env.DEFAULT_PYTHON }}
80+
- name: Pre-black
81+
uses: psf/black@stable
8082
- name: Restore base Python ${{ env.DEFAULT_PYTHON }} virtual environment
8183
id: cache-venv
8284
uses: actions/cache@v2

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.8.2 - Code quality improvements
4+
- Switch Smile to defusedxml from lxml (improving security)
5+
- Lint and flake recommendations fixed
6+
- Project CI changes
7+
38
## 0.8.1 - Standardize logging for stick
49

510
## 0.8.0 - Merged Smile/USB module

plugwise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Plugwise module."""
22

3-
__version__ = "0.8.2a0"
3+
__version__ = "0.8.2a1"
44

55
from plugwise.smile import Smile
66
from plugwise.stick import stick

plugwise/connections/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Plugwise connections."""

plugwise/connections/connection.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
"""
2-
Use of this source code is governed by the MIT license found in the LICENSE file.
3-
4-
Base for serial or socket connections
5-
"""
1+
"""Base for serial or socket connections."""
62
import logging
73
import queue
84
import threading
@@ -15,41 +11,46 @@
1511

1612

1713
class StickConnection:
18-
""" Generic Plugwise stick connection"""
14+
"""Generic Plugwise stick connection."""
1915

2016
def __init__(self, port, stick=None):
17+
"""Initialize StickConnection."""
2118
self.port = port
2219
self.stick = stick
2320
self.run_reader_thread = False
2421
self.run_writer_thread = False
2522
self._is_connected = False
2623
self._writer = None
2724

25+
self._reader_thread = None
26+
self._write_queue = None
27+
self._writer_thread = None
28+
2829
################################################
2930
### Open connection ###
3031
################################################
3132

3233
def connect(self):
33-
"""Open the connection"""
34+
"""Open the connection."""
3435
if not self._is_connected:
3536
self._open_connection()
3637

3738
def _open_connection(self):
38-
"""Placeholder to initialize the connection"""
39+
"""Placeholder to initialize the connection."""
3940
raise NotImplementedError
4041

4142
################################################
4243
### Reader ###
4344
################################################
4445

4546
def _reader_start(self, name):
46-
"""Start the reader thread to receive data"""
47-
self._reader_thread = threading.Thread(None, self._reader_daemon, name, (), {})
47+
"""Start the reader thread to receive data."""
48+
self._reader_thread = threading.Thread(None, self._reader_deamon, name, (), {})
4849
self.run_reader_thread = True
4950
self._reader_thread.start()
5051

51-
def _reader_daemon(self):
52-
"""Thread to collect available data from connection"""
52+
def _reader_deamon(self):
53+
"""Thread to collect available data from connection."""
5354
while self.run_reader_thread:
5455
data = self._read_data()
5556
if data:
@@ -58,15 +59,15 @@ def _reader_daemon(self):
5859
_LOGGER.debug("Reader daemon stopped")
5960

6061
def _read_data(self):
61-
"""Placeholder to receive message from the connection"""
62+
"""Placeholder to receive message from the connection."""
6263
raise NotImplementedError
6364

6465
################################################
6566
### Writer ###
6667
################################################
6768

6869
def _writer_start(self, name: str):
69-
"""Start the writer thread to send data"""
70+
"""Start the writer thread to send data."""
7071
self._write_queue = queue.Queue()
7172
self._writer_thread = threading.Thread(None, self._writer_daemon, name, (), {})
7273
self._writer_thread.daemon = True
@@ -105,23 +106,23 @@ def send(self, message: PlugwiseMessage, callback=None):
105106
################################################
106107

107108
def is_connected(self):
108-
"""Return connection state"""
109+
"""Return connection state."""
109110
return self._is_connected
110111

111112
def read_thread_alive(self):
112-
"""Return state of write thread"""
113+
"""Return state of write thread."""
113114
return self._reader_thread.isAlive() if self.run_reader_thread else False
114115

115116
def write_thread_alive(self):
116-
"""Return state of write thread"""
117+
"""Return state of write thread."""
117118
return self._writer_thread.isAlive() if self.run_writer_thread else False
118119

119120
################################################
120121
### Close connection ###
121122
################################################
122123

123124
def disconnect(self):
124-
"""Close the connection"""
125+
"""Close the connection."""
125126
if self._is_connected:
126127
self._is_connected = False
127128
self.run_writer_thread = False
@@ -133,5 +134,5 @@ def disconnect(self):
133134
self._close_connection()
134135

135136
def _close_connection(self):
136-
"""Placeholder to close the port"""
137+
"""Placeholder to close the port."""
137138
raise NotImplementedError

plugwise/connections/serial.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
"""
2-
Use of this source code is governed by the MIT license found in the LICENSE file.
3-
4-
Serial connection
5-
"""
1+
"""Serial connection."""
62
import logging
73

84
import serial
@@ -11,13 +7,11 @@
117
from plugwise.constants import BAUD_RATE, BYTE_SIZE, STOPBITS
128
from plugwise.exceptions import PortError
139

14-
# from plugwise.message import PlugwiseMessage
15-
1610
_LOGGER = logging.getLogger(__name__)
1711

1812

1913
class PlugwiseUSBConnection(StickConnection):
20-
"""simple wrapper around serial module"""
14+
"""Simple wrapper around serial module."""
2115

2216
def __init__(self, port, stick=None):
2317
super().__init__(port, stick)
@@ -26,8 +20,10 @@ def __init__(self, port, stick=None):
2620
self._stopbits = STOPBITS
2721
self._parity = serial.PARITY_NONE
2822

23+
self._serial = None
24+
2925
def _open_connection(self):
30-
"""Open serial port"""
26+
"""Open serial port."""
3127
_LOGGER.debug("Open serial port %s", self.port)
3228
try:
3329
self._serial = serial.Serial(
@@ -83,7 +79,7 @@ def _read_data(self):
8379
return None
8480

8581
def _write_data(self, data):
86-
"""Write data to serial port"""
82+
"""Write data to serial port."""
8783
try:
8884
self._serial.write(data)
8985
except serial.serialutil.SerialException as err:

plugwise/connections/socket.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
"""
2-
Use of this source code is governed by the MIT license found in the LICENSE file.
3-
4-
Socket connection
5-
"""
1+
"""Socket connection."""
62
import logging
73
import socket
84

95
from plugwise.connections.connection import StickConnection
10-
from plugwise.constants import SLEEP_TIME
116
from plugwise.exceptions import PortError
12-
from plugwise.message import PlugwiseMessage
137

148
_LOGGER = logging.getLogger(__name__)
159

1610

1711
class SocketConnection(StickConnection):
18-
"""
19-
Wrapper for Socket connection configuration
20-
"""
12+
"""Wrapper for Socket connection configuration."""
2113

2214
def __init__(self, port, stick=None):
2315
super().__init__(port, stick)
@@ -27,8 +19,10 @@ def __init__(self, port, stick=None):
2719
self._socket_port = int(port_split[1])
2820
self._socket_address = (self._socket_host, self._socket_port)
2921

22+
self._socket = None
23+
3024
def _open_connection(self):
31-
"""Open socket"""
25+
"""Open socket."""
3226
_LOGGER.debug(
3327
"Open socket to host '%s' at port %s",
3428
self._socket_host,
@@ -87,7 +81,7 @@ def _read_data(self):
8781
return None
8882

8983
def _write_data(self, data):
90-
"""Write data to socket"""
84+
"""Write data to socket."""
9185
try:
9286
self._socket.send(data)
9387
except Exception as err:

plugwise/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Copyright (C) 2011 Sven Petai <[email protected]>, use of this source code is governed by the MIT license found in the LICENSE file."""
1+
"""Plugwise Exceptions."""
22

33

44
class PlugwiseException(Exception):

0 commit comments

Comments
 (0)