nayota-show-sdk 1.3.71 → 1.3.73
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.
- package/api/devices.js +4 -0
- package/package.json +1 -1
- package/utils/iot-module-specs.js +53 -0
- package/utils/iot-module-specs.test.js +56 -0
package/api/devices.js
CHANGED
|
@@ -369,6 +369,10 @@ export function easyList(data) {
|
|
|
369
369
|
}
|
|
370
370
|
*/
|
|
371
371
|
export function getPropHistoryData(data) {
|
|
372
|
+
if (shouldUseIot('getPropHistoryData')) {
|
|
373
|
+
return executeIotModuleAction(MODULE_NAME, 'getPropHistoryData', data)
|
|
374
|
+
}
|
|
375
|
+
|
|
372
376
|
return requestShow({
|
|
373
377
|
url: '/devices/getPropHistoryData',
|
|
374
378
|
method: 'post',
|
package/package.json
CHANGED
|
@@ -360,6 +360,28 @@ function normalizeLegacyPropLine(source = {}, prop = {}, row = {}) {
|
|
|
360
360
|
return null
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
+
function normalizeLegacyNumber(value) {
|
|
364
|
+
if (value === undefined || value === null || value === '') {
|
|
365
|
+
return null
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const raw = normalizeLegacyCurrentValue(value)
|
|
369
|
+
const num = Number(raw)
|
|
370
|
+
return Number.isFinite(num) ? num : null
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function getLegacyStatusCounts(props = []) {
|
|
374
|
+
const statusProps = props.filter(prop => prop && prop.isStatus)
|
|
375
|
+
return {
|
|
376
|
+
total: statusProps.length,
|
|
377
|
+
open: statusProps.filter(prop =>
|
|
378
|
+
normalizeLegacyNumber(prop.rawValue) === 1 ||
|
|
379
|
+
normalizeLegacyNumber(prop.value) === 1 ||
|
|
380
|
+
normalizeLegacyNumber(prop.prop?.value) === 1
|
|
381
|
+
).length
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
363
385
|
function normalizeLegacyEasyListProp(source = {}, row = {}) {
|
|
364
386
|
const prop = withLegacyId(source.prop || {})
|
|
365
387
|
const propId = source.propId || source.devicePropertyId || prop._id || source._id || source.id
|
|
@@ -426,10 +448,18 @@ function normalizeLegacyEasyListRow(item = {}) {
|
|
|
426
448
|
const props = Array.isArray(row.props)
|
|
427
449
|
? row.props.map(prop => normalizeLegacyEasyListProp(prop, row))
|
|
428
450
|
: []
|
|
451
|
+
const statusCounts = getLegacyStatusCounts(props)
|
|
429
452
|
|
|
430
453
|
return removeUndefinedFields({
|
|
431
454
|
...row,
|
|
432
455
|
props,
|
|
456
|
+
status: row.status
|
|
457
|
+
? {
|
|
458
|
+
...row.status,
|
|
459
|
+
total: row.status.total ?? statusCounts.total,
|
|
460
|
+
open: row.status.open ?? statusCounts.open
|
|
461
|
+
}
|
|
462
|
+
: undefined,
|
|
433
463
|
lineTime: row.lineTime || props.find(prop => prop.isImport && prop.valueAt)?.valueAt || row.updatedAt || null
|
|
434
464
|
})
|
|
435
465
|
}
|
|
@@ -738,6 +768,29 @@ export const iotModuleSpecs = {
|
|
|
738
768
|
}
|
|
739
769
|
}
|
|
740
770
|
}
|
|
771
|
+
},
|
|
772
|
+
getPropHistoryData: {
|
|
773
|
+
toRequest(data = {}) {
|
|
774
|
+
return {
|
|
775
|
+
url: '/devices/getPropHistoryData',
|
|
776
|
+
method: 'post',
|
|
777
|
+
data
|
|
778
|
+
}
|
|
779
|
+
},
|
|
780
|
+
fromResponse(response) {
|
|
781
|
+
const payload = response && response.data && response.status ? response.data : response
|
|
782
|
+
const data = payload?.data !== undefined ? payload.data : payload
|
|
783
|
+
const rows = Array.isArray(data?.rows)
|
|
784
|
+
? data.rows
|
|
785
|
+
: Array.isArray(payload?.rows)
|
|
786
|
+
? payload.rows
|
|
787
|
+
: []
|
|
788
|
+
return removeUndefinedFields({
|
|
789
|
+
code: Number(data?.code ?? payload?.code ?? 0),
|
|
790
|
+
rows,
|
|
791
|
+
message: data?.message ?? payload?.message
|
|
792
|
+
})
|
|
793
|
+
}
|
|
741
794
|
}
|
|
742
795
|
}
|
|
743
796
|
},
|
|
@@ -140,6 +140,11 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
|
|
|
140
140
|
id: 'twin-1',
|
|
141
141
|
name: '会议室空调',
|
|
142
142
|
line: false,
|
|
143
|
+
status: {
|
|
144
|
+
value: 1,
|
|
145
|
+
label: '制热',
|
|
146
|
+
valueStr: '制热'
|
|
147
|
+
},
|
|
143
148
|
props: [
|
|
144
149
|
{
|
|
145
150
|
id: 'twin-prop-mode',
|
|
@@ -182,6 +187,13 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
|
|
|
182
187
|
const electricProp = row.props[1]
|
|
183
188
|
|
|
184
189
|
expect(row._id).toBe('twin-1')
|
|
190
|
+
expect(row.status).toEqual({
|
|
191
|
+
value: 1,
|
|
192
|
+
label: '制热',
|
|
193
|
+
valueStr: '制热',
|
|
194
|
+
total: 1,
|
|
195
|
+
open: 1
|
|
196
|
+
})
|
|
185
197
|
expect(modeProp).toEqual(
|
|
186
198
|
expect.objectContaining({
|
|
187
199
|
_id: 'twin-prop-mode',
|
|
@@ -225,3 +237,47 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
|
|
|
225
237
|
)
|
|
226
238
|
})
|
|
227
239
|
})
|
|
240
|
+
|
|
241
|
+
describe('iotModuleSpecs devices getPropHistoryData legacy compatibility', () => {
|
|
242
|
+
const getPropHistoryData = iotModuleSpecs.devices.operations.getPropHistoryData
|
|
243
|
+
|
|
244
|
+
test('posts to the legacy-compatible iot endpoint and keeps rows at top level', () => {
|
|
245
|
+
const request = getPropHistoryData.toRequest({
|
|
246
|
+
date: '2026-04-25T15:59:59.000Z',
|
|
247
|
+
deviceClasses: ['type-1']
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
expect(request).toEqual({
|
|
251
|
+
url: '/devices/getPropHistoryData',
|
|
252
|
+
method: 'post',
|
|
253
|
+
data: {
|
|
254
|
+
date: '2026-04-25T15:59:59.000Z',
|
|
255
|
+
deviceClasses: ['type-1']
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
const response = getPropHistoryData.fromResponse({
|
|
260
|
+
code: 0,
|
|
261
|
+
rows: [
|
|
262
|
+
{
|
|
263
|
+
_id: 'status-prop',
|
|
264
|
+
value: 1,
|
|
265
|
+
valueStr: '制热',
|
|
266
|
+
recordTime: '2026-04-25T08:00:00.000Z'
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
expect(response).toEqual({
|
|
272
|
+
code: 0,
|
|
273
|
+
rows: [
|
|
274
|
+
{
|
|
275
|
+
_id: 'status-prop',
|
|
276
|
+
value: 1,
|
|
277
|
+
valueStr: '制热',
|
|
278
|
+
recordTime: '2026-04-25T08:00:00.000Z'
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
})
|