diff --git a/collector/src/index.js b/collector/src/index.js index f26d2f1..c02e343 100644 --- a/collector/src/index.js +++ b/collector/src/index.js @@ -904,11 +904,28 @@ async function requestIpsymconApi(source, payload) { } } +function getIpsymconLinkedName(variable, variableId) { + const sources = Array.isArray(variable?.sources) ? variable.sources : []; + for (const source of sources) { + const links = Array.isArray(source?.link_chain) ? source.link_chain : []; + for (const link of [...links].reverse()) { + if (Number(link?.target_id) === variableId) { + const linkName = normalizeText(link?.name); + if (linkName) return linkName; + } + } + } + return ""; +} + function mapIpsymconVariable(source, variable, categoryId, index) { const variableId = Number(variable?.id); const variableType = normalizeText(variable?.variable_type || variable?.type || ""); const kind = variableType === "boolean" || typeof variable?.value === "boolean" ? "digital" : "analog"; - const name = normalizeText(variable?.full_name || variable?.name || `Variable ${variableId}`) || `Variable ${variableId}`; + // A named variable link is the operator-facing label and takes precedence over its target's name. + const name = getIpsymconLinkedName(variable, variableId) + || normalizeText(variable?.full_name || variable?.name || `Variable ${variableId}`) + || `Variable ${variableId}`; return { id: `${source.id}::ipsymcon::${variableId}`, protocol: "ipsymcon",