From 3f2fd6f979d0b70db090d7bff48a54ead932867e Mon Sep 17 00:00:00 2001 From: deaflynx Date: Tue, 29 Apr 2025 17:39:54 +0300 Subject: [PATCH] UI: lwm2m observe strategy feature. --- ...ile-transport-configuration.component.html | 14 +++++++ ...ofile-transport-configuration.component.ts | 26 ++++++++++++- .../lwm2m/lwm2m-profile-config.models.ts | 39 ++++++++++++++++++- .../assets/locale/locale.constant-en_US.json | 9 +++++ 4 files changed, 85 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html index f4dbafb6e8..ac7d0677fa 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html @@ -20,6 +20,20 @@
+ + device-profile.lwm2m.observe-strategy.observe-strategy + + + {{ observeStrategyMap.get(lwm2mDeviceProfileFormGroup.get('observeStrategy').value)?.name | translate }} + + + {{ observeStrategyMap.get(strategy).name | translate }} + + {{ observeStrategyMap.get(strategy).description | translate }} + + + + object; @Input() @@ -102,6 +107,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro observeAttrTelemetry: [null], bootstrapServerUpdateEnable: [false], bootstrap: [[]], + observeStrategy: [null, []], clientLwM2mSettings: this.fb.group({ clientOnlyObserveAfterConnect: [1, []], useObject19ForOtaInfo: [false], @@ -173,6 +179,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro } }); + this.lwm2mDeviceProfileFormGroup.get('objectIds').valueChanges.pipe( + takeUntil(this.destroy$) + ).subscribe(value => this.updateObserveStrategy(value)); + this.lwm2mDeviceProfileFormGroup.valueChanges.pipe( takeUntil(this.destroy$) ).subscribe((value) => { @@ -261,6 +271,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value), bootstrap: this.configurationValue.bootstrap, bootstrapServerUpdateEnable: this.configurationValue.bootstrapServerUpdateEnable || false, + observeStrategy: this.configurationValue.observeAttr.observeStrategy || ObserveStrategy.SINGLE, clientLwM2mSettings: { clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect, useObject19ForOtaInfo: this.configurationValue.clientLwM2mSettings.useObject19ForOtaInfo ?? false, @@ -283,6 +294,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateStrategy').updateValueAndValidity({onlySelf: true}); this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateStrategy').updateValueAndValidity({onlySelf: true}); } + this.updateObserveStrategy(value); this.cd.markForCheck(); } @@ -427,6 +439,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro const telemetryArray: Array = []; const attributes: any = {}; const keyNameNew = {}; + const observeStrategyValue = val.length ? this.lwm2mDeviceProfileFormGroup.get('observeStrategy')?.value : ObserveStrategy.SINGLE; const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val)); observeJson.forEach(obj => { if (isDefinedAndNotNull(obj.attributes) && !isEmpty(obj.attributes)) { @@ -467,7 +480,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro attribute: attributeArray, telemetry: telemetryArray, keyName: this.sortObjectKeyPathJson(KEY_NAME, keyNameNew), - attributeLwm2m: attributes + attributeLwm2m: attributes, + observeStrategy: observeStrategyValue }; } @@ -568,4 +582,12 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro return this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings') as UntypedFormGroup; } + private updateObserveStrategy(value: ObjectLwM2M[]) { + if (value.length && !this.disabled) { + this.lwm2mDeviceProfileFormGroup.get('observeStrategy').enable({onlySelf: true}); + } else { + this.lwm2mDeviceProfileFormGroup.get('observeStrategy').disable({onlySelf: true}); + } + } + } diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts index 3972964a5b..48b6c3284c 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts @@ -136,6 +136,41 @@ export const ObjectIDVerTranslationMap = new Map( ] ); +export interface ObserveStrategyData { + name: string; + description: string; +} + +export enum ObserveStrategy { + SINGLE = 'SINGLE', + COMPOSITE_ALL = 'COMPOSITE_ALL', + COMPOSITE_BY_OBJECT = 'COMPOSITE_BY_OBJECT' +} + +export const ObserveStrategyMap = new Map([ + [ + ObserveStrategy.SINGLE, + { + name: 'device-profile.lwm2m.observe-strategy.single', + description: 'device-profile.lwm2m.observe-strategy.single-description' + } + ], + [ + ObserveStrategy.COMPOSITE_ALL, + { + name: 'device-profile.lwm2m.observe-strategy.composite-all', + description: 'device-profile.lwm2m.observe-strategy.composite-all-description' + } + ], + [ + ObserveStrategy.COMPOSITE_BY_OBJECT, + { + name: 'device-profile.lwm2m.observe-strategy.composite-by-object', + description: 'device-profile.lwm2m.observe-strategy.composite-by-object-description' + } + ] +]); + export interface ServerSecurityConfig { host?: string; port?: number; @@ -187,6 +222,7 @@ export interface ObservableAttributes { telemetry: string[]; keyName: {}; attributeLwm2m: AttributesNameValueMap; + observeStrategy: ObserveStrategy; } export function getDefaultProfileObserveAttrConfig(): ObservableAttributes { @@ -195,7 +231,8 @@ export function getDefaultProfileObserveAttrConfig(): ObservableAttributes { attribute: [], telemetry: [], keyName: {}, - attributeLwm2m: {} + attributeLwm2m: {}, + observeStrategy: ObserveStrategy.SINGLE }; } diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index b160a44b0e..91008c69a6 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -2209,6 +2209,15 @@ "v1-0": "1.0", "v1-1": "1.1", "v1-2": "1.2" + }, + "observe-strategy": { + "observe-strategy": "Observe strategy", + "single": "Single", + "single-description": "One resource equals one single observe request", + "composite-all": "Composite all", + "composite-all-description": "All resources in one composite observe request", + "composite-by-object": "Composite by objects", + "composite-by-object-description": "Grouped composite observe requests by object" } }, "snmp": {