Skip to content
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

Add browse_nodes to SyncClient #1412

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions asyncua/client/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import logging
import socket
from typing import List, Union, Coroutine, Optional, Type
from typing import List, Tuple, Union, Coroutine, Optional, Type
from urllib.parse import urlparse, unquote
from pathlib import Path

Expand Down Expand Up @@ -894,7 +894,7 @@ async def write_values(self, nodes, values, raise_on_partial_error=True):
get_values = read_values # legacy compatibility
set_values = write_values # legacy compatibility

async def browse_nodes(self, nodes):
async def browse_nodes(self, nodes: List[Node]) -> List[Tuple[Node, ua.BrowseResult]]:
"""
Browses multiple nodes in one ua call
returns a List of Tuples(Node, BrowseResult)
Expand Down
11 changes: 6 additions & 5 deletions asyncua/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ def _to_async(args, kwargs):
def _to_sync(tloop, result):
if isinstance(result, node.Node):
return SyncNode(tloop, result)
if isinstance(result, (list, tuple)) and len(result) > 0:
if isinstance(result[0], node.Node):
return [SyncNode(tloop, i) for i in result]
elif isinstance(result[0], (list, tuple)):
return [_to_sync(tloop, item) for item in result]
if isinstance(result, (list, tuple)):
return [_to_sync(tloop, item) for item in result]
if isinstance(result, server.event_generator.EventGenerator):
return EventGenerator(tloop, result)
if isinstance(result, subscription.Subscription):
Expand Down Expand Up @@ -315,6 +312,10 @@ def read_values(self, nodes):
def write_values(self, nodes, values, raise_on_partial_error=True):
pass

@syncmethod
def browse_nodes(self, nodes: List["SyncNode"]) -> List[Tuple["SyncNode", ua.BrowseResult]]: # type: ignore[empty-body]
pass

@syncmethod
def translate_browsepaths( # type: ignore[empty-body]
self,
Expand Down
16 changes: 16 additions & 0 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ def test_sync_client_get_node(client, idx):
assert vars[0].read_value() == 6.7


def test_sync_client_browse_nodes(client: Client, idx):
nodes = [
client.get_node("ns=0;i=2267"),
client.get_node("ns=0;i=2259"),
]
results = client.browse_nodes(nodes)
assert len(results) == 2
assert isinstance(results, list)
assert results[0][0] == nodes[0]
assert results[1][0] == nodes[1]
assert isinstance(results[0][0], SyncNode)
assert isinstance(results[1][0], SyncNode)
assert isinstance(results[0][1], ua.BrowseResult)
assert isinstance(results[1][1], ua.BrowseResult)


def test_sync_server_get_node(server, idx):
node = server.get_node(85)
assert node == server.nodes.objects
Expand Down
Loading