Skip to content

Commit

Permalink
Merge pull request #1540 from telefonicaid/fix/store_device_commands_…
Browse files Browse the repository at this point in the history
…from_group

store in device commands from group after CB registration
  • Loading branch information
fgalan authored Dec 18, 2023
2 parents a60fb49 + e16ce23 commit 87f7d30
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fix: store commands from Group at Device level at provision device time
- Log device id when BadTimestamp error
2 changes: 1 addition & 1 deletion lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ function registerDevice(deviceObj, callback) {
deviceObj.subservice = deviceData.subservice;
deviceObj.type = deviceData.type;
deviceObj.staticAttributes = deviceObj.staticAttributes ? deviceObj.staticAttributes : [];
deviceObj.commands = deviceObj.commands ? deviceObj.commands : [];
deviceObj.commands = deviceData.commands ? deviceData.commands : [];
deviceObj.lazy = deviceObj.lazy ? deviceObj.lazy : [];
if ('apikey' in deviceData && deviceData.apikey !== undefined) {
deviceObj.apikey = deviceData.apikey;
Expand Down
60 changes: 60 additions & 0 deletions test/functional/testCases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,66 @@ const testCases = [
}
]
},
// 0200 - COMMANDS TESTS
{
describeName: '0200 - Simple group with commands',
provision: {
url: 'http://localhost:' + config.iota.server.port + '/iot/services',
method: 'POST',
json: {
services: [
{
resource: '/iot/json',
apikey: globalEnv.apikey,
entity_type: globalEnv.entity_type,
commands: [
{
name: 'cmd1',
type: 'command'
}
],
lazy: [],
attributes: [],
static_attributes: []
}
]
},
headers: {
'fiware-service': globalEnv.service,
'fiware-servicepath': globalEnv.servicePath
}
},
should: [
{
loglevel: 'fatal',
shouldName:
'A - WHEN sending not provisioned object_ids (measures) through http IT should store commands into Context Broker',
type: 'single',
measure: {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
qs: {
i: globalEnv.deviceId,
k: globalEnv.apikey
},
json: {
b: 10
}
},
expectation: {
id: globalEnv.entity_name,
type: globalEnv.entity_type,
b: {
value: 10,
type: 'string'
},
cmd1: {
type: 'command'
}
}
}
]
},
// 0300 - STATIC ATTRIBUTES TESTS
{
describeName:
Expand Down
2 changes: 2 additions & 0 deletions test/functional/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ function groupToIoTAConfigType(group, service, subservice) {
type.type = group.entity_type;
} else if (key === 'static_attributes') {
type.staticAttributes = group.static_attributes;
} else if (key === 'commands') {
type.commands = group.commands;
} else if (key !== 'resource') {
type[key] = group[key];
}
Expand Down

0 comments on commit 87f7d30

Please sign in to comment.