Skip to content

Commit 17d19f7

Browse files
committed
Added getUom to Specification.ts, pretty print
1 parent 17c92bb commit 17d19f7

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

.prettierrc.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: false,
3+
singleQuote: true,
4+
trailingComma: 'es5',
5+
arrowParens: 'always',
6+
printWidth: 132,
7+
}

src/Specification.ts

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Ispecification } from "./types";
1+
import { ImodbusSpecification, Ispecification, VariableTargetParameters } from './types'
22
export enum MessageTypes {
33
nameTextMissing = 0,
44
entityTextMissing = 1,
@@ -47,61 +47,54 @@ export enum MessageCategories {
4747
configuration = 8,
4848
}
4949
export interface Imessage {
50-
type: MessageTypes;
51-
category: MessageCategories;
52-
referencedEntity?: number;
53-
additionalInformation?: any;
50+
type: MessageTypes
51+
category: MessageCategories
52+
referencedEntity?: number
53+
additionalInformation?: any
5454
}
55-
export const editableConverters: string[] = [
56-
"binary_sensor",
57-
"number",
58-
"text",
59-
"select",
60-
"button",
61-
];
55+
export const editableConverters: string[] = ['binary_sensor', 'number', 'text', 'select', 'button']
6256

63-
export function validateTranslation(
64-
spec: Ispecification,
65-
language: string,
66-
msgs: Imessage[],
67-
) {
68-
let en = spec.i18n.find((l: { lang: string }) => l.lang === language);
69-
let category = MessageCategories.validateTranslation;
57+
export function validateTranslation(spec: Ispecification, language: string, msgs: Imessage[]) {
58+
let en = spec.i18n.find((l: { lang: string }) => l.lang === language)
59+
let category = MessageCategories.validateTranslation
7060
if (spec.entities.length > 0) {
7161
if (!en)
7262
msgs.push({
7363
type: MessageTypes.translationMissing,
7464
category: category,
7565
additionalInformation: language,
76-
});
66+
})
7767
else {
78-
spec.entities.forEach(
79-
(ent: { variableConfiguration?: any; id: number }) => {
80-
if (!ent.variableConfiguration) {
81-
let translation = en!.texts.find(
82-
(tx: { textId: string }) => tx.textId == "e" + ent.id,
83-
);
84-
if (!translation)
85-
msgs.push({
86-
type: MessageTypes.entityTextMissing,
87-
category: category,
88-
referencedEntity: ent.id,
89-
additionalInformation: language,
90-
});
91-
}
92-
},
93-
);
94-
let nameTranslation = en?.texts.find(
95-
(tx: { textId: string }) => tx.textId == "name",
96-
);
97-
if (!nameTranslation)
98-
msgs.push({ type: MessageTypes.nameTextMissing, category: category });
68+
spec.entities.forEach((ent: { variableConfiguration?: any; id: number }) => {
69+
if (!ent.variableConfiguration) {
70+
let translation = en!.texts.find((tx: { textId: string }) => tx.textId == 'e' + ent.id)
71+
if (!translation)
72+
msgs.push({
73+
type: MessageTypes.entityTextMissing,
74+
category: category,
75+
referencedEntity: ent.id,
76+
additionalInformation: language,
77+
})
78+
}
79+
})
80+
let nameTranslation = en?.texts.find((tx: { textId: string }) => tx.textId == 'name')
81+
if (!nameTranslation) msgs.push({ type: MessageTypes.nameTextMissing, category: category })
9982
}
10083
}
10184
}
10285

10386
export function getBaseFilename(filename: string): string {
104-
let idx = filename.lastIndexOf("/");
105-
if (idx >= 0) return filename.substring(idx + 1);
106-
return filename;
87+
let idx = filename.lastIndexOf('/')
88+
if (idx >= 0) return filename.substring(idx + 1)
89+
return filename
90+
}
91+
export function getUom(spec: ImodbusSpecification, entityId: number): string {
92+
let ent = spec.entities.find((e) => e.id == entityId)
93+
let entUom = spec.entities.find(
94+
(e) =>
95+
e.variableConfiguration &&
96+
e.variableConfiguration.targetParameter == VariableTargetParameters.entityUom &&
97+
e.variableConfiguration.entityId == entityId
98+
)
99+
return entUom && entUom.mqttValue ? (entUom.mqttValue as string) : ''
107100
}

0 commit comments

Comments
 (0)