Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
keep repeating discover_nodes until all registered nodes are online#279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
23088b2
keep repeating discover_nodes until all registered nodes are online
dirixmjm 6293c46
Revert rescheduling discovery for now
dirixmjm e8ddce9
reinstate a minimal discovery repeat for nodes which have poor connec…
dirixmjm 0581596
ruff format
dirixmjm 3bdb00b
Make sure a node loads from cache even if it is offline.
dirixmjm 9f2479e
fix coderabitai
dirixmjm 4571512
CodeRabitAI again
dirixmjm 1ffb28c
update similar to coderabbit suggestion
dirixmjm f196c99
address comments from @CoMPaTech
dirixmjm a6c87f1
cancel straggler tasks on stop()
dirixmjm c62b81e
SonarQubeCloud improvements
dirixmjm 6fec426
update CHANGELOG and version
dirixmjm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,3 +19,4 @@ fixtures/* | ||
| tmp | ||
| .cache | ||
| appdata_folder | ||
| mock_folder_that_exists/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,7 +12,12 @@ | ||
| from ..api import NodeEvent, NodeType, PlugwiseNode, StickEvent | ||
| from ..connection import StickController | ||
| from ..constants import ENERGY_NODE_TYPES, UTF8 | ||
| from ..constants import ( | ||
| ENERGY_NODE_TYPES, | ||
| NODE_RETRY_DISCOVER_INTERVAL, | ||
| NODE_RETRY_LOAD_INTERVAL, | ||
| UTF8, | ||
| ) | ||
| from ..exceptions import CacheError, MessageError, NodeError, StickError, StickTimeout | ||
| from ..helpers.util import validate_mac | ||
| from ..messages.requests import CircleMeasureIntervalRequest, NodePingRequest | ||
| @@ -72,6 +77,9 @@ | ||
| self._unsubscribe_node_rejoin: Callable[[], None] | None = None | ||
| self._discover_sed_tasks: dict[str, Task[bool]] = {} | ||
| self._registry_stragglers: dict[int, str] = {} | ||
| self._discover_stragglers_task: Task[None] | None = None | ||
| self._load_stragglers_task: Task[None] | None = None | ||
| # region - Properties | ||
| @@ -338,7 +346,7 @@ | ||
| # endregion | ||
| # region - Nodes | ||
| def _create_node_object( | ||
| async def _create_node_object( | ||
| self, | ||
| mac: str, | ||
| address: int, | ||
| @@ -363,7 +371,7 @@ | ||
| return | ||
| self._nodes[mac] = node | ||
| _LOGGER.debug("%s node %s added", node.__class__.__name__, mac) | ||
| self._register.update_network_registration(address, mac, node_type) | ||
| await self._register.update_network_registration(address, mac, node_type) | ||
| if self._cache_enabled: | ||
| _LOGGER.debug( | ||
| @@ -404,22 +412,24 @@ | ||
| Return True if discovery succeeded. | ||
| """ | ||
| _LOGGER.debug("Start discovery of node %s ", mac) | ||
| _LOGGER.debug( | ||
| "Start discovery of node %s with NodeType %s", mac, str(node_type) | ||
| ) | ||
| if self._nodes.get(mac) is not None: | ||
| _LOGGER.debug("Skip discovery of already known node %s ", mac) | ||
| return True | ||
| if node_type is not None: | ||
| self._create_node_object(mac, address, node_type) | ||
| await self._create_node_object(mac, address, node_type) | ||
| await self._notify_node_event_subscribers(NodeEvent.DISCOVERED, mac) | ||
| return True | ||
| # Node type is unknown, so we need to discover it first | ||
| _LOGGER.debug("Starting the discovery of node %s", mac) | ||
| _LOGGER.debug("Starting the discovery of node %s with unknown NodeType", mac) | ||
| node_info, node_ping = await self._controller.get_node_details(mac, ping_first) | ||
| if node_info is None: | ||
| return False | ||
| self._create_node_object(mac, address, node_info.node_type) | ||
| await self._create_node_object(mac, address, node_info.node_type) | ||
| # Forward received NodeInfoResponse message to node | ||
| await self._nodes[mac].message_for_node(node_info) | ||
| @@ -431,15 +441,39 @@ | ||
| async def _discover_registered_nodes(self) -> None: | ||
| """Discover nodes.""" | ||
| _LOGGER.debug("Start discovery of registered nodes") | ||
| counter = 0 | ||
| registered_counter = 0 | ||
| for address, registration in self._register.registry.items(): | ||
| mac, node_type = registration | ||
| if mac != "": | ||
| if self._nodes.get(mac) is None: | ||
| await self._discover_node(address, mac, node_type) | ||
| counter += 1 | ||
| if not await self._discover_node(address, mac, node_type): | ||
| self._registry_stragglers[address] = mac | ||
| registered_counter += 1 | ||
| await sleep(0) | ||
| _LOGGER.debug("Total %s registered node(s)", str(counter)) | ||
| if len(self._registry_stragglers) > 0 and ( | ||
| self._discover_stragglers_task is None | ||
| or self._discover_stragglers_task.done() | ||
| ): | ||
| self._discover_stragglers_task = create_task(self._discover_stragglers()) | ||
| _LOGGER.debug( | ||
| "Total %s online of %s registered node(s)", | ||
| str(len(self._nodes)), | ||
| str(registered_counter), | ||
| ) | ||
| async def _discover_stragglers(self) -> None: | ||
| """Repeat Discovery of Nodes with unknown NodeType.""" | ||
| while len(self._registry_stragglers) > 0: | ||
| await sleep(NODE_RETRY_DISCOVER_INTERVAL) | ||
| stragglers: dict[int, str] = {} | ||
| for address, mac in self._registry_stragglers.items(): | ||
| if not await self._discover_node(address, mac, None): | ||
| stragglers[address] = mac | ||
| self._registry_stragglers = stragglers | ||
| _LOGGER.debug( | ||
| "Total %s nodes unreachable having unknown NodeType", | ||
| str(len(stragglers)), | ||
| ) | ||
| async def _load_node(self, mac: str) -> bool: | ||
| """Load node.""" | ||
| @@ -452,6 +486,12 @@ | ||
| return True | ||
| return False | ||
| async def _load_stragglers(self) -> None: | ||
dirixmjm marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| """Retry failed load operation.""" | ||
| await sleep(NODE_RETRY_LOAD_INTERVAL) | ||
| while not self._load_discovered_nodes(): | ||
| await sleep(NODE_RETRY_LOAD_INTERVAL) | ||
| async def _load_discovered_nodes(self) -> bool: | ||
| """Load all nodes currently discovered.""" | ||
| _LOGGER.debug("_load_discovered_nodes | START | %s", len(self._nodes)) | ||
| @@ -499,10 +539,10 @@ | ||
| await self.discover_network_coordinator(load=load) | ||
| if not self._is_running: | ||
| await self.start() | ||
| await self._discover_registered_nodes() | ||
| if load: | ||
| return await self._load_discovered_nodes() | ||
| if load and not await self._load_discovered_nodes(): | ||
| self._load_stragglers_task = create_task(self._load_stragglers()) | ||
| return False | ||
| return True | ||
| @@ -512,10 +552,22 @@ | ||
| for task in self._discover_sed_tasks.values(): | ||
| if not task.done(): | ||
| task.cancel() | ||
| if ( | ||
| hasattr(self, "_load_stragglers_task") | ||
| and self._load_stragglers_task | ||
| and not self._load_stragglers_task.done() | ||
| ): | ||
| self._load_stragglers_task.cancel() | ||
| if ( | ||
| hasattr(self, "_discover_stragglers_task") | ||
| and self._discover_stragglers_task | ||
| and not self._discover_stragglers_task.done() | ||
| ): | ||
| self._discover_stragglers_task.cancel() | ||
| self._is_running = False | ||
| self._unsubscribe_to_protocol_events() | ||
| await self._unload_discovered_nodes() | ||
| await self._register.stop() | ||
| self._register.stop() | ||
| _LOGGER.debug("Stopping finished") | ||
| # endregion | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.