mirror of
https://github.com/JoelBender/bacpypes
synced 2025-10-27 00:57:47 +08:00
sync the python versions
This commit is contained in:
@@ -723,6 +723,7 @@ class IOQController(IOController):
|
||||
|
||||
# if there was an error, abort the request
|
||||
if err:
|
||||
if _debug: IOQController._debug(" - aborting")
|
||||
self.abort_io(iocb, err)
|
||||
|
||||
def process_io(self, iocb):
|
||||
@@ -767,7 +768,7 @@ class IOQController(IOController):
|
||||
|
||||
# schedule a call in the future
|
||||
task = FunctionTask(IOQController._wait_trigger, self)
|
||||
task.install_task(delay=self.wait_time)
|
||||
task.install_task(delta=self.wait_time)
|
||||
|
||||
else:
|
||||
# change our state
|
||||
|
||||
@@ -437,13 +437,6 @@ class Object(Logging):
|
||||
# empty list of property monitors
|
||||
self._property_monitors = defaultdict(list)
|
||||
|
||||
# start with a clean array of property identifiers
|
||||
if 'propertyList' in initargs:
|
||||
propertyList = None
|
||||
else:
|
||||
propertyList = ArrayOf(PropertyIdentifier)()
|
||||
initargs['propertyList'] = propertyList
|
||||
|
||||
# initialize the object
|
||||
for propid, prop in self._properties.items():
|
||||
if propid in initargs:
|
||||
@@ -452,20 +445,12 @@ class Object(Logging):
|
||||
# defer to the property object for error checking
|
||||
prop.WriteProperty(self, initargs[propid], direct=True)
|
||||
|
||||
# add it to the property list if we are building one
|
||||
if propertyList is not None:
|
||||
propertyList.append(propid)
|
||||
|
||||
elif prop.default is not None:
|
||||
if _debug: Object._debug(" - setting %s from default", propid)
|
||||
|
||||
# default values bypass property interface
|
||||
self._values[propid] = prop.default
|
||||
|
||||
# add it to the property list if we are building one
|
||||
if propertyList is not None:
|
||||
propertyList.append(propid)
|
||||
|
||||
else:
|
||||
if not prop.optional:
|
||||
if _debug: Object._debug(" - %s value required", propid)
|
||||
@@ -526,13 +511,6 @@ class Object(Logging):
|
||||
self._properties[prop.identifier] = prop
|
||||
self._values[prop.identifier] = prop.default
|
||||
|
||||
# tell the object it has a new property
|
||||
if 'propertyList' in self._values:
|
||||
property_list = self.propertyList
|
||||
if prop.identifier not in property_list:
|
||||
if _debug: Object._debug(" - adding to property list")
|
||||
property_list.append(prop.identifier)
|
||||
|
||||
def delete_property(self, prop):
|
||||
"""Delete a property from an object. The property is an instance of
|
||||
a Property or one of its derived classes, but only the property
|
||||
@@ -548,13 +526,6 @@ class Object(Logging):
|
||||
if prop.identifier in self._values:
|
||||
del self._values[prop.identifier]
|
||||
|
||||
# remove the property identifier from its list of know properties
|
||||
if 'propertyList' in self._values:
|
||||
property_list = self.propertyList
|
||||
if prop.identifier in property_list:
|
||||
if _debug: Object._debug(" - removing from property list")
|
||||
property_list.remove(prop.identifier)
|
||||
|
||||
def ReadProperty(self, propid, arrayIndex=None):
|
||||
if _debug: Object._debug("ReadProperty %r arrayIndex=%r", propid, arrayIndex)
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ from ..object import register_object_type, registered_object_types, \
|
||||
Property, DeviceObject
|
||||
from ..task import FunctionTask
|
||||
|
||||
from .object import CurrentPropertyListMixIn
|
||||
|
||||
# some debugging
|
||||
_debug = 0
|
||||
_log = ModuleLogger(globals())
|
||||
@@ -66,7 +68,7 @@ class CurrentTimeProperty(Property):
|
||||
# LocalDeviceObject
|
||||
#
|
||||
|
||||
class LocalDeviceObject(DeviceObject):
|
||||
class LocalDeviceObject(CurrentPropertyListMixIn, DeviceObject):
|
||||
|
||||
properties = \
|
||||
[ CurrentTimeProperty('localTime')
|
||||
@@ -107,6 +109,18 @@ class LocalDeviceObject(DeviceObject):
|
||||
if 'localTime' in kwargs:
|
||||
raise RuntimeError("localTime is provided by LocalDeviceObject and cannot be overridden")
|
||||
|
||||
# the object identifier is required for the object list
|
||||
if 'objectIdentifier' not in kwargs:
|
||||
raise RuntimeError("objectIdentifier is required")
|
||||
|
||||
# the object list is provided
|
||||
if 'objectList' in kwargs:
|
||||
raise RuntimeError("objectList is provided by LocalDeviceObject and cannot be overridden")
|
||||
else:
|
||||
kwargs['objectList'] = ArrayOf(ObjectIdentifier)([
|
||||
kwargs['objectIdentifier'],
|
||||
])
|
||||
|
||||
# check for a minimum value
|
||||
if kwargs['maxApduLengthAccepted'] < 50:
|
||||
raise ValueError("invalid max APDU length accepted")
|
||||
@@ -115,20 +129,7 @@ class LocalDeviceObject(DeviceObject):
|
||||
if _debug: LocalDeviceObject._debug(" - updated kwargs: %r", kwargs)
|
||||
|
||||
# proceed as usual
|
||||
DeviceObject.__init__(self, **kwargs)
|
||||
|
||||
# create a default implementation of an object list for local devices.
|
||||
# If it is specified in the kwargs, that overrides this default.
|
||||
if ('objectList' not in kwargs):
|
||||
self.objectList = ArrayOf(ObjectIdentifier)([self.objectIdentifier])
|
||||
|
||||
# if the object has a property list and one wasn't provided
|
||||
# in the kwargs, then it was created by default and the objectList
|
||||
# property should be included
|
||||
if ('propertyList' not in kwargs) and self.propertyList:
|
||||
# make sure it's not already there
|
||||
if 'objectList' not in self.propertyList:
|
||||
self.propertyList.append('objectList')
|
||||
super(LocalDeviceObject, self).__init__(**kwargs)
|
||||
|
||||
bacpypes_debugging(LocalDeviceObject)
|
||||
|
||||
|
||||
@@ -3,20 +3,74 @@
|
||||
from ..debugging import bacpypes_debugging, ModuleLogger
|
||||
from ..capability import Capability
|
||||
|
||||
from ..basetypes import ErrorType
|
||||
from ..basetypes import ErrorType, PropertyIdentifier
|
||||
from ..primitivedata import Atomic, Null, Unsigned
|
||||
from ..constructeddata import Any, Array
|
||||
from ..constructeddata import Any, Array, ArrayOf
|
||||
|
||||
from ..apdu import Error, \
|
||||
SimpleAckPDU, ReadPropertyACK, ReadPropertyMultipleACK, \
|
||||
ReadAccessResult, ReadAccessResultElement, ReadAccessResultElementChoice
|
||||
from ..errors import ExecutionError
|
||||
from ..object import PropertyError
|
||||
from ..object import Property, Object, PropertyError
|
||||
|
||||
# some debugging
|
||||
_debug = 0
|
||||
_log = ModuleLogger(globals())
|
||||
|
||||
# handy reference
|
||||
ArrayOfPropertyIdentifier = ArrayOf(PropertyIdentifier)
|
||||
|
||||
#
|
||||
# CurrentPropertyList
|
||||
#
|
||||
|
||||
@bacpypes_debugging
|
||||
class CurrentPropertyList(Property):
|
||||
|
||||
def __init__(self):
|
||||
if _debug: CurrentPropertyList._debug("__init__")
|
||||
Property.__init__(self, 'propertyList', ArrayOfPropertyIdentifier, default=None, optional=True, mutable=False)
|
||||
|
||||
def ReadProperty(self, obj, arrayIndex=None):
|
||||
if _debug: CurrentPropertyList._debug("ReadProperty %r %r", obj, arrayIndex)
|
||||
|
||||
# make a list of the properties that have values
|
||||
property_list = [k for k, v in obj._values.items()
|
||||
if v is not None
|
||||
and k not in ('objectName', 'objectType', 'objectIdentifier', 'propertyList')
|
||||
]
|
||||
if _debug: CurrentPropertyList._debug(" - property_list: %r", property_list)
|
||||
|
||||
# sort the list so it's stable
|
||||
property_list.sort()
|
||||
|
||||
# asking for the whole thing
|
||||
if arrayIndex is None:
|
||||
return ArrayOfPropertyIdentifier(property_list)
|
||||
|
||||
# asking for the length
|
||||
if arrayIndex == 0:
|
||||
return len(property_list)
|
||||
|
||||
# asking for an index
|
||||
if arrayIndex > len(property_list):
|
||||
raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex')
|
||||
return property_list[arrayIndex - 1]
|
||||
|
||||
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False):
|
||||
raise ExecutionError(errorClass='property', errorCode='writeAccessDenied')
|
||||
|
||||
#
|
||||
# CurrentPropertyListMixIn
|
||||
#
|
||||
|
||||
@bacpypes_debugging
|
||||
class CurrentPropertyListMixIn(Object):
|
||||
|
||||
properties = [
|
||||
CurrentPropertyList(),
|
||||
]
|
||||
|
||||
#
|
||||
# ReadProperty and WriteProperty Services
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user