nayota-show-sdk 1.3.73 → 1.3.74

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nayota-show-sdk",
3
- "version": "1.3.73",
3
+ "version": "1.3.74",
4
4
  "description": "nayota-show-server rest-api",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -370,15 +370,85 @@ function normalizeLegacyNumber(value) {
370
370
  return Number.isFinite(num) ? num : null
371
371
  }
372
372
 
373
+ const LEGACY_OPEN_STATUS_KEYWORDS = ['开', '开启', '运行', '启动']
374
+
375
+ function normalizeLegacyStatusText(value) {
376
+ if (value === undefined || value === null) {
377
+ return ''
378
+ }
379
+
380
+ if (value && typeof value === 'object') {
381
+ return String(value.valueStr ?? value.label ?? value.name ?? value.value ?? '').trim()
382
+ }
383
+
384
+ return String(value).trim()
385
+ }
386
+
387
+ function isLegacyOpenStatusText(value) {
388
+ const text = normalizeLegacyStatusText(value)
389
+ if (!text) return false
390
+
391
+ return LEGACY_OPEN_STATUS_KEYWORDS.some(keyword => text.includes(keyword))
392
+ }
393
+
394
+ function isLegacyOpenStatusProp(prop = {}) {
395
+ return (
396
+ normalizeLegacyNumber(prop.rawValue) === 1 ||
397
+ normalizeLegacyNumber(prop.value) === 1 ||
398
+ normalizeLegacyNumber(prop.prop?.value) === 1 ||
399
+ isLegacyOpenStatusText(prop.rawValue) ||
400
+ isLegacyOpenStatusText(prop.value) ||
401
+ isLegacyOpenStatusText(prop.valueStr) ||
402
+ isLegacyOpenStatusText(prop.prop?.valueStr)
403
+ )
404
+ }
405
+
373
406
  function getLegacyStatusCounts(props = []) {
374
407
  const statusProps = props.filter(prop => prop && prop.isStatus)
375
408
  return {
376
409
  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
410
+ open: statusProps.filter(prop => isLegacyOpenStatusProp(prop)).length
411
+ }
412
+ }
413
+
414
+ function getLegacyOpenStatusProp(props = []) {
415
+ return props.find(prop => prop && prop.isStatus && isLegacyOpenStatusProp(prop))
416
+ }
417
+
418
+ function normalizeLegacyStatus(status, props = []) {
419
+ if (!status) {
420
+ return undefined
421
+ }
422
+
423
+ const statusCounts = getLegacyStatusCounts(props)
424
+ const openStatusProp = getLegacyOpenStatusProp(props)
425
+ const shouldUseOpenStatus =
426
+ statusCounts.open > 0 &&
427
+ normalizeLegacyNumber(status.value) !== 1 &&
428
+ openStatusProp
429
+
430
+ const displayStatus = shouldUseOpenStatus
431
+ ? {
432
+ value: 1,
433
+ label:
434
+ openStatusProp.prop?.valueStr ||
435
+ openStatusProp.valueStr ||
436
+ openStatusProp.name ||
437
+ openStatusProp.propName ||
438
+ '开',
439
+ valueStr:
440
+ openStatusProp.prop?.valueStr ||
441
+ openStatusProp.valueStr ||
442
+ openStatusProp.name ||
443
+ openStatusProp.propName ||
444
+ '开'
445
+ }
446
+ : status
447
+
448
+ return {
449
+ ...displayStatus,
450
+ total: status.total ?? statusCounts.total,
451
+ open: status.open ?? statusCounts.open
382
452
  }
383
453
  }
384
454
 
@@ -448,18 +518,11 @@ function normalizeLegacyEasyListRow(item = {}) {
448
518
  const props = Array.isArray(row.props)
449
519
  ? row.props.map(prop => normalizeLegacyEasyListProp(prop, row))
450
520
  : []
451
- const statusCounts = getLegacyStatusCounts(props)
452
521
 
453
522
  return removeUndefinedFields({
454
523
  ...row,
455
524
  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,
525
+ status: normalizeLegacyStatus(row.status, props),
463
526
  lineTime: row.lineTime || props.find(prop => prop.isImport && prop.valueAt)?.valueAt || row.updatedAt || null
464
527
  })
465
528
  }
@@ -141,11 +141,26 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
141
141
  name: '会议室空调',
142
142
  line: false,
143
143
  status: {
144
- value: 1,
145
- label: '制热',
146
- valueStr: '制热'
144
+ value: 0,
145
+ label: '解锁',
146
+ valueStr: '解锁'
147
147
  },
148
148
  props: [
149
+ {
150
+ id: 'twin-prop-lock',
151
+ propId: 'device-prop-lock',
152
+ propertyKey: 'lock',
153
+ name: '锁屏',
154
+ isStatus: true,
155
+ line: true,
156
+ value: 0,
157
+ valueStr: '解锁',
158
+ interval: '[["解锁","锁屏"],[0,1]]',
159
+ valueAt: '2026-04-25T06:29:00.000Z',
160
+ prop: {
161
+ id: 'device-prop-lock'
162
+ }
163
+ },
149
164
  {
150
165
  id: 'twin-prop-mode',
151
166
  propId: 'device-prop-mode',
@@ -183,15 +198,15 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
183
198
  })
184
199
 
185
200
  const row = response.data.rows[0]
186
- const modeProp = row.props[0]
187
- const electricProp = row.props[1]
201
+ const modeProp = row.props[1]
202
+ const electricProp = row.props[2]
188
203
 
189
204
  expect(row._id).toBe('twin-1')
190
205
  expect(row.status).toEqual({
191
206
  value: 1,
192
207
  label: '制热',
193
208
  valueStr: '制热',
194
- total: 1,
209
+ total: 2,
195
210
  open: 1
196
211
  })
197
212
  expect(modeProp).toEqual(