Skip to content

Commit

Permalink
only create new node if there is none yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Hoch committed Apr 29, 2024
1 parent 3c085ae commit 4545fd5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pyvlx/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .api import GetAllNodesInformation, GetNodeInformation
from .exception import PyVLXException
from .log import PYVLXLOG
from .node import Node
from .node_helper import convert_frame_to_node

Expand Down Expand Up @@ -82,9 +83,16 @@ async def _load_node(self, node_id: int) -> None:
notification_frame = get_node_information.notification_frame
if notification_frame is None:
return
node = convert_frame_to_node(self.pyvlx, notification_frame)
if node is not None:
self.add(node)
node: Node | None = None
for n in self.__nodes:
if n.node_id == node_id:
node = n
PYVLXLOG.debug("Loaded node %s from existing nodes", n.node_id)
if node is None:
node = convert_frame_to_node(self.pyvlx, notification_frame)
if node is not None:
PYVLXLOG.debug("Created new node %s", node.node_id)
self.add(node)

async def _load_all_nodes(self) -> None:
"""Load all nodes via API."""
Expand Down

0 comments on commit 4545fd5

Please sign in to comment.