nayota-show-sdk 1.3.72 → 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.72",
3
+ "version": "1.3.74",
4
4
  "description": "nayota-show-server rest-api",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -360,6 +360,98 @@ 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
+ 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
+
406
+ function getLegacyStatusCounts(props = []) {
407
+ const statusProps = props.filter(prop => prop && prop.isStatus)
408
+ return {
409
+ total: statusProps.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
452
+ }
453
+ }
454
+
363
455
  function normalizeLegacyEasyListProp(source = {}, row = {}) {
364
456
  const prop = withLegacyId(source.prop || {})
365
457
  const propId = source.propId || source.devicePropertyId || prop._id || source._id || source.id
@@ -430,6 +522,7 @@ function normalizeLegacyEasyListRow(item = {}) {
430
522
  return removeUndefinedFields({
431
523
  ...row,
432
524
  props,
525
+ status: normalizeLegacyStatus(row.status, props),
433
526
  lineTime: row.lineTime || props.find(prop => prop.isImport && prop.valueAt)?.valueAt || row.updatedAt || null
434
527
  })
435
528
  }
@@ -140,7 +140,27 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
140
140
  id: 'twin-1',
141
141
  name: '会议室空调',
142
142
  line: false,
143
+ status: {
144
+ value: 0,
145
+ label: '解锁',
146
+ valueStr: '解锁'
147
+ },
143
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
+ },
144
164
  {
145
165
  id: 'twin-prop-mode',
146
166
  propId: 'device-prop-mode',
@@ -178,10 +198,17 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
178
198
  })
179
199
 
180
200
  const row = response.data.rows[0]
181
- const modeProp = row.props[0]
182
- const electricProp = row.props[1]
201
+ const modeProp = row.props[1]
202
+ const electricProp = row.props[2]
183
203
 
184
204
  expect(row._id).toBe('twin-1')
205
+ expect(row.status).toEqual({
206
+ value: 1,
207
+ label: '制热',
208
+ valueStr: '制热',
209
+ total: 2,
210
+ open: 1
211
+ })
185
212
  expect(modeProp).toEqual(
186
213
  expect.objectContaining({
187
214
  _id: 'twin-prop-mode',