diff --git a/mango/augment_site_model.py b/mango/augment_site_model.py index b5218ce..1a68d94 100644 --- a/mango/augment_site_model.py +++ b/mango/augment_site_model.py @@ -59,7 +59,7 @@ def main(): print(f"Discovery wasn't found: {item_path}. Skipping.") continue - cloud_num_id = discovery_match.item() + cloud_num_id = str(discovery_match.iloc[0]) if "CGW" in d: # gateways have their own metadata and are not in carson config diff --git a/mango/loadsheet_to_building_config.py b/mango/loadsheet_to_building_config.py index 0379588..7179f77 100644 --- a/mango/loadsheet_to_building_config.py +++ b/mango/loadsheet_to_building_config.py @@ -38,7 +38,7 @@ def main(): "units", "deviceId", "objectType", "objectId", "isMissing"]] display_name = asset - code = ", ".join(sorted(asset_loadsheet.controlProgram.dropna().unique().tolist())) + code = ", ".join(sorted(asset_loadsheet.controlProgram.dropna().astype(str).unique().tolist())) type = asset_loadsheet.typeName.dropna().unique().tolist() if len(type) != 1: print(f"[ERROR] Asset has no typeName: {asset}. Check Loadsheet.") @@ -72,7 +72,8 @@ def main(): print(f"[WARNING] No numeric_id found for proxy_id: {device.proxy_id}") device.numeric_id = None elif len(device_match) > 1: - print(f"[WARNING] Multiple numeric_id found for {device.proxy_id}, {', '.join(device_match.tolist())}. Using the first one.") + match_list = [str(x) for x in device_match.tolist()] + print(f"[WARNING] Multiple numeric_id found for {device.proxy_id}, {', '.join(match_list)}. Using the first one.") device.numeric_id = str(device_match.values[0]) else: device.numeric_id = str(device_match.values[0]) diff --git a/models/cloud_models.py b/models/cloud_models.py index abe523a..7d32e8a 100644 --- a/models/cloud_models.py +++ b/models/cloud_models.py @@ -1,6 +1,45 @@ import os from helpers import helpers +def parse_object_id(dp_string): + """ + Parses device_id and object_id from a metadata string. + """ + try: + if not isinstance(dp_string, str): + return None, None + + # Handle URI format: bacnet://4013203/AV/13 + if "bacnet://" in dp_string: + # Remove protocol and split by slash + clean_uri = dp_string.replace("bacnet://", "") + parts = clean_uri.split("/") + + # Now parts is ['4013203', 'AV', '13'] + if len(parts) < 3: + return None, None + + numeric_id = parts[0] + type_initials = parts[1] + index = parts[2] + return str(numeric_id), f"{type_initials}:{index}" + + # Handle Legacy format: DP_2800039_ANALOG_VALUE_68 + elif "DP_" in dp_string: + parts = dp_string.split("_") + if len(parts) < 4: + return None, None + + numeric_id = parts[1] + type_initials = "".join([word[0] for word in parts[2:-1]]) + index = parts[-1] + return str(numeric_id), f"{type_initials}:{index}" + + return None, None + + except Exception as e: + return None, None + class Device: def __init__(self, proxy_id=None, numeric_id=None, point_dict=None, device_list=None, metadata=None, guid=None): self._proxy_id = proxy_id