Skip to content

feat(LN): add describe Log #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: describeInputs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions describe/LN.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const scl = new DOMParser().parseFromString(
<Val>on</Val>
</DAI>
</DOI>
<Log name="someLog" />
<Log name="someOtherLog" />
<Inputs>
<ExtRef intAddr="Beh.t" pLN="LLN0" pDO="Beh" pDA="t" pServT="GOOSE" />
</Inputs>
Expand Down Expand Up @@ -55,6 +57,8 @@ const scl = new DOMParser().parseFromString(
</LDevice>
<LDevice inst="lDevice2">
<LN0 lnClass="LLN0" inst="" lnType="LLN02" >
<Log name="someOtherLog" />
<Log name="someLog" />
<Inputs>
<ExtRef intAddr="Beh.t" pLN="LLN0" pDO="Beh" pDA="t" pServT="GOOSE" />
</Inputs>
Expand Down
17 changes: 17 additions & 0 deletions describe/LN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { describeVal, compareBySGroup } from "./Val.js";
export interface LNDescription extends NamingDescription {
reports: Record<string, ReportControlDescription>;
logControls: Record<string, LogControlDescription>;
logs: Record<string, NamingDescription>;
inputs?: InputsDescription;
lnType: LNodeTypeDescription;
}
Expand Down Expand Up @@ -90,6 +91,21 @@ function logControls(element: Element): Record<string, LogControlDescription> {
>;
}

function logs(element: Element): Record<string, NamingDescription> {
const unsortedLogs: Record<string, NamingDescription> = {};

Array.from(element.children)
.filter((child) => child.tagName === "Log")
.forEach((log) => {
const name = log.getAttribute("name");
const logDescription = describeNaming(log);
if (name && !unsortedLogs[name] && logDescription)
unsortedLogs[name] = logDescription;
});

return sortRecord(unsortedLogs) as Record<string, NamingDescription>;
}

/** Returns leaf data attribute (BDA or DA) from
* LNodeTypeDescription containing vals
* @param path - parent DOI/SDI/DAI name attributes
Expand Down Expand Up @@ -160,6 +176,7 @@ export function LN(element: Element): LNDescription | undefined {
...describeNaming(element),
reports: reportControls(element),
logControls: logControls(element),
logs: logs(element),
lnType,
};

Expand Down
2 changes: 2 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { DADescription } from "./describe/DADescription.js";
import { DODescription } from "./describe/DODescription.js";
import { LogControlDescription } from "./describe/LogControl.js";
import { NamingDescription } from "./describe/Naming.js";
import { ReportControlDescription } from "./describe/ReportControl.js";
import { SDODescription } from "./describe/SDODescription.js";

type SortedObjects =
| DADescription
| LogControlDescription
| NamingDescription
| SDODescription
| ReportControlDescription
| DODescription;
Expand Down