Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
22c2e992
Commit
22c2e992
authored
Jun 05, 2022
by
Alexander Schrode
Committed by
oroulet
Jun 05, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eventfilter: handle objects in eventtypes
parent
c3da1d88
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
15 deletions
+39
-15
asyncua/common/events.py
asyncua/common/events.py
+29
-15
tests/test_subscriptions.py
tests/test_subscriptions.py
+10
-0
No files found.
asyncua/common/events.py
View file @
22c2e992
import
copy
from
typing
import
Dict
,
List
,
TYPE_CHECKING
from
asyncua
import
ua
import
asyncua
from
..ua.uaerrors
import
UaError
from
.ua_utils
import
get_node_subtypes
if
TYPE_CHECKING
:
from
asyncua.common.node
import
Node
class
Event
:
...
...
@@ -142,10 +144,7 @@ async def get_filter_from_event_type(eventtypes):
return
evfilter
async
def
append_new_attribute_to_select_clauses
(
attribute
,
select_clauses
,
already_selected
,
parent_variable
):
browse_path
=
[]
if
parent_variable
:
browse_path
.
append
(
await
parent_variable
.
read_browse_name
())
async
def
_append_new_attribute_to_select_clauses
(
attribute
:
"Node"
,
select_clauses
:
List
[
ua
.
SimpleAttributeOperand
],
already_selected
:
Dict
[
str
,
str
],
browse_path
:
List
[
ua
.
QualifiedName
]):
browse_path
.
append
(
await
attribute
.
read_browse_name
())
string_path
=
'/'
.
join
(
map
(
str
,
browse_path
))
if
string_path
not
in
already_selected
:
...
...
@@ -153,23 +152,34 @@ async def append_new_attribute_to_select_clauses(attribute, select_clauses, alre
op
=
ua
.
SimpleAttributeOperand
()
op
.
AttributeId
=
ua
.
AttributeIds
.
Value
op
.
BrowsePath
=
browse_path
select_clauses
.
append
(
op
)
select_clauses
.
append
(
op
)
async
def
_select_clause_from_childs
(
child
:
"Node"
,
select_clauses
:
List
[
ua
.
SimpleAttributeOperand
],
already_selected
:
Dict
[
str
,
str
],
browse_path
:
List
[
ua
.
QualifiedName
]):
for
property
in
await
child
.
get_properties
():
await
_append_new_attribute_to_select_clauses
(
property
,
select_clauses
,
already_selected
,
[
*
browse_path
])
for
variable
in
await
child
.
get_variables
():
await
_append_new_attribute_to_select_clauses
(
variable
,
select_clauses
,
already_selected
,
[
*
browse_path
])
await
_select_clause_from_childs
(
variable
,
select_clauses
,
already_selected
,
browse_path
+
[
await
variable
.
read_browse_name
()])
for
object
in
await
child
.
get_children
(
refs
=
ua
.
ObjectIds
.
HasComponent
,
nodeclassmask
=
ua
.
NodeClass
.
Object
):
await
_select_clause_from_childs
(
object
,
select_clauses
,
already_selected
,
browse_path
+
[
await
object
.
read_browse_name
()])
async
def
select_clauses_from_evtype
(
evtypes
):
async
def
select_clauses_from_evtype
(
evtypes
:
List
[
"Node"
]
):
select_clauses
=
[]
already_selected
=
{}
for
evtype
in
evtypes
:
for
property
in
await
get_event_properties_from_type_node
(
evtype
):
await
append_new_attribute_to_select_clauses
(
property
,
select_clauses
,
already_selected
,
None
)
await
_append_new_attribute_to_select_clauses
(
property
,
select_clauses
,
already_selected
,
[]
)
for
variable
in
await
get_event_variables_from_type_node
(
evtype
):
await
append_new_attribute_to_select_clauses
(
variable
,
select_clauses
,
already_selected
,
None
)
for
subproperty
in
await
variable
.
get_properties
():
await
append_new_attribute_to_select_clauses
(
subproperty
,
select_clauses
,
already_selected
,
variable
)
await
_append_new_attribute_to_select_clauses
(
variable
,
select_clauses
,
already_selected
,
[])
await
_select_clause_from_childs
(
variable
,
select_clauses
,
already_selected
,
[
await
variable
.
read_browse_name
()])
for
object
in
await
get_event_objects_from_type_node
(
evtype
):
await
_select_clause_from_childs
(
object
,
select_clauses
,
already_selected
,
[
await
object
.
read_browse_name
()])
return
select_clauses
async
def
where_clause_from_evtype
(
evtypes
):
async
def
where_clause_from_evtype
(
evtypes
:
List
[
"Node"
]
):
cf
=
ua
.
ContentFilter
()
el
=
ua
.
ContentFilterElement
()
# operands can be ElementOperand, LiteralOperand, AttributeOperand, SimpleAttribute
...
...
@@ -197,7 +207,7 @@ async def where_clause_from_evtype(evtypes):
return
cf
async
def
select_event_attributes_from_type_node
(
node
,
attributeSelector
):
async
def
select_event_attributes_from_type_node
(
node
:
"Node"
,
attributeSelector
):
attributes
=
[]
curr_node
=
node
while
True
:
...
...
@@ -213,14 +223,18 @@ async def select_event_attributes_from_type_node(node, attributeSelector):
return
attributes
async
def
get_event_properties_from_type_node
(
node
)
:
async
def
get_event_properties_from_type_node
(
node
:
"Node"
)
->
List
[
ua
.
NodeId
]
:
return
await
select_event_attributes_from_type_node
(
node
,
lambda
n
:
n
.
get_properties
())
async
def
get_event_variables_from_type_node
(
node
)
:
async
def
get_event_variables_from_type_node
(
node
:
"Node"
)
->
List
[
ua
.
NodeId
]
:
return
await
select_event_attributes_from_type_node
(
node
,
lambda
n
:
n
.
get_variables
())
async
def
get_event_objects_from_type_node
(
node
:
"Node"
)
->
List
[
ua
.
NodeId
]:
return
await
select_event_attributes_from_type_node
(
node
,
lambda
n
:
n
.
get_children
(
refs
=
ua
.
ObjectIds
.
HasComponent
,
nodeclassmask
=
ua
.
NodeClass
.
Object
))
async
def
get_event_obj_from_type_node
(
node
):
"""
return an Event object from an event type node
...
...
tests/test_subscriptions.py
View file @
22c2e992
...
...
@@ -545,6 +545,16 @@ async def test_get_filter_from_ConditionType(opc):
assert
systemType
.
nodeid
in
operandNodeIds
async
def
test_get_event_contains_object
(
opc
):
""" Shelving State is a object this should be in the filter list!"""
alarm_type
=
opc
.
opc
.
get_node
(
ua
.
ObjectIds
.
AlarmConditionType
)
evfilter
=
await
asyncua
.
common
.
events
.
get_filter_from_event_type
([
alarm_type
])
browsePathList
=
[
o
.
BrowsePath
for
o
in
evfilter
.
SelectClauses
if
o
.
BrowsePath
]
[
print
(
b
)
for
b
in
browsePathList
]
browsePathId
=
[
ua
.
QualifiedName
(
'ShelvingState'
),
ua
.
QualifiedName
(
'CurrentState'
),
ua
.
QualifiedName
(
'Id'
)]
assert
browsePathId
in
browsePathList
async
def
test_get_event_from_type_node_CustomEvent
(
opc
):
etype
=
await
opc
.
server
.
create_custom_event_type
(
2
,
'MyEvent'
,
ua
.
ObjectIds
.
AuditEventType
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment