UNPKG

isoxml

Version:

JavaScript library to parse and generate ISOXML (ISO11783-10) files

39 lines (38 loc) 1.75 kB
import { DeviceElement } from "../baseEntities"; import { TAGS } from "../baseEntities/constants"; import { registerEntityClass } from "../classRegistry"; export class ExtendedDeviceElement extends DeviceElement { constructor(attributes, isoxmlManager) { super(attributes, isoxmlManager); this.tag = TAGS.DeviceElement; } static fromXML(xml, isoxmlManager, internalId) { return DeviceElement.fromXML(xml, isoxmlManager, internalId, ExtendedDeviceElement); } getParentDevice() { return this.isoxmlManager.getEntitiesOfTag(TAGS.Device).find(device => (device.attributes.DeviceElement || []).find(deviceElement => deviceElement === this)); } getValuePresentation(ddi) { const device = this.getParentDevice(); if (!device) { return null; } const processData = this.getDataProcess(ddi); const dvpObjectId = processData === null || processData === void 0 ? void 0 : processData.attributes.DeviceValuePresentationObjectId; if (!dvpObjectId) { return null; } return (device.attributes.DeviceValuePresentation || []) .find(dvp => dvp.attributes.DeviceValuePresentationObjectId === dvpObjectId); } getDataProcess(ddi) { const device = this.getParentDevice(); if (!device) { return null; } return (device.attributes.DeviceProcessData || []).find(dpd => dpd.attributes.DeviceProcessDataDDI === ddi && (this.attributes.DeviceObjectReference || []) .find(ref => ref.attributes.DeviceObjectId === dpd.attributes.DeviceProcessDataObjectId)); } } registerEntityClass('main', TAGS.DeviceElement, ExtendedDeviceElement);