Skip to content

Commit bdc5610

Browse files
author
Dennis Labordus
committed
Fixed build and processed some review comments.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent f44a111 commit bdc5610

File tree

13 files changed

+334
-247
lines changed

13 files changed

+334
-247
lines changed

src/editors/protocol104/foundation/cdc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
Create,
33
getNameAttribute,
4-
getTypeAttribute,
54
newLogEvent,
65
newWizardEvent,
76
} from '../../../foundation.js';
@@ -16,6 +15,7 @@ import {
1615
findElementInOriginalLNStructure,
1716
getCdcValueFromDOElement,
1817
getEnumOrds,
18+
getTypeAttribute,
1919
isEnumDataAttribute,
2020
} from './foundation.js';
2121
import { editAddressWizard } from '../wizards/address.js';
@@ -657,7 +657,7 @@ function createTemplateStructure(
657657
let templateStructure: Element[] | null = [doElement];
658658

659659
const doc = doElement.ownerDocument;
660-
const doType = doElement.getAttribute('type') ?? '';
660+
const doType = getTypeAttribute(doElement) ?? '';
661661
let typeElement = doc.querySelector(`DOType[id="${doType}"]`);
662662

663663
daPath.path.forEach(name => {
@@ -678,7 +678,7 @@ function createTemplateStructure(
678678

679679
const bType = daElement.getAttribute('bType') ?? '';
680680
if (bType === 'Struct') {
681-
const type = daElement.getAttribute('type') ?? '';
681+
const type = getTypeAttribute(daElement) ?? '';
682682
typeElement = doc.querySelector(`DAType[id="${type}"]`);
683683
} else {
684684
typeElement = null;

src/editors/protocol104/foundation/foundation.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function getCdcValueFromDOIElement(doiElement: Element): string | null {
7676
}
7777

7878
export function getCdcValueFromDOElement(doElement: Element): string | null {
79-
const doType = doElement.getAttribute('type');
79+
const doType = getTypeAttribute(doElement);
8080
const doTypeElement = doElement.ownerDocument.querySelector(
8181
`DOType[id="${doType}"]`
8282
);
@@ -124,6 +124,16 @@ export function get104DetailsLine(
124124
.join(', ');
125125
}
126126

127+
/**
128+
* Extract the 'type' attribute from the given XML element.
129+
* @param element - The element to extract instance from.
130+
* @returns the value, or undefined if there is no instance.
131+
*/
132+
export function getTypeAttribute(element: Element): string | undefined {
133+
const type = element.getAttribute('type');
134+
return type ? type : undefined;
135+
}
136+
127137
/**
128138
* Search for a DAI Element below the passed DOI Element.
129139
*
@@ -132,7 +142,7 @@ export function get104DetailsLine(
132142
* @returns The found DA Element or null, if not found.
133143
*/
134144
export function getDaElement(doElement: Element, name: string): Element | null {
135-
const doType = doElement.getAttribute('type');
145+
const doType = getTypeAttribute(doElement);
136146
if (doType) {
137147
return doElement.ownerDocument.querySelector(
138148
`DOType[id="${doType}"] > DA[name="${name}"]`
@@ -288,7 +298,7 @@ function buildTemplateChainFromInstanceElements(
288298
templateChain.push(doElement);
289299

290300
// For the next element search the DOType that is linked to the DO Element.
291-
const typeId = doElement.getAttribute('type') ?? '';
301+
const typeId = getTypeAttribute(doElement) ?? '';
292302
typeElement = doc.querySelector(`DOType[id="${typeId}"]`);
293303
} else {
294304
typeElement = null;
@@ -306,7 +316,7 @@ function buildTemplateChainFromInstanceElements(
306316

307317
if (daElement.getAttribute('bType') === 'Struct') {
308318
// Only if the bType is a struct we need to search for the DAType for the next element.
309-
const typeId = element.getAttribute('type') ?? '';
319+
const typeId = getTypeAttribute(element) ?? '';
310320
typeElement = doc.querySelector(`DAType[id="${typeId}"]`);
311321
} else {
312322
typeElement = null;
@@ -373,7 +383,7 @@ export function isEnumDataAttribute(daiElement: Element): boolean {
373383
export function getEnumVal(daiElement: Element, ord: string): string | null {
374384
const daElement = getDaElementByDaiElement(daiElement);
375385
if (isEnumType(daElement)) {
376-
const enumType = daElement!.getAttribute('type');
386+
const enumType = getTypeAttribute(daElement!);
377387
const enumVal = daiElement.ownerDocument.querySelector(
378388
`EnumType[id="${enumType}"] > EnumVal[ord="${ord}"]`
379389
);
@@ -393,7 +403,7 @@ export function getEnumOrds(daiElement: Element): string[] {
393403
const ords: string[] = [];
394404
const daElement = getDaElementByDaiElement(daiElement);
395405
if (isEnumType(daElement)) {
396-
const enumType = daElement!.getAttribute('type');
406+
const enumType = getTypeAttribute(daElement!);
397407
const enumVals = daiElement.ownerDocument.querySelectorAll(
398408
`EnumType[id="${enumType}"] > EnumVal`
399409
);

src/editors/protocol104/foundation/p-types.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const pTypes104: string[] = [
66
'TIMEOUT-0',
77
'TIMEOUT-1',
88
'TIMEOUT-2',
9-
'TIMEOUT-3'
9+
'TIMEOUT-3',
1010
];
1111

1212
export const pTypesRedundancyGroup104: string[] = [
@@ -15,18 +15,16 @@ export const pTypesRedundancyGroup104: string[] = [
1515
'TIMEOUT-0',
1616
'TIMEOUT-1',
1717
'TIMEOUT-2',
18-
'TIMEOUT-3'
18+
'TIMEOUT-3',
1919
];
2020

21-
export const pTypesLogicLink104: string[] = [
22-
'IP',
23-
'IP-SUBNET'
24-
];
21+
export const pTypesLogicLink104: string[] = ['IP', 'IP-SUBNET'];
2522

2623
const typeBase = {
2724
IP: '([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])',
28-
factor: '[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-3][0-2][0-7][0-6][0-7]',
29-
timeout: '[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]'
25+
factor:
26+
'[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-3][0-2][0-7][0-6][0-7]',
27+
timeout: '[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]',
3028
};
3129

3230
/** Patterns from IEC 61850-80-1 for all `P` elements */
@@ -38,22 +36,22 @@ export const typePattern: Partial<Record<string, string>> = {
3836
'TIMEOUT-0': typeBase.timeout,
3937
'TIMEOUT-1': typeBase.timeout,
4038
'TIMEOUT-2': typeBase.timeout,
41-
'TIMEOUT-3': typeBase.timeout
39+
'TIMEOUT-3': typeBase.timeout,
4240
};
4341

4442
export const stationTypeOptions: string[] = [
4543
'controlling-station',
46-
'controlled-station'
47-
]
44+
'controlled-station',
45+
];
4846

4947
export const typeDescriptiveNameKeys: Record<string, string> = {
50-
'StationType': 'protocol104.network.connectedAp.wizard.stationTypeHelper',
51-
'IP': 'protocol104.network.connectedAp.wizard.ipHelper',
48+
StationType: 'protocol104.network.connectedAp.wizard.stationTypeHelper',
49+
IP: 'protocol104.network.connectedAp.wizard.ipHelper',
5250
'IP-SUBNET': 'protocol104.network.connectedAp.wizard.ipSubnetHelper',
5351
'W-FACTOR': 'protocol104.network.connectedAp.wizard.wFactorHelper',
5452
'K-FACTOR': 'protocol104.network.connectedAp.wizard.kFactorHelper',
5553
'TIMEOUT-0': 'protocol104.network.connectedAp.wizard.timeout0Helper',
5654
'TIMEOUT-1': 'protocol104.network.connectedAp.wizard.timeout1Helper',
5755
'TIMEOUT-2': 'protocol104.network.connectedAp.wizard.timeout2Helper',
5856
'TIMEOUT-3': 'protocol104.network.connectedAp.wizard.timeout3Helper',
59-
};
57+
};

src/editors/protocol104/network-container.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import {
1010
} from '../../foundation.js';
1111
import { createSubNetworkWizard } from './wizards/subnetwork.js';
1212
import { Base104Container } from './base-container.js';
13+
import { getTypeAttribute } from './foundation/foundation.js';
1314

1415
@customElement('network-104-container')
1516
export class Network104Container extends Base104Container {
1617
private getSubNetworkElements(): Element[] {
1718
return Array.from(
1819
this.doc.querySelectorAll('Communication > SubNetwork') ?? []
1920
)
20-
.filter(network => network.getAttribute('type') === '104')
21+
.filter(network => getTypeAttribute(network) === '104')
2122
.sort((a, b) => compareNames(a, b));
2223
}
2324

src/editors/protocol104/subnetwork-container.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { compareNames, newWizardEvent } from '../../foundation.js';
1313
import { translate } from 'lit-translate';
1414
import { createConnectedApWizard } from './wizards/connectedap.js';
1515
import { Base104Container } from './base-container.js';
16+
import { getTypeAttribute } from './foundation/foundation.js';
1617

1718
/** [[`104`]] subeditor for a `SubNetwork` element. */
1819
@customElement('subnetwork-104-container')
@@ -60,7 +61,7 @@ export class SubNetwork104Container extends Base104Container {
6061
}
6162

6263
private subNetworkSpecs(): string {
63-
const type = this.element.getAttribute('type') ?? null;
64+
const type = getTypeAttribute(this.element) ?? null;
6465

6566
if (!type && !this.bitrate) return '';
6667

0 commit comments

Comments
 (0)