Skip to content

Commit 6015873

Browse files
committed
Some code cleanup and formatting
1 parent 96f612d commit 6015873

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

plugwise/stick.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
ACCEPT_JOIN_REQUESTS,
1414
CB_JOIN_REQUEST,
1515
CB_NEW_NODE,
16-
MESSAGE_RETRY,
1716
MESSAGE_TIME_OUT,
1817
NODE_TYPE_CELSIUS_NR,
1918
NODE_TYPE_CELSIUS_SED,
@@ -249,9 +248,7 @@ def scan_circle_plus(self):
249248
"""Scan the Circle+ memory for registered nodes."""
250249
if self._device_nodes.get(self.circle_plus_mac):
251250
_LOGGER.debug("Scan Circle+ for linked nodes...")
252-
self._device_nodes[self.circle_plus_mac].scan_for_nodes(
253-
self.discover_nodes
254-
)
251+
self._device_nodes[self.circle_plus_mac].scan_for_nodes(self.discover_nodes)
255252
else:
256253
_LOGGER.error("Circle+ is not discovered yet")
257254

@@ -276,9 +273,7 @@ def discover_nodes(self, nodes_to_discover):
276273
self._joined_nodes = len(nodes_to_discover)
277274

278275
# setup timeout for node discovery
279-
discover_timeout = (
280-
10 + (len(nodes_to_discover) * 2) + (MESSAGE_TIME_OUT * MESSAGE_RETRY)
281-
)
276+
discover_timeout = 10 + (len(nodes_to_discover) * 2) + (MESSAGE_TIME_OUT)
282277
threading.Timer(discover_timeout, self.scan_timeout_expired).start()
283278
_LOGGER.debug("Start discovery of linked node types...")
284279
for mac in nodes_to_discover:
@@ -303,7 +298,7 @@ def node_discovered_by_scan(self, nodes_off_line=False):
303298
self._nodes_not_discovered = {}
304299
else:
305300
for mac in self._nodes_to_discover:
306-
if mac not in self._device_nodes.keys():
301+
if not self._device_nodes.get(mac):
307302
_LOGGER.info(
308303
"Failed to discover node type for registered MAC '%s'. This is expected for battery powered nodes, they will be discovered at their first awake",
309304
str(mac),
@@ -375,7 +370,7 @@ def _append_node(self, mac, address, node_type):
375370

376371
def node_state_updates(self, mac, state: bool):
377372
"""Update availability state of a node"""
378-
if mac in self._device_nodes:
373+
if self._device_nodes.get(mac):
379374
if not self._device_nodes[mac].battery_powered:
380375
self._device_nodes[mac].available = state
381376

@@ -405,7 +400,7 @@ def node_unjoin(self, mac: str, callback=None) -> bool:
405400

406401
def _remove_node(self, mac):
407402
"""Remove node from list of controllable nodes."""
408-
if mac in self._device_nodes:
403+
if self._device_nodes.get(mac):
409404
del self._device_nodes[mac]
410405
else:
411406
_LOGGER.warning("Node %s does not exists, unable to remove node.", mac)
@@ -479,7 +474,12 @@ def _process_node_join_request(self, node_join_request, mac):
479474
Process NodeJoinAvailableResponse message from a node that
480475
is not part of a plugwise network yet and wants to join
481476
"""
482-
if not self._device_nodes.get(mac):
477+
if self._device_nodes.get(mac):
478+
_LOGGER.debug(
479+
"Received node available message for node %s which is already joined.",
480+
mac,
481+
)
482+
else:
483483
if self._accept_join_requests:
484484
# Send accept join request
485485
_LOGGER.info(
@@ -494,11 +494,6 @@ def _process_node_join_request(self, node_join_request, mac):
494494
mac,
495495
)
496496
self.do_callback(CB_JOIN_REQUEST, mac)
497-
else:
498-
_LOGGER.debug(
499-
"Received node available message for node %s which is already joined.",
500-
mac,
501-
)
502497

503498
def _process_node_remove(self, node_remove_response):
504499
"""
@@ -712,9 +707,7 @@ def _check_availability_of_seds(self, mac):
712707
if self._device_nodes[mac].available:
713708
if self._device_nodes[mac].last_update < (
714709
datetime.now()
715-
- timedelta(
716-
minutes=(self._device_nodes[mac].maintenance_interval + 1)
717-
)
710+
- timedelta(minutes=(self._device_nodes[mac].maintenance_interval + 1))
718711
):
719712
_LOGGER.info(
720713
"No messages received within (%s minutes) of expected maintenance interval from node %s, mark as unavailable [%s > %s]",

0 commit comments

Comments
 (0)