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:
parent
5cd17080c0
commit
6be49d9b15
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
59
sandbox/add_remove_property.py
Normal file
59
sandbox/add_remove_property.py
Normal 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("")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user