1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

adding and removing a property

This commit is contained in:
Joel Bender 2017-09-26 00:20:17 -04:00
parent 5cd17080c0
commit 6be49d9b15
4 changed files with 74 additions and 0 deletions

View File

@ -600,6 +600,11 @@ def ArrayOf(klass):
# not found # not found
raise ValueError("%r not in array" % (value,)) raise ValueError("%r not in array" % (value,))
def remove(self, item):
# find the index of the item and delete it
indx = self.index(item)
self.__delitem__(indx)
def encode(self, taglist): def encode(self, taglist):
if _debug: ArrayOf._debug("(%r)encode %r", self.__class__.__name__, taglist) if _debug: ArrayOf._debug("(%r)encode %r", self.__class__.__name__, taglist)

View File

@ -598,6 +598,11 @@ def ArrayOf(klass):
# not found # not found
raise ValueError("%r not in array" % (value,)) raise ValueError("%r not in array" % (value,))
def remove(self, item):
# find the index of the item and delete it
indx = self.index(item)
self.__delitem__(indx)
def encode(self, taglist): def encode(self, taglist):
if _debug: ArrayOf._debug("(%r)encode %r", self.__class__.__name__, taglist) if _debug: ArrayOf._debug("(%r)encode %r", self.__class__.__name__, taglist)

View File

@ -598,6 +598,11 @@ def ArrayOf(klass):
# not found # not found
raise ValueError("%r not in array" % (value,)) raise ValueError("%r not in array" % (value,))
def remove(self, item):
# find the index of the item and delete it
indx = self.index(item)
self.__delitem__(indx)
def encode(self, taglist): def encode(self, taglist):
if _debug: ArrayOf._debug("(%r)encode %r", self.__class__.__name__, taglist) if _debug: ArrayOf._debug("(%r)encode %r", self.__class__.__name__, taglist)

View File

@ -0,0 +1,59 @@
from bacpypes.basetypes import PropertyIdentifier
from bacpypes.constructeddata import ArrayOf
from bacpypes.object import AnalogValueObject
# create an array of property identifiers datatype
ArrayOfPropertyIdentifier = ArrayOf(PropertyIdentifier)
aopi = ArrayOfPropertyIdentifier()
aopi.append('objectName')
aopi.append('objectType')
aopi.append('description')
aopi.debug_contents()
aopi.remove('objectType')
aopi.debug_contents()
print("Create an Analog Value Object")
av = AnalogValueObject(
objectName='av-sample',
objectIdentifier=('analogValue', 1),
description="sample",
)
av.debug_contents()
print("")
print("Change the description")
av.description = "something else"
av.debug_contents()
print("")
# get the description property by the attribute name
description_property = av._attr_to_property('description')
print("description_property = %r" % (description_property,))
print("")
print("Delete the property")
av.delete_property(description_property)
print("...property deleted")
try:
av.description = "this raises an exception"
except Exception as err:
print(repr(err))
av.debug_contents()
print("")
print("===== Add the property")
av.add_property(description_property)
print("...property added")
try:
av.description = "this works"
except Exception as err:
print(repr(err))
av.debug_contents()
print("")