Skip to content

Commit 809d5d8

Browse files
CoMPaTechbouwew
authored andcommitted
pylint improvements
1 parent d91f6d5 commit 809d5d8

File tree

12 files changed

+101
-58
lines changed

12 files changed

+101
-58
lines changed

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
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+
]
316
- repo: https://github.com/pre-commit/pre-commit-hooks
417
rev: v4.1.0
518
hooks:

plugwise/connections/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def _reader_deamon(self):
5858
time.sleep(0.01)
5959
_LOGGER.debug("Reader daemon stopped")
6060

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

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: 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: 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: 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: 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: snakestyle name
139+
# pylint: disable=invalid-name
139140
def Configure_SED(
140141
self,
141142
stay_active=SED_STAY_ACTIVE,

plugwise/smile.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
"""Use of this source code is governed by the MIT license found in the LICENSE file.
22
Plugwise backend module for Home Assistant Core.
33
"""
4-
import asyncio
5-
import copy
64
import logging
75

86
import aiohttp
97

10-
from defusedxml import ElementTree as etree
11-
128
# Dict as class
139
from munch import Munch
1410

@@ -74,11 +70,11 @@ def _all_device_data(self):
7470
self._append_special(data, dev_id, temp_bs_dict, temp_s_dict)
7571

7672
dev_and_data.update(data)
77-
if temp_bs_dict != {}:
73+
if temp_bs_dict:
7874
dev_and_data["binary_sensors"] = temp_bs_dict
79-
if temp_s_dict != {}:
75+
if temp_s_dict:
8076
dev_and_data["sensors"] = temp_s_dict
81-
if temp_sw_dict != {}:
77+
if temp_sw_dict:
8278
dev_and_data["switches"] = temp_sw_dict
8379

8480
self.gw_devices[dev_id] = dev_and_data
@@ -468,7 +464,7 @@ async def async_update(self):
468464
data = self._get_device_data(dev_id)
469465
for key, value in list(data.items()):
470466
if key in dev_dict:
471-
self.gw_devices[dev_id][key] = value
467+
dev_dict[key] = value
472468
if "binary_sensors" in dev_dict:
473469
for key, value in list(data.items()):
474470
update_helper(
@@ -531,7 +527,7 @@ async def set_schedule_state(self, loc_id, name, state):
531527
return await self._set_schedule_state_legacy(name, state)
532528

533529
schema_rule = self._rule_ids_by_name(str(name), loc_id)
534-
if schema_rule == {} or schema_rule is None:
530+
if not schema_rule or schema_rule is None:
535531
return False
536532

537533
schema_rule_id = next(iter(schema_rule))

plugwise/stick.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -610,21 +610,21 @@ def _update_loop(self):
610610
if datetime.now().day != day_of_month:
611611
day_of_month = datetime.now().day
612612
_sync_clock = True
613-
for mac in self._device_nodes:
614-
if self._device_nodes[mac]:
615-
if self._device_nodes[mac].battery_powered:
613+
for mac, device in self._device_nodes.items():
614+
if device:
615+
if device.battery_powered:
616616
# Check availability state of SED's
617617
self._check_availability_of_seds(mac)
618618
else:
619619
# Do ping request for all non SED's
620-
self._device_nodes[mac].do_ping()
620+
device.do_ping()
621621

622-
if self._device_nodes[mac].measures_power:
622+
if device.measures_power:
623623
# Request current power usage
624-
self._device_nodes[mac].request_power_update()
624+
device.request_power_update()
625625
# Sync internal clock of power measure nodes once a day
626626
if _sync_clock:
627-
self._device_nodes[mac].sync_clock()
627+
device.sync_clock()
628628
_sync_clock = False
629629

630630
# Do a single ping for undiscovered nodes once per 10 update cycles
@@ -669,8 +669,8 @@ def auto_update(self, timer=None):
669669
# Timer based on a minimum of 5 seconds + 1 second for each node supporting power measurement
670670
if not self._auto_update_manually:
671671
count_nodes = 0
672-
for mac in self._device_nodes:
673-
if self._device_nodes[mac].measures_power:
672+
for _, node in self._device_nodes.items():
673+
if node.measures_power:
674674
count_nodes += 1
675675
self._auto_update_timer = 5 + (count_nodes * 1)
676676
_LOGGER.info(
@@ -680,7 +680,7 @@ def auto_update(self, timer=None):
680680
if not self._run_update_thread:
681681
self._update_thread.start()
682682

683-
### Helper functions ###
683+
# Helper functions
684684
def do_callback(self, callback_type, callback_arg=None):
685685
"""Helper to execute registered callbacks for specified callback type."""
686686
if callback_type in self._stick_callbacks:

0 commit comments

Comments
 (0)