nayota-show-sdk 1.3.96 → 1.3.97
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 +8 -0
- package/package.json +1 -1
- package/utils/iot-module-specs.js +34 -0
- package/utils/iot-module-specs.test.js +51 -0
package/api/devices.js
CHANGED
|
@@ -399,6 +399,10 @@ export function getPropHistoryData(data) {
|
|
|
399
399
|
* }
|
|
400
400
|
*/
|
|
401
401
|
export function updateDepart(data) {
|
|
402
|
+
if (shouldUseIot('updateDepart')) {
|
|
403
|
+
return executeIotModuleAction(MODULE_NAME, 'updateDepart', data)
|
|
404
|
+
}
|
|
405
|
+
|
|
402
406
|
return requestShow({
|
|
403
407
|
url: '/devices/updateDepart',
|
|
404
408
|
method: 'post',
|
|
@@ -407,6 +411,10 @@ export function updateDepart(data) {
|
|
|
407
411
|
}
|
|
408
412
|
|
|
409
413
|
export function updateProp(data) {
|
|
414
|
+
if (shouldUseIot('updateProp')) {
|
|
415
|
+
return executeIotModuleAction(MODULE_NAME, 'updateProp', data)
|
|
416
|
+
}
|
|
417
|
+
|
|
410
418
|
return requestShow({
|
|
411
419
|
url: '/devices/updateProp',
|
|
412
420
|
method: 'post',
|
package/package.json
CHANGED
|
@@ -1195,6 +1195,40 @@ export const iotModuleSpecs = {
|
|
|
1195
1195
|
message: data?.message ?? payload?.message
|
|
1196
1196
|
})
|
|
1197
1197
|
}
|
|
1198
|
+
},
|
|
1199
|
+
updateDepart: {
|
|
1200
|
+
toRequest(data = {}) {
|
|
1201
|
+
return {
|
|
1202
|
+
url: '/devices/updateDepart',
|
|
1203
|
+
method: 'post',
|
|
1204
|
+
data
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
fromResponse(response) {
|
|
1208
|
+
const payload = response && response.data && response.status ? response.data : response
|
|
1209
|
+
const data = payload?.data !== undefined ? payload.data : payload
|
|
1210
|
+
return removeUndefinedFields({
|
|
1211
|
+
code: Number(data?.code ?? payload?.code ?? 0),
|
|
1212
|
+
message: data?.message ?? payload?.message ?? '更新成功'
|
|
1213
|
+
})
|
|
1214
|
+
}
|
|
1215
|
+
},
|
|
1216
|
+
updateProp: {
|
|
1217
|
+
toRequest(data = {}) {
|
|
1218
|
+
return {
|
|
1219
|
+
url: '/devices/updateProp',
|
|
1220
|
+
method: 'post',
|
|
1221
|
+
data
|
|
1222
|
+
}
|
|
1223
|
+
},
|
|
1224
|
+
fromResponse(response) {
|
|
1225
|
+
const payload = response && response.data && response.status ? response.data : response
|
|
1226
|
+
const data = payload?.data !== undefined ? payload.data : payload
|
|
1227
|
+
return removeUndefinedFields({
|
|
1228
|
+
code: Number(data?.code ?? payload?.code ?? 0),
|
|
1229
|
+
message: data?.message ?? payload?.message ?? '更新成功'
|
|
1230
|
+
})
|
|
1231
|
+
}
|
|
1198
1232
|
}
|
|
1199
1233
|
}
|
|
1200
1234
|
},
|
|
@@ -735,3 +735,54 @@ describe('iotModuleSpecs devices getPropHistoryData legacy compatibility', () =>
|
|
|
735
735
|
})
|
|
736
736
|
})
|
|
737
737
|
})
|
|
738
|
+
|
|
739
|
+
describe('iotModuleSpecs devices legacy mutation compatibility', () => {
|
|
740
|
+
const devices = iotModuleSpecs.devices.operations
|
|
741
|
+
|
|
742
|
+
test('posts updateDepart to the v2 legacy-compatible endpoint', () => {
|
|
743
|
+
const payload = {
|
|
744
|
+
deviceIds: ['twin-1', 'twin-2'],
|
|
745
|
+
depart: 'hierarchy-1'
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const request = devices.updateDepart.toRequest(payload)
|
|
749
|
+
|
|
750
|
+
expect(request).toEqual({
|
|
751
|
+
url: '/devices/updateDepart',
|
|
752
|
+
method: 'post',
|
|
753
|
+
data: payload
|
|
754
|
+
})
|
|
755
|
+
|
|
756
|
+
expect(devices.updateDepart.fromResponse({ code: 0 })).toEqual({
|
|
757
|
+
code: 0,
|
|
758
|
+
message: '更新成功'
|
|
759
|
+
})
|
|
760
|
+
})
|
|
761
|
+
|
|
762
|
+
test('posts updateProp to the v2 legacy-compatible endpoint', () => {
|
|
763
|
+
const payload = {
|
|
764
|
+
deviceId: 'twin-1',
|
|
765
|
+
iotDeviceId: 'device-1',
|
|
766
|
+
props: [
|
|
767
|
+
{
|
|
768
|
+
type: 'Operate',
|
|
769
|
+
address: 'powerSwitch',
|
|
770
|
+
name: '开关'
|
|
771
|
+
}
|
|
772
|
+
]
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
const request = devices.updateProp.toRequest(payload)
|
|
776
|
+
|
|
777
|
+
expect(request).toEqual({
|
|
778
|
+
url: '/devices/updateProp',
|
|
779
|
+
method: 'post',
|
|
780
|
+
data: payload
|
|
781
|
+
})
|
|
782
|
+
|
|
783
|
+
expect(devices.updateProp.fromResponse({ code: 0, message: '更新成功' })).toEqual({
|
|
784
|
+
code: 0,
|
|
785
|
+
message: '更新成功'
|
|
786
|
+
})
|
|
787
|
+
})
|
|
788
|
+
})
|