mirror of
https://github.com/JoelBender/bacpypes
synced 2025-10-27 00:57:47 +08:00
merging #147 for next release
This commit is contained in:
@@ -1472,7 +1472,18 @@ class Reliability(Enumerated):
|
||||
, 'multiStateFault':9
|
||||
, 'configurationError':10
|
||||
, 'communicationFailure':12
|
||||
, 'numberFault':13
|
||||
, 'memberFault': 13
|
||||
, 'monitoredObjectFault': 14
|
||||
, 'tripped': 15
|
||||
, 'lampFailure': 16
|
||||
, 'activationFailure': 17
|
||||
, 'renewDHCPFailure': 18
|
||||
, 'renewFDRegistration-failure': 19
|
||||
, 'restartAutoNegotiationFailure': 20
|
||||
, 'restartFailure': 21
|
||||
, 'proprietaryCommandFailure': 22
|
||||
, 'faultsListed': 23
|
||||
, 'referencedObjectFault': 24
|
||||
}
|
||||
|
||||
class RestartReason(Enumerated):
|
||||
|
||||
@@ -565,7 +565,7 @@ def ArrayOf(klass):
|
||||
|
||||
def __setitem__(self, item, value):
|
||||
# no wrapping index
|
||||
if (item < 1) or (item > self.value[0]):
|
||||
if (item < 0) or (item > self.value[0]):
|
||||
raise IndexError("index out of range")
|
||||
|
||||
# special length handling for index 0
|
||||
@@ -575,7 +575,11 @@ def ArrayOf(klass):
|
||||
self.value = self.value[0:value + 1]
|
||||
elif value > self.value[0]:
|
||||
# extend
|
||||
self.value.extend( [None] * (value - self.value[0]) )
|
||||
if issubclass(self.subtype, Atomic):
|
||||
self.value.extend( [self.subtype().value] * (value - self.value[0]) )
|
||||
else:
|
||||
for i in range(value - self.value[0]):
|
||||
self.value.append(self.subtype())
|
||||
else:
|
||||
return
|
||||
self.value[0] = value
|
||||
|
||||
@@ -167,6 +167,7 @@ class Property(Logging):
|
||||
|
||||
# get the value
|
||||
value = obj._values[self.identifier]
|
||||
if _debug: Property._debug(" - value: %r", value)
|
||||
|
||||
# access an array
|
||||
if arrayIndex is not None:
|
||||
@@ -200,14 +201,61 @@ class Property(Logging):
|
||||
if not self.mutable:
|
||||
raise ExecutionError(errorClass='property', errorCode='writeAccessDenied')
|
||||
|
||||
# if changing the length of the array, the value is unsigned
|
||||
if arrayIndex == 0:
|
||||
if not Unsigned.is_valid(value):
|
||||
raise InvalidParameterDatatype("length of %s must be unsigned" % (
|
||||
self.identifier,
|
||||
))
|
||||
|
||||
# if it's atomic, make sure it's valid
|
||||
if issubclass(self.datatype, Atomic):
|
||||
elif issubclass(self.datatype, Atomic):
|
||||
if _debug: Property._debug(" - property is atomic, checking value")
|
||||
if not self.datatype.is_valid(value):
|
||||
raise InvalidParameterDatatype("%s must be of type %s" % (
|
||||
self.identifier, self.datatype.__name__,
|
||||
))
|
||||
|
||||
# if it's an array, make sure it's valid regarding arrayIndex provided
|
||||
elif issubclass(self.datatype, Array):
|
||||
if _debug: Property._debug(" - property is array, checking subtype and index")
|
||||
|
||||
# changing a single element
|
||||
if arrayIndex is not None:
|
||||
# if it's atomic, make sure it's valid
|
||||
if issubclass(self.datatype.subtype, Atomic):
|
||||
if _debug: Property._debug(" - subtype is atomic, checking value")
|
||||
if not self.datatype.subtype.is_valid(value):
|
||||
raise InvalidParameterDatatype("%s must be of type %s" % (
|
||||
self.identifier, self.datatype.__name__,
|
||||
))
|
||||
# constructed type
|
||||
elif not isinstance(value, self.datatype.subtype):
|
||||
raise InvalidParameterDatatype("%s must be of type %s" % (
|
||||
self.identifier, self.datatype.subtype.__name__
|
||||
))
|
||||
|
||||
# replacing the array
|
||||
elif isinstance(value, list):
|
||||
# check validity regarding subtype
|
||||
for item in value:
|
||||
# if it's atomic, make sure it's valid
|
||||
if issubclass(self.datatype.subtype, Atomic):
|
||||
if _debug: Property._debug(" - subtype is atomic, checking value")
|
||||
if not self.datatype.subtype.is_valid(item):
|
||||
raise InvalidParameterDatatype("elements of %s must be of type %s" % (
|
||||
self.identifier, self.datatype.subtype.__name__,
|
||||
))
|
||||
# constructed type
|
||||
elif not isinstance(item, self.datatype.subtype):
|
||||
raise InvalidParameterDatatype("elements of %s must be of type %s" % (
|
||||
self.identifier, self.datatype.subtype.__name__
|
||||
))
|
||||
|
||||
# value is mutated into a new array
|
||||
value = self.datatype(value)
|
||||
|
||||
# some kind of constructed data
|
||||
elif not isinstance(value, self.datatype):
|
||||
if _debug: Property._debug(" - property is not atomic and wrong type")
|
||||
raise InvalidParameterDatatype("%s must be of type %s" % (
|
||||
|
||||
Reference in New Issue
Block a user