def __sync_point_value_gp_to_mp(modbus_point_uuid: str, priority_array_write: dict): priority_array_write.pop('point_uuid', None) gw_request( api=f"/modbus/api/modbus/points_value/uuid/{modbus_point_uuid}", body={"priority_array_write": priority_array_write}, http_method=HttpMethod.PATCH)
def __set_mapped_point_uuid(self): if not self.mapped_point_name: raise ValueError("mapped_point_name should not be null or blank") if self.type in (MapType.GENERIC.name, MapType.GENERIC): mapped_point_names = self.mapped_point_name.split(":") if len(mapped_point_names) != 3: raise ValueError( "mapped_point_names should be colon (:) delimited network_name:device_name:point_name" ) network_name, device_name, point_name = mapped_point_names response: Response = gw_request( f'/ps/api/generic/points/name/{network_name}/{device_name}/{point_name}' ) if response.status_code != 200: raise ValueError( f"Does not exit mapped_point_name {self.mapped_point_name}" ) self.mapped_point_uuid = json.loads(response.data).get('uuid') elif self.type in (MapType.BACNET.name, MapType.BACNET): response: Response = gw_request( api=f'/bacnet/api/bacnet/points/name/{self.mapped_point_name}') if response.status_code != 200: raise ValueError( f"Does not exist mapped_point_name {self.mapped_point_name}" ) self.mapped_point_uuid = json.loads(response.data).get('uuid') else: raise ValueError(f"Invalid type {self.type}")
def sync_point_value_bp_to_mp(self): response: Response = gw_request(f"/ps/api/mappings/mp_gbp/bacnet/{self.point_uuid}") if response.status_code == 200: gw_request( api=f"/ps/api/modbus/points_value/uuid/{json.loads(response.data).get('modbus_point_uuid')}", body={"value": self.present_value}, http_method=HttpMethod.PATCH )
def sync_on_start(): from rubix_http.request import gw_request """Sync mapped points values from LoRa > BACnet points values""" gw_request('/lora/api/sync/lp_to_bp') """Sync mapped points values from Modbus > BACnet points values""" gw_request('/ps/api/sync/mp_to_bp') """Sync mapped points values from BACnet > Generic points values""" from .bacnet_server.models.model_point_store import BACnetPointStoreModel BACnetPointStoreModel.sync_points_values_bp_to_gp_process()
def sync_point_value_lp_to_gbp(self, map_type: str, mapped_point_uuid: str, gp: bool = True, bp=True): if map_type in (MapType.GENERIC.name, MapType.GENERIC) and gp: gw_request( api=f"/ps/api/generic/points_value/uuid/{mapped_point_uuid}", body={"value": self.value}, http_method=HttpMethod.PATCH) elif map_type in (MapType.BACNET.name, MapType.BACNET) and bp: gw_request( api=f"/bacnet/api/bacnet/points/uuid/{mapped_point_uuid}", body={"priority_array_write": { "_16": self.value }}, http_method=HttpMethod.PATCH)
def __sync_point_value_gp_to_bp_process(self, priority_array_write: dict): response: Response = gw_request( api=f"/bacnet/api/mappings/bp_gp/generic/{self.point_uuid}") if response.status_code == 200: mapping = json.loads(response.data) if mapping and mapping.get('mapping_state') in ( MappingState.MAPPED, MappingState.MAPPED.name): gevent.spawn(self.__sync_point_value_gp_to_bp, mapping.get('point_uuid'), priority_array_write)
def __update_generic_point_store(message: MQTTMessage, point_uuid: str): try: payload: dict = json.loads(message.payload) except Exception as e: logger.warning( f'Invalid generic point COV payload for point.uuid={point_uuid}. Here, error=({str(e)})' ) return value = payload.get('value', None) priority = payload.get('priority', None) priority_array_write = payload.get('priority_array_write', None) # Requesting API instead querying directly, coz API itself have the queueing feature for API call # It queues value for same API call gw_request(api=f"/ps/api/generic/points_value/uuid/{point_uuid}", body={ "value": value, 'priority': priority, 'priority_array_write': priority_array_write }, http_method=HttpMethod.PATCH)
def __set_mapped_point_name(self): if not self.mapped_point_uuid: raise ValueError("mapped_point_uuid should not be null or blank") if self.type in (MapType.GENERIC.name, MapType.GENERIC): response: Response = gw_request( f'/ps/api/generic/points/get_name/uuid/{self.mapped_point_uuid}' ) if response.status_code != 200: raise ValueError( f"Does not exist mapped_point_uuid {self.mapped_point_uuid}" ) self.mapped_point_name = json.loads(response.data).get('name') elif self.type in (MapType.BACNET.name, MapType.BACNET): response: Response = gw_request( f'/bacnet/api/bacnet/points/uuid/{self.mapped_point_uuid}') if response.status_code != 200: raise ValueError( f"Does not exist mapped_point_uuid {self.mapped_point_uuid}" ) self.mapped_point_name = json.loads( response.data).get('object_name')
def __sync_point_value_gp_to_bp(bacnet_point_uuid, priority_array_write: dict): priority_array_write.pop('point_uuid', None) gw_request(api=f"/bacnet/api/bacnet/points/uuid/{bacnet_point_uuid}", body={"priority_array_write": priority_array_write}, http_method=HttpMethod.PATCH)
def sync_point_value_bp_to_gp(self, generic_point_uuid: str): gw_request( api=f"/ps/api/generic/points_value/uuid/{generic_point_uuid}", body={"value": self.present_value}, http_method=HttpMethod.PATCH )
def validate_generic_point_uuid(self, _, value): response: Response = gw_request(f'/ps/api/generic/points/uuid/{value}') if response.status_code != 200: raise ValueError(f'generic_point_uuid = {value}, does not exist') return value
def sync_on_start(): from rubix_http.request import gw_request """Sync mapped points values from LoRa > Generic points values""" gw_request(api='/lora/api/sync/lp_to_gp') """Sync mapped points values from BACnet > Generic points values""" gw_request(api='/bacnet/api/sync/bp_to_gp')