Commit 0f150337397472a1b0deb117a7eeb649c9dbcfff
Committed by
GitHub
1 parent
96878b6d
Lwm2m: fix bug add new instance (#4554)
* Lwm2m: fix bug add new instance * Lwm2m: add KeyName default with instanceId
Showing
3 changed files
with
16 additions
and
7 deletions
@@ -23,6 +23,7 @@ import { | @@ -23,6 +23,7 @@ import { | ||
23 | BINDING_MODE, | 23 | BINDING_MODE, |
24 | BINDING_MODE_NAMES, | 24 | BINDING_MODE_NAMES, |
25 | getDefaultProfileConfig, | 25 | getDefaultProfileConfig, |
26 | + Instance, | ||
26 | INSTANCES, | 27 | INSTANCES, |
27 | KEY_NAME, | 28 | KEY_NAME, |
28 | Lwm2mProfileConfigModels, | 29 | Lwm2mProfileConfigModels, |
@@ -37,6 +38,7 @@ import { DeviceProfileService } from '@core/http/device-profile.service'; | @@ -37,6 +38,7 @@ import { DeviceProfileService } from '@core/http/device-profile.service'; | ||
37 | import { deepClone, isDefinedAndNotNull, isEmpty, isUndefined } from '@core/utils'; | 38 | import { deepClone, isDefinedAndNotNull, isEmpty, isUndefined } from '@core/utils'; |
38 | import { JsonArray, JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point'; | 39 | import { JsonArray, JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point'; |
39 | import { Direction } from '@shared/models/page/sort-order'; | 40 | import { Direction } from '@shared/models/page/sort-order'; |
41 | +import _ from 'lodash'; | ||
40 | 42 | ||
41 | @Component({ | 43 | @Component({ |
42 | selector: 'tb-profile-lwm2m-device-transport-configuration', | 44 | selector: 'tb-profile-lwm2m-device-transport-configuration', |
@@ -230,24 +232,30 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -230,24 +232,30 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
230 | const isNotZeroInstanceId = (instance) => !instance.includes('/0/'); | 232 | const isNotZeroInstanceId = (instance) => !instance.includes('/0/'); |
231 | return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId); | 233 | return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId); |
232 | } | 234 | } |
233 | - | ||
234 | private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => { | 235 | private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => { |
235 | const instancesPath = attribute.concat(telemetry) | 236 | const instancesPath = attribute.concat(telemetry) |
236 | .filter(instance => !instance.includes('/0/')) | 237 | .filter(instance => !instance.includes('/0/')) |
237 | .map(instance => instance.slice(1, instance.lastIndexOf('/'))) | 238 | .map(instance => instance.slice(1, instance.lastIndexOf('/'))) |
238 | .sort(this.sortPath); | 239 | .sort(this.sortPath); |
239 | - | ||
240 | new Set(instancesPath).forEach(path => { | 240 | new Set(instancesPath).forEach(path => { |
241 | const pathParameter = Array.from(path.split('/'), String); | 241 | const pathParameter = Array.from(path.split('/'), String); |
242 | const objectLwM2M = clientObserveAttrTelemetry.find(x => x.keyId === pathParameter[0]); | 242 | const objectLwM2M = clientObserveAttrTelemetry.find(x => x.keyId === pathParameter[0]); |
243 | if (objectLwM2M) { | 243 | if (objectLwM2M) { |
244 | - const instance = deepClone(objectLwM2M.instances[0]); | ||
245 | - instance.id = +pathParameter[1]; | 244 | + const instance = this.updateInInstanceKeyName (objectLwM2M.instances[0], +pathParameter[1]); |
246 | objectLwM2M.instances.push(instance); | 245 | objectLwM2M.instances.push(instance); |
247 | } | 246 | } |
248 | }); | 247 | }); |
249 | } | 248 | } |
250 | 249 | ||
250 | + private updateInInstanceKeyName = (instance: Instance, instanceId: number): Instance => { | ||
251 | + const instanceUpdate = deepClone(instance); | ||
252 | + instanceUpdate.id = instanceId; | ||
253 | + instanceUpdate.resources.forEach(resource => { | ||
254 | + resource.keyName = _.camelCase(resource.name + instanceUpdate.id); | ||
255 | + }) | ||
256 | + return instanceUpdate; | ||
257 | + } | ||
258 | + | ||
251 | private updateObserveAttrTelemetryObjects = (parameters: string[], objectLwM2MS: ObjectLwM2M[], | 259 | private updateObserveAttrTelemetryObjects = (parameters: string[], objectLwM2MS: ObjectLwM2M[], |
252 | nameParameter: string): void => { | 260 | nameParameter: string): void => { |
253 | parameters.forEach(parameter => { | 261 | parameters.forEach(parameter => { |
@@ -45,6 +45,7 @@ import { | @@ -45,6 +45,7 @@ import { | ||
45 | Lwm2mObjectAddInstancesData, | 45 | Lwm2mObjectAddInstancesData, |
46 | Lwm2mObjectAddInstancesDialogComponent | 46 | Lwm2mObjectAddInstancesDialogComponent |
47 | } from '@home/components/profile/device/lwm2m/lwm2m-object-add-instances-dialog.component'; | 47 | } from '@home/components/profile/device/lwm2m/lwm2m-object-add-instances-dialog.component'; |
48 | +import _ from 'lodash'; | ||
48 | 49 | ||
49 | @Component({ | 50 | @Component({ |
50 | selector: 'tb-profile-lwm2m-observe-attr-telemetry', | 51 | selector: 'tb-profile-lwm2m-observe-attr-telemetry', |
@@ -261,7 +262,6 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor | @@ -261,7 +262,6 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor | ||
261 | r.attribute = false; | 262 | r.attribute = false; |
262 | r.telemetry = false; | 263 | r.telemetry = false; |
263 | r.observe = false; | 264 | r.observe = false; |
264 | - r.keyName = {}; | ||
265 | r.attributeLwm2m = {}; | 265 | r.attributeLwm2m = {}; |
266 | }); | 266 | }); |
267 | const valueOld = this.instancesToSetId(instancesArray); | 267 | const valueOld = this.instancesToSetId(instancesArray); |
@@ -280,7 +280,8 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor | @@ -280,7 +280,8 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor | ||
280 | private addInstancesNew = (idsAdd: Set<number>, objectLwM2MFormGroup: FormGroup, instancesFormArray: FormArray, | 280 | private addInstancesNew = (idsAdd: Set<number>, objectLwM2MFormGroup: FormGroup, instancesFormArray: FormArray, |
281 | instanceNew: Instance): void => { | 281 | instanceNew: Instance): void => { |
282 | idsAdd.forEach(x => { | 282 | idsAdd.forEach(x => { |
283 | - this.pushInstance(instancesFormArray, x, instanceNew); | 283 | + instanceNew.resources.forEach(resource => {resource.keyName = _.camelCase(resource.name + x);}); |
284 | + this.pushInstance(instancesFormArray, x, deepClone(instanceNew as Instance)); | ||
284 | }); | 285 | }); |
285 | (instancesFormArray.controls as FormGroup[]).sort((a, b) => a.value.id - b.value.id); | 286 | (instancesFormArray.controls as FormGroup[]).sort((a, b) => a.value.id - b.value.id); |
286 | } | 287 | } |
@@ -246,7 +246,7 @@ export interface ResourceLwM2M { | @@ -246,7 +246,7 @@ export interface ResourceLwM2M { | ||
246 | observe: boolean; | 246 | observe: boolean; |
247 | attribute: boolean; | 247 | attribute: boolean; |
248 | telemetry: boolean; | 248 | telemetry: boolean; |
249 | - keyName: {}; | 249 | + keyName: string; |
250 | attributeLwm2m?: {}; | 250 | attributeLwm2m?: {}; |
251 | } | 251 | } |
252 | 252 |