@ecobridge.xyz/devicemanager 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/.gitea/workflows/default_nottags.yaml +66 -0
  2. package/.gitea/workflows/default_tags.yaml +124 -0
  3. package/.vscode/launch.json +11 -0
  4. package/.vscode/settings.json +26 -0
  5. package/changelog.md +91 -0
  6. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  7. package/dist_ts/00_commitinfo_data.js +9 -0
  8. package/dist_ts/device/device.classes.device.d.ts +205 -0
  9. package/dist_ts/device/device.classes.device.js +344 -0
  10. package/dist_ts/devicemanager.classes.devicemanager.d.ts +210 -0
  11. package/dist_ts/devicemanager.classes.devicemanager.js +835 -0
  12. package/dist_ts/discovery/discovery.classes.homeassistant.d.ts +101 -0
  13. package/dist_ts/discovery/discovery.classes.homeassistant.js +313 -0
  14. package/dist_ts/discovery/discovery.classes.mdns.d.ts +90 -0
  15. package/dist_ts/discovery/discovery.classes.mdns.js +291 -0
  16. package/dist_ts/discovery/discovery.classes.networkscanner.d.ts +64 -0
  17. package/dist_ts/discovery/discovery.classes.networkscanner.js +535 -0
  18. package/dist_ts/discovery/discovery.classes.ssdp.d.ts +112 -0
  19. package/dist_ts/discovery/discovery.classes.ssdp.js +255 -0
  20. package/dist_ts/factories/index.d.ts +190 -0
  21. package/dist_ts/factories/index.js +350 -0
  22. package/dist_ts/features/feature.abstract.d.ts +118 -0
  23. package/dist_ts/features/feature.abstract.js +172 -0
  24. package/dist_ts/features/feature.camera.d.ts +95 -0
  25. package/dist_ts/features/feature.camera.js +162 -0
  26. package/dist_ts/features/feature.climate.d.ts +174 -0
  27. package/dist_ts/features/feature.climate.js +328 -0
  28. package/dist_ts/features/feature.cover.d.ts +121 -0
  29. package/dist_ts/features/feature.cover.js +217 -0
  30. package/dist_ts/features/feature.fan.d.ts +127 -0
  31. package/dist_ts/features/feature.fan.js +235 -0
  32. package/dist_ts/features/feature.light.d.ts +156 -0
  33. package/dist_ts/features/feature.light.js +296 -0
  34. package/dist_ts/features/feature.lock.d.ts +103 -0
  35. package/dist_ts/features/feature.lock.js +170 -0
  36. package/dist_ts/features/feature.playback.d.ts +98 -0
  37. package/dist_ts/features/feature.playback.js +191 -0
  38. package/dist_ts/features/feature.power.d.ts +79 -0
  39. package/dist_ts/features/feature.power.js +173 -0
  40. package/dist_ts/features/feature.print.d.ts +78 -0
  41. package/dist_ts/features/feature.print.js +226 -0
  42. package/dist_ts/features/feature.scan.d.ts +79 -0
  43. package/dist_ts/features/feature.scan.js +315 -0
  44. package/dist_ts/features/feature.sensor.d.ts +95 -0
  45. package/dist_ts/features/feature.sensor.js +147 -0
  46. package/dist_ts/features/feature.snmp.d.ts +88 -0
  47. package/dist_ts/features/feature.snmp.js +175 -0
  48. package/dist_ts/features/feature.switch.d.ts +75 -0
  49. package/dist_ts/features/feature.switch.js +126 -0
  50. package/dist_ts/features/feature.volume.d.ts +104 -0
  51. package/dist_ts/features/feature.volume.js +186 -0
  52. package/dist_ts/features/index.d.ts +19 -0
  53. package/dist_ts/features/index.js +23 -0
  54. package/dist_ts/helpers/helpers.iprange.d.ts +35 -0
  55. package/dist_ts/helpers/helpers.iprange.js +151 -0
  56. package/dist_ts/helpers/helpers.retry.d.ts +25 -0
  57. package/dist_ts/helpers/helpers.retry.js +69 -0
  58. package/dist_ts/index.d.ts +15 -0
  59. package/dist_ts/index.js +40 -0
  60. package/dist_ts/interfaces/feature.interfaces.d.ts +255 -0
  61. package/dist_ts/interfaces/feature.interfaces.js +6 -0
  62. package/dist_ts/interfaces/homeassistant.interfaces.d.ts +550 -0
  63. package/dist_ts/interfaces/homeassistant.interfaces.js +111 -0
  64. package/dist_ts/interfaces/index.d.ts +330 -0
  65. package/dist_ts/interfaces/index.js +16 -0
  66. package/dist_ts/interfaces/smarthome.interfaces.d.ts +282 -0
  67. package/dist_ts/interfaces/smarthome.interfaces.js +7 -0
  68. package/dist_ts/paths.d.ts +1 -0
  69. package/dist_ts/paths.js +3 -0
  70. package/dist_ts/plugins.d.ts +23 -0
  71. package/dist_ts/plugins.js +30 -0
  72. package/dist_ts/protocols/index.d.ts +12 -0
  73. package/dist_ts/protocols/index.js +21 -0
  74. package/dist_ts/protocols/protocol.escl.d.ts +58 -0
  75. package/dist_ts/protocols/protocol.escl.js +364 -0
  76. package/dist_ts/protocols/protocol.homeassistant.d.ts +248 -0
  77. package/dist_ts/protocols/protocol.homeassistant.js +611 -0
  78. package/dist_ts/protocols/protocol.ipp.d.ts +45 -0
  79. package/dist_ts/protocols/protocol.ipp.js +284 -0
  80. package/dist_ts/protocols/protocol.nut.d.ts +160 -0
  81. package/dist_ts/protocols/protocol.nut.js +364 -0
  82. package/dist_ts/protocols/protocol.sane.d.ts +104 -0
  83. package/dist_ts/protocols/protocol.sane.js +597 -0
  84. package/dist_ts/protocols/protocol.snmp.d.ts +133 -0
  85. package/dist_ts/protocols/protocol.snmp.js +333 -0
  86. package/dist_ts/protocols/protocol.upnp.d.ts +207 -0
  87. package/dist_ts/protocols/protocol.upnp.js +442 -0
  88. package/dist_ts/protocols/protocol.upssnmp.d.ts +160 -0
  89. package/dist_ts/protocols/protocol.upssnmp.js +263 -0
  90. package/npmextra.json +24 -0
  91. package/package.json +39 -0
  92. package/readme.hints.md +115 -0
  93. package/readme.md +624 -0
  94. package/test/test.ts +261 -0
  95. package/ts/00_commitinfo_data.ts +8 -0
  96. package/ts/device/device.classes.device.ts +454 -0
  97. package/ts/devicemanager.classes.devicemanager.ts +1219 -0
  98. package/ts/discovery/discovery.classes.homeassistant.ts +376 -0
  99. package/ts/discovery/discovery.classes.mdns.ts +347 -0
  100. package/ts/discovery/discovery.classes.networkscanner.ts +648 -0
  101. package/ts/discovery/discovery.classes.ssdp.ts +357 -0
  102. package/ts/factories/index.ts +696 -0
  103. package/ts/features/feature.abstract.ts +251 -0
  104. package/ts/features/feature.camera.ts +214 -0
  105. package/ts/features/feature.climate.ts +407 -0
  106. package/ts/features/feature.cover.ts +278 -0
  107. package/ts/features/feature.fan.ts +296 -0
  108. package/ts/features/feature.light.ts +369 -0
  109. package/ts/features/feature.lock.ts +223 -0
  110. package/ts/features/feature.playback.ts +246 -0
  111. package/ts/features/feature.power.ts +231 -0
  112. package/ts/features/feature.print.ts +297 -0
  113. package/ts/features/feature.scan.ts +370 -0
  114. package/ts/features/feature.sensor.ts +202 -0
  115. package/ts/features/feature.snmp.ts +235 -0
  116. package/ts/features/feature.switch.ts +170 -0
  117. package/ts/features/feature.volume.ts +256 -0
  118. package/ts/features/index.ts +25 -0
  119. package/ts/helpers/helpers.iprange.ts +172 -0
  120. package/ts/helpers/helpers.retry.ts +100 -0
  121. package/ts/index.ts +165 -0
  122. package/ts/interfaces/feature.interfaces.ts +359 -0
  123. package/ts/interfaces/homeassistant.interfaces.ts +666 -0
  124. package/ts/interfaces/index.ts +421 -0
  125. package/ts/interfaces/smarthome.interfaces.ts +421 -0
  126. package/ts/paths.ts +5 -0
  127. package/ts/plugins.ts +41 -0
  128. package/ts/protocols/index.ts +59 -0
  129. package/ts/protocols/protocol.escl.ts +439 -0
  130. package/ts/protocols/protocol.homeassistant.ts +737 -0
  131. package/ts/protocols/protocol.ipp.ts +329 -0
  132. package/ts/protocols/protocol.nut.ts +471 -0
  133. package/ts/protocols/protocol.sane.ts +694 -0
  134. package/ts/protocols/protocol.snmp.ts +439 -0
  135. package/ts/protocols/protocol.upnp.ts +627 -0
  136. package/ts/protocols/protocol.upssnmp.ts +377 -0
  137. package/tsconfig.json +12 -0
@@ -0,0 +1,377 @@
1
+ import { SnmpProtocol, SNMP_OIDS, type ISnmpOptions } from '../protocols/index.js';
2
+
3
+ /**
4
+ * Extended UPS-MIB OIDs (RFC 1628)
5
+ */
6
+ export const UPS_SNMP_OIDS = {
7
+ // Identity
8
+ upsIdentManufacturer: '1.3.6.1.2.1.33.1.1.1.0',
9
+ upsIdentModel: '1.3.6.1.2.1.33.1.1.2.0',
10
+ upsIdentUPSSoftwareVersion: '1.3.6.1.2.1.33.1.1.3.0',
11
+ upsIdentAgentSoftwareVersion: '1.3.6.1.2.1.33.1.1.4.0',
12
+ upsIdentName: '1.3.6.1.2.1.33.1.1.5.0',
13
+ upsIdentAttachedDevices: '1.3.6.1.2.1.33.1.1.6.0',
14
+
15
+ // Battery group
16
+ upsBatteryStatus: '1.3.6.1.2.1.33.1.2.1.0',
17
+ upsSecondsOnBattery: '1.3.6.1.2.1.33.1.2.2.0',
18
+ upsEstimatedMinutesRemaining: '1.3.6.1.2.1.33.1.2.3.0',
19
+ upsEstimatedChargeRemaining: '1.3.6.1.2.1.33.1.2.4.0',
20
+ upsBatteryVoltage: '1.3.6.1.2.1.33.1.2.5.0',
21
+ upsBatteryCurrent: '1.3.6.1.2.1.33.1.2.6.0',
22
+ upsBatteryTemperature: '1.3.6.1.2.1.33.1.2.7.0',
23
+
24
+ // Input group
25
+ upsInputLineBads: '1.3.6.1.2.1.33.1.3.1.0',
26
+ upsInputNumLines: '1.3.6.1.2.1.33.1.3.2.0',
27
+ upsInputLineIndex: '1.3.6.1.2.1.33.1.3.3.1.1',
28
+ upsInputFrequency: '1.3.6.1.2.1.33.1.3.3.1.2',
29
+ upsInputVoltage: '1.3.6.1.2.1.33.1.3.3.1.3',
30
+ upsInputCurrent: '1.3.6.1.2.1.33.1.3.3.1.4',
31
+ upsInputTruePower: '1.3.6.1.2.1.33.1.3.3.1.5',
32
+
33
+ // Output group
34
+ upsOutputSource: '1.3.6.1.2.1.33.1.4.1.0',
35
+ upsOutputFrequency: '1.3.6.1.2.1.33.1.4.2.0',
36
+ upsOutputNumLines: '1.3.6.1.2.1.33.1.4.3.0',
37
+ upsOutputLineIndex: '1.3.6.1.2.1.33.1.4.4.1.1',
38
+ upsOutputVoltage: '1.3.6.1.2.1.33.1.4.4.1.2',
39
+ upsOutputCurrent: '1.3.6.1.2.1.33.1.4.4.1.3',
40
+ upsOutputPower: '1.3.6.1.2.1.33.1.4.4.1.4',
41
+ upsOutputPercentLoad: '1.3.6.1.2.1.33.1.4.4.1.5',
42
+
43
+ // Bypass group
44
+ upsBypassFrequency: '1.3.6.1.2.1.33.1.5.1.0',
45
+ upsBypassNumLines: '1.3.6.1.2.1.33.1.5.2.0',
46
+
47
+ // Alarm group
48
+ upsAlarmsPresent: '1.3.6.1.2.1.33.1.6.1.0',
49
+
50
+ // Test group
51
+ upsTestId: '1.3.6.1.2.1.33.1.7.1.0',
52
+ upsTestSpinLock: '1.3.6.1.2.1.33.1.7.2.0',
53
+ upsTestResultsSummary: '1.3.6.1.2.1.33.1.7.3.0',
54
+ upsTestResultsDetail: '1.3.6.1.2.1.33.1.7.4.0',
55
+ upsTestStartTime: '1.3.6.1.2.1.33.1.7.5.0',
56
+ upsTestElapsedTime: '1.3.6.1.2.1.33.1.7.6.0',
57
+
58
+ // Control group
59
+ upsShutdownType: '1.3.6.1.2.1.33.1.8.1.0',
60
+ upsShutdownAfterDelay: '1.3.6.1.2.1.33.1.8.2.0',
61
+ upsStartupAfterDelay: '1.3.6.1.2.1.33.1.8.3.0',
62
+ upsRebootWithDuration: '1.3.6.1.2.1.33.1.8.4.0',
63
+ upsAutoRestart: '1.3.6.1.2.1.33.1.8.5.0',
64
+
65
+ // Config group
66
+ upsConfigInputVoltage: '1.3.6.1.2.1.33.1.9.1.0',
67
+ upsConfigInputFreq: '1.3.6.1.2.1.33.1.9.2.0',
68
+ upsConfigOutputVoltage: '1.3.6.1.2.1.33.1.9.3.0',
69
+ upsConfigOutputFreq: '1.3.6.1.2.1.33.1.9.4.0',
70
+ upsConfigOutputVA: '1.3.6.1.2.1.33.1.9.5.0',
71
+ upsConfigOutputPower: '1.3.6.1.2.1.33.1.9.6.0',
72
+ upsConfigLowBattTime: '1.3.6.1.2.1.33.1.9.7.0',
73
+ upsConfigAudibleStatus: '1.3.6.1.2.1.33.1.9.8.0',
74
+ upsConfigLowVoltageTransferPoint: '1.3.6.1.2.1.33.1.9.9.0',
75
+ upsConfigHighVoltageTransferPoint: '1.3.6.1.2.1.33.1.9.10.0',
76
+ };
77
+
78
+ /**
79
+ * Battery status values from UPS-MIB
80
+ */
81
+ export type TUpsBatteryStatus =
82
+ | 'unknown'
83
+ | 'batteryNormal'
84
+ | 'batteryLow'
85
+ | 'batteryDepleted';
86
+
87
+ /**
88
+ * Output source values from UPS-MIB
89
+ */
90
+ export type TUpsOutputSource =
91
+ | 'other'
92
+ | 'none'
93
+ | 'normal'
94
+ | 'bypass'
95
+ | 'battery'
96
+ | 'booster'
97
+ | 'reducer';
98
+
99
+ /**
100
+ * Test results summary from UPS-MIB
101
+ */
102
+ export type TUpsTestResult =
103
+ | 'donePass'
104
+ | 'doneWarning'
105
+ | 'doneError'
106
+ | 'aborted'
107
+ | 'inProgress'
108
+ | 'noTestsInitiated';
109
+
110
+ /**
111
+ * SNMP-based UPS status interface
112
+ */
113
+ export interface IUpsSnmpStatus {
114
+ batteryStatus: TUpsBatteryStatus;
115
+ secondsOnBattery: number;
116
+ estimatedMinutesRemaining: number;
117
+ estimatedChargeRemaining: number;
118
+ batteryVoltage: number;
119
+ batteryTemperature: number;
120
+ outputSource: TUpsOutputSource;
121
+ outputFrequency: number;
122
+ outputVoltage: number;
123
+ outputCurrent: number;
124
+ outputPower: number;
125
+ outputPercentLoad: number;
126
+ inputFrequency: number;
127
+ inputVoltage: number;
128
+ alarmsPresent: number;
129
+ }
130
+
131
+ /**
132
+ * UPS SNMP handler for querying UPS devices via SNMP
133
+ */
134
+ export class UpsSnmpHandler {
135
+ private protocol: SnmpProtocol;
136
+
137
+ constructor(address: string, options?: ISnmpOptions) {
138
+ this.protocol = new SnmpProtocol(address, options);
139
+ }
140
+
141
+ /**
142
+ * Close SNMP session
143
+ */
144
+ public close(): void {
145
+ this.protocol.close();
146
+ }
147
+
148
+ /**
149
+ * Get UPS identity information
150
+ */
151
+ public async getIdentity(): Promise<{
152
+ manufacturer: string;
153
+ model: string;
154
+ softwareVersion: string;
155
+ name: string;
156
+ }> {
157
+ const varbinds = await this.protocol.getMultiple([
158
+ UPS_SNMP_OIDS.upsIdentManufacturer,
159
+ UPS_SNMP_OIDS.upsIdentModel,
160
+ UPS_SNMP_OIDS.upsIdentUPSSoftwareVersion,
161
+ UPS_SNMP_OIDS.upsIdentName,
162
+ ]);
163
+
164
+ const getValue = (oid: string): string => {
165
+ const vb = varbinds.find((v) => v.oid === oid);
166
+ return String(vb?.value || '');
167
+ };
168
+
169
+ return {
170
+ manufacturer: getValue(UPS_SNMP_OIDS.upsIdentManufacturer),
171
+ model: getValue(UPS_SNMP_OIDS.upsIdentModel),
172
+ softwareVersion: getValue(UPS_SNMP_OIDS.upsIdentUPSSoftwareVersion),
173
+ name: getValue(UPS_SNMP_OIDS.upsIdentName),
174
+ };
175
+ }
176
+
177
+ /**
178
+ * Get battery status
179
+ */
180
+ public async getBatteryStatus(): Promise<{
181
+ status: TUpsBatteryStatus;
182
+ secondsOnBattery: number;
183
+ estimatedMinutesRemaining: number;
184
+ estimatedChargeRemaining: number;
185
+ voltage: number;
186
+ temperature: number;
187
+ }> {
188
+ const varbinds = await this.protocol.getMultiple([
189
+ UPS_SNMP_OIDS.upsBatteryStatus,
190
+ UPS_SNMP_OIDS.upsSecondsOnBattery,
191
+ UPS_SNMP_OIDS.upsEstimatedMinutesRemaining,
192
+ UPS_SNMP_OIDS.upsEstimatedChargeRemaining,
193
+ UPS_SNMP_OIDS.upsBatteryVoltage,
194
+ UPS_SNMP_OIDS.upsBatteryTemperature,
195
+ ]);
196
+
197
+ const getValue = (oid: string): number => {
198
+ const vb = varbinds.find((v) => v.oid === oid);
199
+ return Number(vb?.value || 0);
200
+ };
201
+
202
+ const statusMap: Record<number, TUpsBatteryStatus> = {
203
+ 1: 'unknown',
204
+ 2: 'batteryNormal',
205
+ 3: 'batteryLow',
206
+ 4: 'batteryDepleted',
207
+ };
208
+
209
+ return {
210
+ status: statusMap[getValue(UPS_SNMP_OIDS.upsBatteryStatus)] || 'unknown',
211
+ secondsOnBattery: getValue(UPS_SNMP_OIDS.upsSecondsOnBattery),
212
+ estimatedMinutesRemaining: getValue(UPS_SNMP_OIDS.upsEstimatedMinutesRemaining),
213
+ estimatedChargeRemaining: getValue(UPS_SNMP_OIDS.upsEstimatedChargeRemaining),
214
+ voltage: getValue(UPS_SNMP_OIDS.upsBatteryVoltage) / 10, // Typically in 0.1V units
215
+ temperature: getValue(UPS_SNMP_OIDS.upsBatteryTemperature),
216
+ };
217
+ }
218
+
219
+ /**
220
+ * Get input status
221
+ */
222
+ public async getInputStatus(): Promise<{
223
+ frequency: number;
224
+ voltage: number;
225
+ lineBads: number;
226
+ }> {
227
+ const varbinds = await this.protocol.getMultiple([
228
+ UPS_SNMP_OIDS.upsInputFrequency + '.1', // Line 1
229
+ UPS_SNMP_OIDS.upsInputVoltage + '.1', // Line 1
230
+ UPS_SNMP_OIDS.upsInputLineBads,
231
+ ]);
232
+
233
+ const getValue = (oid: string): number => {
234
+ const vb = varbinds.find((v) => v.oid === oid);
235
+ return Number(vb?.value || 0);
236
+ };
237
+
238
+ return {
239
+ frequency: getValue(UPS_SNMP_OIDS.upsInputFrequency + '.1') / 10, // 0.1 Hz units
240
+ voltage: getValue(UPS_SNMP_OIDS.upsInputVoltage + '.1'),
241
+ lineBads: getValue(UPS_SNMP_OIDS.upsInputLineBads),
242
+ };
243
+ }
244
+
245
+ /**
246
+ * Get output status
247
+ */
248
+ public async getOutputStatus(): Promise<{
249
+ source: TUpsOutputSource;
250
+ frequency: number;
251
+ voltage: number;
252
+ current: number;
253
+ power: number;
254
+ percentLoad: number;
255
+ }> {
256
+ const varbinds = await this.protocol.getMultiple([
257
+ UPS_SNMP_OIDS.upsOutputSource,
258
+ UPS_SNMP_OIDS.upsOutputFrequency,
259
+ UPS_SNMP_OIDS.upsOutputVoltage + '.1', // Line 1
260
+ UPS_SNMP_OIDS.upsOutputCurrent + '.1', // Line 1
261
+ UPS_SNMP_OIDS.upsOutputPower + '.1', // Line 1
262
+ UPS_SNMP_OIDS.upsOutputPercentLoad + '.1', // Line 1
263
+ ]);
264
+
265
+ const getValue = (oid: string): number => {
266
+ const vb = varbinds.find((v) => v.oid === oid);
267
+ return Number(vb?.value || 0);
268
+ };
269
+
270
+ const sourceMap: Record<number, TUpsOutputSource> = {
271
+ 1: 'other',
272
+ 2: 'none',
273
+ 3: 'normal',
274
+ 4: 'bypass',
275
+ 5: 'battery',
276
+ 6: 'booster',
277
+ 7: 'reducer',
278
+ };
279
+
280
+ return {
281
+ source: sourceMap[getValue(UPS_SNMP_OIDS.upsOutputSource)] || 'other',
282
+ frequency: getValue(UPS_SNMP_OIDS.upsOutputFrequency) / 10, // 0.1 Hz units
283
+ voltage: getValue(UPS_SNMP_OIDS.upsOutputVoltage + '.1'),
284
+ current: getValue(UPS_SNMP_OIDS.upsOutputCurrent + '.1') / 10, // 0.1 A units
285
+ power: getValue(UPS_SNMP_OIDS.upsOutputPower + '.1'),
286
+ percentLoad: getValue(UPS_SNMP_OIDS.upsOutputPercentLoad + '.1'),
287
+ };
288
+ }
289
+
290
+ /**
291
+ * Get full UPS status
292
+ */
293
+ public async getFullStatus(): Promise<IUpsSnmpStatus> {
294
+ const [battery, input, output] = await Promise.all([
295
+ this.getBatteryStatus(),
296
+ this.getInputStatus(),
297
+ this.getOutputStatus(),
298
+ ]);
299
+
300
+ // Get alarms separately
301
+ let alarmsPresent = 0;
302
+ try {
303
+ const alarmVb = await this.protocol.get(UPS_SNMP_OIDS.upsAlarmsPresent);
304
+ alarmsPresent = Number(alarmVb.value || 0);
305
+ } catch {
306
+ // Ignore alarm fetch errors
307
+ }
308
+
309
+ return {
310
+ batteryStatus: battery.status,
311
+ secondsOnBattery: battery.secondsOnBattery,
312
+ estimatedMinutesRemaining: battery.estimatedMinutesRemaining,
313
+ estimatedChargeRemaining: battery.estimatedChargeRemaining,
314
+ batteryVoltage: battery.voltage,
315
+ batteryTemperature: battery.temperature,
316
+ outputSource: output.source,
317
+ outputFrequency: output.frequency,
318
+ outputVoltage: output.voltage,
319
+ outputCurrent: output.current,
320
+ outputPower: output.power,
321
+ outputPercentLoad: output.percentLoad,
322
+ inputFrequency: input.frequency,
323
+ inputVoltage: input.voltage,
324
+ alarmsPresent,
325
+ };
326
+ }
327
+
328
+ /**
329
+ * Check if UPS-MIB is supported on device
330
+ */
331
+ public async isUpsDevice(): Promise<boolean> {
332
+ try {
333
+ const vb = await this.protocol.get(UPS_SNMP_OIDS.upsBatteryStatus);
334
+ return vb.value !== null && vb.value !== undefined;
335
+ } catch {
336
+ return false;
337
+ }
338
+ }
339
+
340
+ /**
341
+ * Get configuration info
342
+ */
343
+ public async getConfiguration(): Promise<{
344
+ inputVoltage: number;
345
+ inputFrequency: number;
346
+ outputVoltage: number;
347
+ outputFrequency: number;
348
+ outputVA: number;
349
+ outputPower: number;
350
+ lowBatteryTime: number;
351
+ }> {
352
+ const varbinds = await this.protocol.getMultiple([
353
+ UPS_SNMP_OIDS.upsConfigInputVoltage,
354
+ UPS_SNMP_OIDS.upsConfigInputFreq,
355
+ UPS_SNMP_OIDS.upsConfigOutputVoltage,
356
+ UPS_SNMP_OIDS.upsConfigOutputFreq,
357
+ UPS_SNMP_OIDS.upsConfigOutputVA,
358
+ UPS_SNMP_OIDS.upsConfigOutputPower,
359
+ UPS_SNMP_OIDS.upsConfigLowBattTime,
360
+ ]);
361
+
362
+ const getValue = (oid: string): number => {
363
+ const vb = varbinds.find((v) => v.oid === oid);
364
+ return Number(vb?.value || 0);
365
+ };
366
+
367
+ return {
368
+ inputVoltage: getValue(UPS_SNMP_OIDS.upsConfigInputVoltage),
369
+ inputFrequency: getValue(UPS_SNMP_OIDS.upsConfigInputFreq) / 10,
370
+ outputVoltage: getValue(UPS_SNMP_OIDS.upsConfigOutputVoltage),
371
+ outputFrequency: getValue(UPS_SNMP_OIDS.upsConfigOutputFreq) / 10,
372
+ outputVA: getValue(UPS_SNMP_OIDS.upsConfigOutputVA),
373
+ outputPower: getValue(UPS_SNMP_OIDS.upsConfigOutputPower),
374
+ lowBatteryTime: getValue(UPS_SNMP_OIDS.upsConfigLowBattTime),
375
+ };
376
+ }
377
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "esModuleInterop": true,
7
+ "verbatimModuleSyntax": true
8
+ },
9
+ "exclude": [
10
+ "dist_*/**/*.d.ts"
11
+ ]
12
+ }