|
1 | | -import { Ispecification } from "./types"; |
| 1 | +import { ImodbusSpecification, Ispecification, VariableTargetParameters } from './types' |
2 | 2 | export enum MessageTypes { |
3 | 3 | nameTextMissing = 0, |
4 | 4 | entityTextMissing = 1, |
@@ -47,61 +47,54 @@ export enum MessageCategories { |
47 | 47 | configuration = 8, |
48 | 48 | } |
49 | 49 | 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 |
54 | 54 | } |
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'] |
62 | 56 |
|
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 |
70 | 60 | if (spec.entities.length > 0) { |
71 | 61 | if (!en) |
72 | 62 | msgs.push({ |
73 | 63 | type: MessageTypes.translationMissing, |
74 | 64 | category: category, |
75 | 65 | additionalInformation: language, |
76 | | - }); |
| 66 | + }) |
77 | 67 | 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 }) |
99 | 82 | } |
100 | 83 | } |
101 | 84 | } |
102 | 85 |
|
103 | 86 | 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) : '' |
107 | 100 | } |
0 commit comments