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
bc4e04fb
Commit
bc4e04fb
authored
Jan 06, 2022
by
ratara
Committed by
oroulet
Jan 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added type hinting
parent
f21019a2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
asyncua/server/address_space.py
asyncua/server/address_space.py
+12
-12
No files found.
asyncua/server/address_space.py
View file @
bc4e04fb
...
...
@@ -14,7 +14,7 @@ from asyncua.ua.attribute_ids import AttributeIds
from
asyncua.ua.uaprotocol_auto
import
Index
if
TYPE_CHECKING
:
from
typing
import
Callable
,
Dict
,
List
,
Union
from
typing
import
Callable
,
Dict
,
List
,
Union
,
Tuple
from
asyncua.ua.uatypes
import
NodeId
,
DataValue
,
VariantType
from
asyncua.ua.uaprotocol_auto
import
(
AddNodesItem
,
BrowsePath
,
BrowseParameters
,
RelativePathElement
,
BrowseResult
,
...
...
@@ -45,7 +45,7 @@ class AttributeValue(object):
"""
def
__init__
(
self
,
value
:
DataValue
):
self
.
value
=
value
self
.
value_callback
:
Union
[
Callable
[[],
Non
e
],
None
]
=
None
self
.
value_callback
:
Union
[
Callable
[[],
ua
.
DataValu
e
],
None
]
=
None
self
.
datachange_callbacks
=
{}
def
__str__
(
self
)
->
str
:
...
...
@@ -434,7 +434,7 @@ class NodeManagementService:
"Error calling delete node callback callback %s, %s, %s"
,
nodedata
,
ua
.
AttributeIds
.
Value
,
ex
)
def
add_references
(
self
,
refs
:
AddReferencesItem
,
user
:
User
=
User
(
role
=
UserRole
.
Admin
)):
def
add_references
(
self
,
refs
:
AddReferencesItem
,
user
:
User
=
User
(
role
=
UserRole
.
Admin
)):
# FIXME return type
result
=
[]
for
ref
in
refs
:
result
.
append
(
self
.
_add_reference
(
ref
,
user
))
...
...
@@ -620,7 +620,7 @@ class AddressSpace:
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
_nodes
:
Dict
[
NodeId
,
NodeData
]
=
{}
self
.
_datachange_callback_counter
=
200
self
.
_handle_to_attribute_map
=
{}
self
.
_handle_to_attribute_map
:
Dict
[
int
,
Tuple
[
NodeId
,
AttributeIds
]]
=
{}
self
.
_default_idx
=
2
self
.
_nodeid_counter
=
{
0
:
20000
,
1
:
2000
}
...
...
@@ -762,7 +762,7 @@ class AddressSpace:
self
.
_nodes
=
LazyLoadingDict
(
shelve
.
open
(
path
,
"r"
))
def
read_attribute_value
(
self
,
nodeid
,
attr
)
:
def
read_attribute_value
(
self
,
nodeid
:
NodeId
,
attr
:
AttributeIds
)
->
ua
.
DataValue
:
# self.logger.debug("get attr val: %s %s", nodeid, attr)
if
nodeid
not
in
self
.
_nodes
:
dv
=
ua
.
DataValue
(
StatusCode_
=
ua
.
StatusCode
(
ua
.
StatusCodes
.
BadNodeIdUnknown
))
...
...
@@ -776,7 +776,7 @@ class AddressSpace:
return
attval
.
value_callback
()
return
attval
.
value
async
def
write_attribute_value
(
self
,
nodeid
,
attr
,
v
alue
)
->
ua
.
StatusCode
:
async
def
write_attribute_value
(
self
,
nodeid
:
NodeId
,
attr
:
AttributeIds
,
value
:
DataV
alue
)
->
ua
.
StatusCode
:
# self.logger.debug("set attr val: %s %s %s", nodeid, attr, value)
node
=
self
.
_nodes
.
get
(
nodeid
,
None
)
if
node
is
None
:
...
...
@@ -803,8 +803,8 @@ class AddressSpace:
return
ua
.
StatusCode
()
def
_is_expected_variant_type
(
self
,
value
,
attval
,
node
)
:
vtype
=
attval
.
value
.
Value
.
VariantType
def
_is_expected_variant_type
(
self
,
value
:
DataValue
,
attval
:
AttributeValue
,
node
:
NodeData
)
->
bool
:
vtype
=
attval
.
value
.
Value
.
VariantType
# FIXME Type hinting reveals that it is possible that Value (Optional) is None which would raise an exception
if
vtype
==
ua
.
VariantType
.
Null
:
# Node had a null value, many nodes are initialized with that value
# we should check what the real type is
...
...
@@ -821,8 +821,8 @@ class AddressSpace:
value
.
Value
,
value
.
Value
.
VariantType
,
attval
.
value
.
Value
.
VariantType
)
return
False
def
add_datachange_callback
(
self
,
nodeid
,
attr
,
callback
)
:
self
.
logger
.
debug
(
"set attr callback: %s %s %s"
,
nodeid
,
attr
,
callback
)
def
add_datachange_callback
(
self
,
nodeid
:
NodeId
,
attr
:
AttributeIds
,
callback
:
Callable
)
->
Tuple
[
ua
.
StatusCode
,
int
]
:
#
self.logger.debug("set attr callback: %s %s %s", nodeid, attr, callback)
if
nodeid
not
in
self
.
_nodes
:
return
ua
.
StatusCode
(
ua
.
StatusCodes
.
BadNodeIdUnknown
),
0
node
=
self
.
_nodes
[
nodeid
]
...
...
@@ -835,11 +835,11 @@ class AddressSpace:
self
.
_handle_to_attribute_map
[
handle
]
=
(
nodeid
,
attr
)
return
ua
.
StatusCode
(),
handle
def
delete_datachange_callback
(
self
,
handle
):
def
delete_datachange_callback
(
self
,
handle
:
int
):
if
handle
in
self
.
_handle_to_attribute_map
:
nodeid
,
attr
=
self
.
_handle_to_attribute_map
.
pop
(
handle
)
self
.
_nodes
[
nodeid
].
attributes
[
attr
].
datachange_callbacks
.
pop
(
handle
)
def
add_method_callback
(
self
,
methodid
,
callback
):
def
add_method_callback
(
self
,
methodid
:
NodeId
,
callback
:
Callable
):
node
=
self
.
_nodes
[
methodid
]
node
.
call
=
callback
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