Skip to content

Commit 05c86e3

Browse files
committed
Change update timer on number of active nodes
1 parent c6899e1 commit 05c86e3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

plugwise/stick.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def __init__(self, port, callback=None):
8686
self._stick_callbacks = {}
8787
self._run_update_thread = False
8888
self._auto_update_timer = 0
89+
self._auto_update_manually = False
8990
self._nodes_discovered = None
9091
self._run_watchdog = None
9192
self._update_thread = None
@@ -682,8 +683,17 @@ def auto_update(self, timer=None):
682683
self._auto_update_timer = 0
683684
self._run_update_thread = False
684685
else:
685-
# Timer based on number of nodes and 3 seconds per node
686-
self._auto_update_timer = len(self._plugwise_nodes) * 3
686+
# Timer based on a minium of 5 seconds + 1 second for each node supporting power measurement
687+
if not self._auto_update_manually:
688+
count_nodes = 0
689+
for mac in self.discovered_nodes:
690+
if self._plugwise_nodes[mac].measures_power:
691+
count_nodes += 1
692+
self._auto_update_timer = 5 + (count_nodes * 1)
693+
_LOGGER.info(
694+
"Update interval is (re)set to %s seconds",
695+
str(self._auto_update_timer),
696+
)
687697
if not self._run_update_thread:
688698
self._update_thread.start()
689699

@@ -733,6 +743,7 @@ def _discover_after_scan(self):
733743
if node_discovered:
734744
del self._nodes_not_discovered[node_discovered]
735745
self.do_callback(CB_NEW_NODE, node_discovered)
746+
self.auto_update()
736747

737748
def discover_node(self, mac: str, callback=None, force_discover=False) -> bool:
738749
"""Helper to try to discovery the node (type) based on mac."""

0 commit comments

Comments
 (0)