Esempio n. 1
0
 def add_point(self, point: BACnetPointModel, _update_point_store=True):
     [priority_array,
      present_value] = default_values(point.priority_array_write,
                                      point.relinquish_default)
     if point.use_next_available_address:
         point.address = BACnetPointModel.get_next_available_address(
             point.address)
     object_identifier = create_object_identifier(point.object_type.name,
                                                  point.address)
     if point.object_type.name == "analogOutput":
         register_object_type(AnalogOutputCmdObject)
         p = AnalogOutputFeedbackObject(
             profileName=point.uuid,
             objectIdentifier=(point.object_type.name, point.address),
             objectName=point.object_name,
             relinquishDefault=point.relinquish_default,
             presentValue=present_value,
             priorityArray=priority_array,
             eventState=point.event_state.name,
             statusFlags=StatusFlags(),
             units=EngineeringUnits(point.units.name),
             description=point.description,
             outOfService=False,
         )
         self.__bacnet.add_object(p)
         self.__registry[object_identifier] = p
     elif point.object_type.name == "analogValue":
         register_object_type(AnalogValueCmdObject)
         p = AnalogValueFeedbackObject(
             profileName=point.uuid,
             objectIdentifier=(point.object_type.name, point.address),
             objectName=point.object_name,
             relinquishDefault=point.relinquish_default,
             presentValue=present_value,
             priorityArray=priority_array,
             eventState=point.event_state.name,
             statusFlags=StatusFlags(),
             units=EngineeringUnits(point.units.name),
             description=point.description,
             outOfService=False,
         )
         self.__bacnet.add_object(p)
         self.__registry[object_identifier] = p
     if _update_point_store:  # make it so on start of app not to update the point store
         update_point_store(point.uuid, present_value)
     setting: AppSetting = current_app.config[AppSetting.FLASK_KEY]
     if setting.mqtt.enabled:
         priority = get_highest_priority_field(point.priority_array_write)
         mqtt_client = MqttClient()
         mqtt_client.publish_value(
             ('ao', object_identifier, point.object_name), present_value,
             priority)
Esempio n. 2
0
 def check_feedback(self, old_value, new_value):
     priority_array = self._dict_contents().get('priorityArray')
     serialized_priority_array = serialize_priority_array(priority_array)
     with self.__app_context():
         priority_array_updated = PriorityArrayModel.filter_by_point_uuid(self.profileName).update(
             serialized_priority_array)
         update_point_store(self.profileName, new_value)
         setting: AppSetting = current_app.config[AppSetting.FLASK_KEY]
         if setting.mqtt.publish_value:
             object_identifier = create_object_identifier(self.objectIdentifier[0], self.objectIdentifier[1])
             present_value = self.presentValue
             if isinstance(present_value, Real):
                 present_value = float(present_value.value)
             elif type(present_value) is float:
                 present_value = float(present_value)
             priority = get_highest_priority_field(priority_array_updated)
             mqtt_client = MqttClient()
             mqtt_client.publish_value(('ao', object_identifier, self.objectName), present_value, priority)