Skip to content

Commit 150d695

Browse files
committed
Rewrite auto_update()
1 parent 09bae00 commit 150d695

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

plugwise/stick.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __init__(self, port, callback=None, print_progress=False):
127127
self._run_send_message_thread = False
128128
self._run_update_thread = False
129129

130-
self._auto_update_timer = None
130+
self._auto_update_timer = 0
131131
self._nodes_discovered = None
132132
self._receive_timeout_thread = None
133133
self._run_watchdog = None
@@ -1532,18 +1532,14 @@ def _update_loop(self): # noqa: C901
15321532
_LOGGER.debug("Update loop stopped")
15331533

15341534
def auto_update(self, timer=None):
1535-
"""
1536-
setup auto update polling for power usage.
1537-
"""
1538-
if timer == 0:
1539-
self._run_update_thread = False
1535+
""" Configure auto update polling daemon for power usage and availability state. """
1536+
if timer:
1537+
self._auto_update_timer = timer
1538+
elif timer == 0:
15401539
self._auto_update_timer = 0
1540+
self._run_update_thread = False
15411541
else:
1542-
self._auto_update_timer = 5
1543-
if timer is None:
1544-
# Timer based on number of nodes and 3 seconds per node
1545-
self._auto_update_timer = len(self._plugwise_nodes) * 3
1546-
elif timer > 5:
1547-
self._auto_update_timer = timer
1548-
if not self._run_update_thread:
1549-
self._update_thread.start()
1542+
# Timer based on number of nodes and 3 seconds per node
1543+
self._auto_update_timer = len(self._plugwise_nodes) * 3
1544+
if not self._run_update_thread:
1545+
self._update_thread.start()

0 commit comments

Comments
 (0)