Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raise ValueError("unknown object type")
obj_inst = int(args[i])
i += 1
prop_reference_list = []
while i < len(args):
prop_id = args[i]
if prop_id not in PropertyIdentifier.enumerations:
break
i += 1
if prop_id in ('all', 'required', 'optional'):
pass
else:
datatype = get_datatype(obj_type, prop_id)
if not datatype:
raise ValueError(
"invalid property for object type : %s | %s" %
(obj_type, prop_id))
# build a property reference
prop_reference = PropertyReference(
propertyIdentifier=prop_id,
)
# check for an array index
if (i < len(args)) and args[i].isdigit():
prop_reference.propertyArrayIndex = int(args[i])
i += 1
# add it to the list
obj_inst = int(obj_inst)
value = args[4]
indx = None
if len(args) >= 6:
if args[5] != "-":
indx = int(args[5])
if _debug: TestConsoleCmd._debug(" - indx: %r", indx)
priority = None
if len(args) >= 7:
priority = int(args[6])
if _debug: TestConsoleCmd._debug(" - priority: %r", priority)
# get the datatype
datatype = get_datatype(obj_type, prop_id)
if _debug: TestConsoleCmd._debug(" - datatype: %r", datatype)
# change atomic values into something encodeable, null is a special case
if (value == 'null'):
value = Null()
elif issubclass(datatype, Atomic):
if datatype is Integer:
value = int(value)
elif datatype is Real:
value = float(value)
elif datatype is Unsigned:
value = int(value)
value = datatype(value)
elif issubclass(datatype, Array) and (indx is not None):
if indx == 0:
value = Integer(value)
read_access_spec_list = []
while i < len(args):
obj_id = ObjectIdentifier(args[i]).value
i += 1
prop_reference_list = []
while i < len(args):
prop_id = args[i]
if prop_id not in PropertyIdentifier.enumerations:
break
i += 1
if prop_id in ('all', 'required', 'optional'):
pass
else:
datatype = get_datatype(obj_id[0], prop_id)
if not datatype:
raise ValueError("invalid property for object type")
# build a property reference
prop_reference = PropertyReference(
propertyIdentifier=prop_id,
)
# check for an array index
if (i < len(args)) and args[i].isdigit():
prop_reference.propertyArrayIndex = int(args[i])
i += 1
# add it to the list
prop_reference_list.append(prop_reference)
present_value_type = get_datatype(object_type, 'presentValue')
# The object name translates into the point name of the object.
key = '{}-{}'.format(index, "objectName")
query_map[key] = [object_type, index, "objectName"]
key = '{}-{}'.format(index, 'description')
query_map[key] = [object_type, index, "description"]
if issubclass(present_value_type, Enumerated):
key = '{}-{}'.format(index, "relinquishDefault")
query_map[key] = [object_type, index, "relinquishDefault"]
elif issubclass(present_value_type, Boolean):
pass
elif get_datatype(object_type, 'units') is None:
key = '{}-{}'.format(index, 'numberOfStates')
query_map[key] = [object_type, index, "numberOfStates"]
key = '{}-{}'.format(index, 'stateText')
query_map[key] = [object_type, index, "stateText"]
if object_type != 'multiSTateInput':
key = '{}-{}'.format(index, "relinquishDefault")
query_map[key] = [object_type, index, "relinquishDefault"]
elif object_type == 'loop':
pass
else:
pass
else:
key = '{}-{}'.format(index, 'units')
query_map[key] = [object_type, index, "units"]
# optional array index
if indx is not None:
request.propertyArrayIndex = indx
# optional priority
if priority is not None:
request.priority = priority
self.log_subtitle("Creating Request")
self._log.debug(
"{:<20} {:<20} {:<20} {:<20}".format(
"indx", "priority", "datatype", "value"
)
)
datatype = get_datatype(obj_type, prop_id, vendor_id=vendor_id)
self._log.debug(
"{!r:<20} {!r:<20} {!r:<20} {!r:<20}".format(
indx, priority, datatype, value
)
)
self._log.debug("{:<20} {}".format("REQUEST", request))
return request
context = None
if obj_type == "device":
context = dict(address=address, device=index)
writable = 'FALSE'
subondinate_list_property = get_datatype(obj_type, 'subordinateList')
if subondinate_list_property is not None:
_log.debug('Processing StructuredViewObject')
# self._process_device_object_reference(address, obj_type, index,
# 'subordinateList',
# max_range_report,
# config_writer)
return
subondinate_list_property = get_datatype(obj_type, 'zoneMembers')
if subondinate_list_property is not None:
_log.debug('Processing LifeSafetyZoneObject')
# self._process_device_object_reference(address, obj_type, index,
# 'zoneMembers',
# max_range_report,
# config_writer)
return
present_value_type = get_datatype(obj_type, 'presentValue')
if present_value_type is None:
_log.debug('This object type has no presentValue. Skipping.')
return
if not issubclass(present_value_type, (Enumerated,
Unsigned,
Boolean,
PropertyValue(
propertyIdentifier=prop_id,
propertyArrayIndex=indx,
value=value,
priority=priority,
)
)
was.append(
WriteAccessSpecification(
objectIdentifier=(obj_type, obj_inst),
listOfProperties=property_values,
)
)
datatype = get_datatype(obj_type, prop_id, vendor_id=vendor_id)
self._log.debug(
"{!r:<20} {!r:<20} {!r:<20} {!r:<20}".format(
indx, priority, datatype, value
)
)
# build a request
request = WritePropertyMultipleRequest(listOfWriteAccessSpecs=was)
request.pduDestination = Address(addr)
self._log.debug("{:<20} {}".format("REQUEST", request))
return request
obj_id = ObjectIdentifier(obj_id).value # make a bacpypes obj id
addr = self.__get_device()
prop_id = self.__get_prop()
# write
value = float(_value)
self.logger.debug(f"write: {config_obj_id} {_value} for port \'{obj.get('name')}\' {str(obj_id)} {prop_id} {value}")
request = WritePropertyRequest(
objectIdentifier=obj_id,
propertyIdentifier=prop_id
)
request.pduDestination = Address(addr)
# the value to write
datatype = get_datatype(obj_id[0], prop_id)
value = datatype(value)
request.propertyValue = Any()
try:
request.propertyValue.cast_in(value)
except Exception as err:
self.logger.critical(f"write: {err}")
iocb = IOCB(request)
self.app.request_io(iocb)
self.logger.debug("write: waiting for response...")
loopCount = 0
while loopCount < 20 and not iocb.ioResponse:
loopCount += 1
run_once()
asyncore.loop(timeout=0.2, count=1)
time.sleep(0.2)
iocb.ioDefered.errback(RuntimeError("no matching request"))
return
del self.iocb[invoke_key]
if isinstance(apdu, AbortPDU):
iocb.ioDefered.errback(RuntimeError("Device communication aborted: " + str(apdu)))
return
if isinstance(apdu, Error):
iocb.ioDefered.errback(RuntimeError("Error during device communication: " + str(apdu)))
return
elif (isinstance(iocb.ioRequest, ReadPropertyRequest) and
isinstance(apdu, ReadPropertyACK)):
# find the datatype
datatype = get_datatype(apdu.objectIdentifier[0], apdu.propertyIdentifier)
if not datatype:
iocb.ioDefered.errback(TypeError("unknown datatype"))
return
# special case for array parts, others are managed by cast_out
if issubclass(datatype, Array) and (apdu.propertyArrayIndex is not None):
if apdu.propertyArrayIndex == 0:
value = apdu.propertyValue.cast_out(Unsigned)
else:
value = apdu.propertyValue.cast_out(datatype.subtype)
else:
value = apdu.propertyValue.cast_out(datatype)
if issubclass(datatype, Enumerated):
value = datatype(value).get_long()
iocb.ioDefered.callback(value)
_log.debug('emit_responses: objects: {}'.format(objects))
for index, obj in objects.items():
object_type = obj['object_type']
present_value_type = get_datatype(object_type, 'presentValue')
object_units_details = ''
object_units = ''
object_notes = ''
if issubclass(present_value_type, Boolean):
object_units = 'Boolean'
elif issubclass(present_value_type, Enumerated):
object_units, object_units_details, object_notes = \
self._process_enumerated(object_type, obj)
elif get_datatype(object_type, 'units') is None:
object_units, object_units_details, object_notes = \
self._process_units(object_type, obj)
else:
object_units, object_units_details, object_notes = \
self._process_unknown(object_type, obj)
results = {}
results['Reference Point Name'] = results[
'Volttron Point Name'] = obj['object_name']
results['Units'] = object_units
results['Unit Details'] = object_units_details
results['BACnet Object Type'] = object_type
results['Property'] = 'presentValue'
results['Writable'] = 'FALSE'
results['Index'] = obj['index']
results['Notes'] = object_notes