Skip to content

Commit fe1ba5a

Browse files
authored
Merge pull request #128 from plugwise/anna42lint
QA: Improve code - reintroduce flake/lint
2 parents 7fe4264 + eb6b472 commit fe1ba5a

File tree

14 files changed

+113
-93
lines changed

14 files changed

+113
-93
lines changed

.github/workflows/verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name: Latest commit
55

66
env:
7-
CACHE_VERSION: 1
7+
CACHE_VERSION: 3
88
DEFAULT_PYTHON: "3.9"
99
PRE_COMMIT_HOME: ~/.cache/pre-commit
1010

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
build.sh
22
.DS_Store
33
*.pyc
4+
.*.swp
45
__pycache__
56
/dist/
67
/*.egg-info

.pre-commit-config.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
repos:
22
# Run manually in CI skipping the branch checks
3+
- repo: https://github.com/PyCQA/pylint
4+
rev: v2.12.2
5+
hooks:
6+
- id: pylint
7+
name: pylint
8+
entry: pylint
9+
language: system
10+
types: [python]
11+
args:
12+
[
13+
"-rn", # Only display messages
14+
"-sn", # Don't display the score
15+
]
16+
- repo: https://github.com/PyCQA/isort
17+
rev: 5.10.1
18+
hooks:
19+
- id: isort
320
- repo: https://github.com/pre-commit/pre-commit-hooks
421
rev: v4.1.0
522
hooks:
@@ -75,7 +92,3 @@ repos:
7592
types: [python]
7693
require_serial: true
7794
files: ^plugwise/.+\.py$
78-
# - repo: https://github.com/PyCQA/isort
79-
# rev: 5.10.1
80-
# hooks:
81-
# - id: isort

plugwise/connections/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, port, parser):
2727
self._writer_thread = None
2828

2929
################################################
30-
### Open connection ###
30+
# Open connection #
3131
################################################
3232

3333
def connect(self) -> bool:
@@ -40,7 +40,7 @@ def _open_connection(self):
4040
"""Placeholder."""
4141

4242
################################################
43-
### Reader ###
43+
# Reader #
4444
################################################
4545

4646
def _reader_start(self, name):
@@ -58,12 +58,14 @@ def _reader_deamon(self):
5858
time.sleep(0.01)
5959
_LOGGER.debug("Reader daemon stopped")
6060

61+
# TODO: 20220125 function instead of self
62+
# pylint: disable=no-self-use
6163
def _read_data(self):
6264
"""placeholder."""
6365
return b"0000"
6466

6567
################################################
66-
### Writer ###
68+
# Writer #
6769
################################################
6870

6971
def _writer_start(self, name: str):
@@ -101,7 +103,7 @@ def send(self, message: NodeRequest, callback=None):
101103
self._write_queue.put_nowait((message, callback))
102104

103105
################################################
104-
### Connection state ###
106+
# Connection state #
105107
################################################
106108

107109
def is_connected(self):
@@ -117,7 +119,7 @@ def write_thread_alive(self):
117119
return self._writer_thread.is_alive() if self.run_writer_thread else False
118120

119121
################################################
120-
### Close connection ###
122+
# Close connection #
121123
################################################
122124

123125
def disconnect(self):

plugwise/controller.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,7 @@ def message_handler(self, message):
280280
else:
281281
self._log_status_message(message)
282282
self.message_processor(message)
283-
if (
284-
message.seq_id != b"FFFF"
285-
and message.seq_id != b"FFFE"
286-
and message.seq_id != b"FFFD"
287-
):
283+
if message.seq_id not in [b"FFFF", b"FFFE", b"FFFD"]:
288284
self._post_message_action(
289285
message.seq_id, None, message.__class__.__name__
290286
)

plugwise/helper.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts)
99
from aiohttp import BasicAuth, ClientSession, ClientTimeout, ServerTimeoutError
10-
from dateutil import tz
1110
from dateutil.parser import parse
1211
from defusedxml import ElementTree as etree
1312
from munch import Munch
@@ -17,24 +16,16 @@
1716

1817
from .constants import (
1918
APPLIANCES,
20-
ATTR_ICON,
21-
ATTR_ID,
2219
ATTR_NAME,
23-
ATTR_STATE,
2420
ATTR_TYPE,
2521
ATTR_UNIT_OF_MEASUREMENT,
2622
BINARY_SENSORS,
27-
COOLING_ICON,
2823
DEVICE_MEASUREMENTS,
29-
DOMAIN_OBJECTS,
3024
ENERGY_KILO_WATT_HOUR,
3125
ENERGY_WATT_HOUR,
3226
FAKE_LOC,
33-
FLAME_ICON,
3427
HEATER_CENTRAL_MEASUREMENTS,
35-
HEATING_ICON,
3628
HOME_MEASUREMENTS,
37-
IDLE_ICON,
3829
LOCATIONS,
3930
POWER_WATT,
4031
SENSORS,
@@ -49,7 +40,6 @@
4940
ResponseError,
5041
)
5142
from .util import (
52-
determine_selected,
5343
escape_illegal_xml_characters,
5444
format_measure,
5545
in_between,
@@ -165,9 +155,9 @@ def schemas_schedule_temp(schedules, name):
165155
for i in range(length):
166156
result_1 = schema_list[i][0]
167157
start = schema_list[i][1]
168-
n = (i + 1) % (length - 1)
169-
result_2 = schema_list[n][0]
170-
end = schema_list[n][1]
158+
j = (i + 1) % (length - 1)
159+
result_2 = schema_list[j][0]
160+
end = schema_list[j][1]
171161
now = dt.datetime.now().time()
172162
if (
173163
result_1 == dt.datetime.now().weekday()
@@ -326,6 +316,39 @@ async def close_connection(self):
326316
class SmileHelper:
327317
"""The SmileHelper class."""
328318

319+
def __init__(self):
320+
"""Set the constructor for this class."""
321+
self._appl_data = None
322+
self._appliances = None
323+
self._cooling_present = None
324+
self._cp_state = None
325+
self._devices = None
326+
self._domain_objects = None
327+
self._heater_id = None
328+
self._home_location = None
329+
self._last_active = {}
330+
self._loc_data = None
331+
self._locations = None
332+
self._modules = None
333+
self._on_off_device = None
334+
self._ot_device = None
335+
self._outdoor_temp = None
336+
self._sm_thermostat = None
337+
self._thermo_locs = None
338+
339+
self._smile_legacy = None
340+
self._stretch_v2 = None
341+
self._stretch_v3 = None
342+
343+
self.cooling_active = None
344+
self.gateway_id = None
345+
self.gw_data = {}
346+
self.gw_devices = {}
347+
348+
self.smile_name = None
349+
self.smile_type = None
350+
self.smile_version = []
351+
329352
def _locations_legacy(self):
330353
"""Helper-function for _all_locations().
331354
Create locations for legacy devices.
@@ -420,7 +443,8 @@ def _get_module_data(self, appliance, locator, mod_type):
420443
if appl_search is not None:
421444
link_id = appl_search.attrib["id"]
422445
locator = f".//{mod_type}[@id='{link_id}']...."
423-
if (module := self._modules.find(locator)) is not None:
446+
module = self._modules.find(locator)
447+
if module is not None:
424448
v_name = module.find("vendor_name").text
425449
v_model = module.find("vendor_model").text
426450
hw_version = module.find("hardware_version").text

plugwise/messages/responses.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def deserialize(self, response):
6666
self.msg_id = response[4:8]
6767
self.seq_id = response[8:12]
6868
response = response[12:]
69-
if self.format_size == MESSAGE_SMALL or self.format_size == MESSAGE_LARGE:
69+
if self.format_size in [MESSAGE_SMALL, MESSAGE_LARGE]:
7070
self.ack_id = response[:4]
7171
response = response[4:]
7272
if self.format_size != MESSAGE_SMALL:
@@ -337,6 +337,8 @@ def __init__(self):
337337
self.datetime = DateTime()
338338
self.last_logaddr = LogAddr(0, length=8)
339339
self.relay_state = Int(0, length=2)
340+
# TODO: 20220126 snake-style
341+
# pylint: disable=invalid-name
340342
self.hz = Int(0, length=2)
341343
self.hw_ver = String(None, length=12)
342344
self.fw_ver = UnixTimestamp(0)

plugwise/nodes/circle.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,9 @@ def _response_energy_counters(self, message: CircleEnergyCountersResponse):
685685
self._energy_last_populated_slot = _slot
686686

687687
# Store most recent timestamp of collected pulses
688-
if self._energy_last_collected_timestamp < _log_timestamp:
689-
self._energy_last_collected_timestamp = _log_timestamp
688+
self._energy_last_collected_timestamp = max(
689+
self._energy_last_collected_timestamp, _log_timestamp
690+
)
690691

691692
# Trigger history rollover
692693
if (
@@ -746,11 +747,11 @@ def _response_energy_counters(self, message: CircleEnergyCountersResponse):
746747
)
747748
self._update_energy_today_now(False, _history_rollover, _midnight_rollover)
748749
else:
749-
_LOGGER.info(
750-
"_response_energy_counters for %s | self._energy_history_collecting running",
751-
self.mac,
752-
str(_local_midnight_timestamp),
750+
logstring = (
751+
"_response_energy_counters for %s | self._energy_history_collecting running %s"
752+
% (self.mac, str(_local_midnight_timestamp))
753753
)
754+
_LOGGER.info(logstring)
754755

755756
# Cleanup energy history for more than 8 day's ago
756757
_8_days_ago = datetime.utcnow().replace(

plugwise/nodes/scan.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ def _process_switch_group(self, message):
9797
self.mac,
9898
)
9999

100+
# TODO: 20220125 snakestyle name
101+
# pylint: disable=invalid-name
100102
def CalibrateLight(self, callback=None):
101103
"""Queue request to calibration light sensitivity"""
102104
self._queue_request(ScanLightCalibrateRequest(self._mac), callback)
103105

106+
# TODO: 20220125 snakestyle name
107+
# pylint: disable=invalid-name
104108
def Configure_scan(
105109
self,
106110
motion_reset_timer=SCAN_MOTION_RESET_TIMER,
@@ -126,6 +130,8 @@ def Configure_scan(
126130
callback,
127131
)
128132

133+
# TODO: 20220125 snakestyle name
134+
# pylint: disable=invalid-name
129135
def SetMotionAction(self, callback=None):
130136
"""Queue Configure Scan to signal motion"""
131137
# TODO:

plugwise/nodes/sed.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@ def _process_awake_response(self, message):
7575
str(message.awake_type.value),
7676
self.mac,
7777
)
78-
if (
79-
message.awake_type.value == SED_AWAKE_MAINTENANCE
80-
or message.awake_type.value == SED_AWAKE_FIRST
81-
or message.awake_type.value == SED_AWAKE_STARTUP
82-
or message.awake_type.value == SED_AWAKE_BUTTON
83-
):
84-
for request in self._sed_requests:
85-
(request_message, callback) = self._sed_requests[request]
78+
if message.awake_type.value in [
79+
SED_AWAKE_MAINTENANCE,
80+
SED_AWAKE_FIRST,
81+
SED_AWAKE_STARTUP,
82+
SED_AWAKE_BUTTON,
83+
]:
84+
for request_message, callback in self._sed_requests.items():
8685
_LOGGER.info(
8786
"Send queued %s message to SED node %s",
8887
request_message.__class__.__name__,
@@ -136,6 +135,8 @@ def _wake_up_interval_accepted(self):
136135
"""Callback after wake up interval is received and accepted by SED."""
137136
self._wake_up_interval = self._new_maintenance_interval
138137

138+
# TODO: 20220125 snakestyle name
139+
# pylint: disable=invalid-name
139140
def Configure_SED(
140141
self,
141142
stay_active=SED_STAY_ACTIVE,

0 commit comments

Comments
 (0)