diff --git a/ui-ngx/src/app/modules/home/components/home-components.module.ts b/ui-ngx/src/app/modules/home/components/home-components.module.ts
index 3cfb4c19dc..735e11c2c8 100644
--- a/ui-ngx/src/app/modules/home/components/home-components.module.ts
+++ b/ui-ngx/src/app/modules/home/components/home-components.module.ts
@@ -141,6 +141,7 @@ import { DashboardImageDialogComponent } from '@home/components/dashboard-page/d
import { WidgetContainerComponent } from '@home/components/widget/widget-container.component';
import { SnmpDeviceProfileTransportModule } from '@home/components/profile/device/snpm/snmp-device-profile-transport.module';
import { DeviceCredentialsModule } from '@home/components/device/device-credentials.module';
+import { PowerModeSettingComponent } from '@home/components/profile/device/common/power-mode-setting.component';
@NgModule({
declarations:
@@ -259,7 +260,8 @@ import { DeviceCredentialsModule } from '@home/components/device/device-credenti
DashboardStateDialogComponent,
DashboardImageDialogComponent,
EmbedDashboardDialogComponent,
- DisplayWidgetTypesPanelComponent
+ DisplayWidgetTypesPanelComponent,
+ PowerModeSettingComponent
],
imports: [
CommonModule,
@@ -369,7 +371,8 @@ import { DeviceCredentialsModule } from '@home/components/device/device-credenti
DashboardStateDialogComponent,
DashboardImageDialogComponent,
EmbedDashboardDialogComponent,
- DisplayWidgetTypesPanelComponent
+ DisplayWidgetTypesPanelComponent,
+ PowerModeSettingComponent
],
providers: [
WidgetComponentService,
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.html
index 1399b95e67..8e1680ea46 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.html
+++ b/ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.html
@@ -84,49 +84,8 @@
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.ts
index 3929292742..09fa6320ec 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.ts
@@ -35,7 +35,7 @@ import {
import { isDefinedAndNotNull } from '@core/utils';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
-import { PowerMode, PowerModeTranslationMap } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models';
+import { PowerMode } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models';
@Component({
selector: 'tb-coap-device-profile-transport-configuration',
@@ -55,9 +55,6 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
transportPayloadTypes = Object.values(TransportPayloadType);
transportPayloadTypeTranslations = transportPayloadTypeTranslationMap;
- powerMods = Object.values(PowerMode);
- powerModeTranslationMap = PowerModeTranslationMap;
-
coapTransportConfigurationFormGroup: FormGroup;
private destroy$ = new Subject();
@@ -114,21 +111,6 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
).subscribe(coapDeviceType => {
this.updateCoapDeviceTypeBasedControls(coapDeviceType, true);
});
- this.coapTransportConfigurationFormGroup.get('clientSettings.powerMode').valueChanges.pipe(
- takeUntil(this.destroy$)
- ).subscribe((powerMode: PowerMode) => {
- if (powerMode === PowerMode.E_DRX) {
- this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').enable({emitEvent: false});
- this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').enable({emitEvent: false});
- this.disablePSKMode();
- } else if (powerMode === PowerMode.PSM) {
- this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').enable({emitEvent: false});
- this.disableEdrxMode();
- } else {
- this.disableEdrxMode();
- this.disablePSKMode();
- }
- });
this.coapTransportConfigurationFormGroup.valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe(() => {
@@ -152,6 +134,9 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
return transportPayloadType === TransportPayloadType.PROTOBUF;
}
+ get clientSettingsFormGroup(): FormGroup {
+ return this.coapTransportConfigurationFormGroup.get('clientSettings') as FormGroup;
+ }
private updateCoapDeviceTypeBasedControls(type: CoapTransportDeviceType, forceUpdated = false) {
const coapDeviceTypeConfigurationFormGroup = this.coapTransportConfigurationFormGroup
@@ -201,16 +186,4 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
}
this.propagateChange(configuration);
}
-
- private disablePSKMode() {
- this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').disable({emitEvent: false});
- this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').reset(0, {emitEvent: false});
- }
-
- private disableEdrxMode() {
- this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').disable({emitEvent: false});
- this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').reset(0, {emitEvent: false});
- this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').disable({emitEvent: false});
- this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').reset(0, {emitEvent: false});
- }
}
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.html b/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.html
new file mode 100644
index 0000000000..8920001535
--- /dev/null
+++ b/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.html
@@ -0,0 +1,63 @@
+
+
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.ts
new file mode 100644
index 0000000000..cae224ad2e
--- /dev/null
+++ b/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.ts
@@ -0,0 +1,75 @@
+///
+/// Copyright © 2016-2021 The Thingsboard Authors
+///
+/// Licensed under the Apache License, Version 2.0 (the "License");
+/// you may not use this file except in compliance with the License.
+/// You may obtain a copy of the License at
+///
+/// http://www.apache.org/licenses/LICENSE-2.0
+///
+/// Unless required by applicable law or agreed to in writing, software
+/// distributed under the License is distributed on an "AS IS" BASIS,
+/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+/// See the License for the specific language governing permissions and
+/// limitations under the License.
+///
+
+import { Component, Input, OnDestroy, OnInit } from '@angular/core';
+import { FormGroup } from '@angular/forms';
+import { PowerMode, PowerModeTranslationMap } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models';
+import { takeUntil } from 'rxjs/operators';
+import { Subject } from 'rxjs';
+
+@Component({
+ selector: 'tb-power-mode-settings',
+ templateUrl: './power-mode-setting.component.html',
+ styleUrls: []
+})
+export class PowerModeSettingComponent implements OnInit, OnDestroy {
+
+ powerMods = Object.values(PowerMode);
+ powerModeTranslationMap = PowerModeTranslationMap;
+
+ private destroy$ = new Subject();
+
+ @Input()
+ parentForm: FormGroup;
+
+ @Input()
+ isDeviceSetting = false;
+
+ ngOnInit() {
+ this.parentForm.get('powerMode').valueChanges.pipe(
+ takeUntil(this.destroy$)
+ ).subscribe((powerMode: PowerMode) => {
+ if (powerMode === PowerMode.E_DRX) {
+ this.parentForm.get('edrxCycle').enable({emitEvent: false});
+ this.parentForm.get('pagingTransmissionWindow').enable({emitEvent: false});
+ this.disablePSKMode();
+ } else if (powerMode === PowerMode.PSM) {
+ this.parentForm.get('psmActivityTimer').enable({emitEvent: false});
+ this.disableEdrxMode();
+ } else {
+ this.disableEdrxMode();
+ this.disablePSKMode();
+ }
+ });
+ }
+
+ ngOnDestroy() {
+ this.destroy$.next();
+ this.destroy$.complete();
+ }
+
+ private disablePSKMode() {
+ this.parentForm.get('psmActivityTimer').disable({emitEvent: false});
+ this.parentForm.get('psmActivityTimer').reset(0, {emitEvent: false});
+ }
+
+ private disableEdrxMode() {
+ this.parentForm.get('edrxCycle').disable({emitEvent: false});
+ this.parentForm.get('edrxCycle').reset(0, {emitEvent: false});
+ this.parentForm.get('pagingTransmissionWindow').disable({emitEvent: false});
+ this.parentForm.get('pagingTransmissionWindow').reset(0, {emitEvent: false});
+ }
+}
diff --git a/ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.html b/ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.html
index 5010726b5b..615eeea493 100644
--- a/ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.html
+++ b/ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.html
@@ -16,48 +16,6 @@
-->
diff --git a/ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.ts b/ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.ts
index 9f01376874..046585e00e 100644
--- a/ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.ts
+++ b/ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.ts
@@ -24,7 +24,6 @@ import {
DeviceTransportConfiguration,
DeviceTransportType
} from '@shared/models/device.models';
-import { PowerMode, PowerModeTranslationMap } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { isDefinedAndNotNull } from '@core/utils';
@@ -43,9 +42,6 @@ export class CoapDeviceTransportConfigurationComponent implements ControlValueAc
coapDeviceTransportForm: FormGroup;
- powerMods = Object.values(PowerMode);
- powerModeTranslationMap = PowerModeTranslationMap;
-
private requiredValue: boolean;
get required(): boolean {
return this.requiredValue;
@@ -79,21 +75,6 @@ export class CoapDeviceTransportConfigurationComponent implements ControlValueAc
psmActivityTimer: [{disabled: true, value: 0}, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]],
pagingTransmissionWindow: [{disabled: true, value: 0}, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]]
});
- this.coapDeviceTransportForm.get('powerMode').valueChanges.pipe(
- takeUntil(this.destroy$)
- ).subscribe((powerMode: PowerMode) => {
- if (powerMode === PowerMode.E_DRX) {
- this.coapDeviceTransportForm.get('edrxCycle').enable({emitEvent: false});
- this.coapDeviceTransportForm.get('pagingTransmissionWindow').enable({emitEvent: false});
- this.disablePSKMode();
- } else if (powerMode === PowerMode.PSM) {
- this.coapDeviceTransportForm.get('psmActivityTimer').enable({emitEvent: false});
- this.disableEdrxMode();
- } else {
- this.disableEdrxMode();
- this.disablePSKMode();
- }
- });
this.coapDeviceTransportForm.valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe(() => {
@@ -135,16 +116,4 @@ export class CoapDeviceTransportConfigurationComponent implements ControlValueAc
}
this.propagateChange(configuration);
}
-
- private disablePSKMode() {
- this.coapDeviceTransportForm.get('psmActivityTimer').disable({emitEvent: false});
- this.coapDeviceTransportForm.get('psmActivityTimer').reset(0, {emitEvent: false});
- }
-
- private disableEdrxMode() {
- this.coapDeviceTransportForm.get('edrxCycle').disable({emitEvent: false});
- this.coapDeviceTransportForm.get('edrxCycle').reset(0, {emitEvent: false});
- this.coapDeviceTransportForm.get('pagingTransmissionWindow').disable({emitEvent: false});
- this.coapDeviceTransportForm.get('pagingTransmissionWindow').reset(0, {emitEvent: false});
- }
}
diff --git a/ui-ngx/src/app/shared/models/device.models.ts b/ui-ngx/src/app/shared/models/device.models.ts
index a45ef05170..fb1426b15b 100644
--- a/ui-ngx/src/app/shared/models/device.models.ts
+++ b/ui-ngx/src/app/shared/models/device.models.ts
@@ -361,6 +361,9 @@ export function createDeviceProfileTransportConfiguration(type: DeviceTransportT
coapDeviceTypeConfiguration: {
coapDeviceType: CoapTransportDeviceType.DEFAULT,
transportPayloadTypeConfiguration: {transportPayloadType: TransportPayloadType.JSON}
+ },
+ clientSettings: {
+ powerMode: PowerMode.DRX
}
};
transportConfiguration = {...coapTransportConfiguration, type: DeviceTransportType.COAP};
@@ -395,7 +398,9 @@ export function createDeviceTransportConfiguration(type: DeviceTransportType): D
transportConfiguration = {...mqttTransportConfiguration, type: DeviceTransportType.MQTT};
break;
case DeviceTransportType.COAP:
- const coapTransportConfiguration: CoapDeviceTransportConfiguration = {};
+ const coapTransportConfiguration: CoapDeviceTransportConfiguration = {
+ powerMode: null
+ };
transportConfiguration = {...coapTransportConfiguration, type: DeviceTransportType.COAP};
break;
case DeviceTransportType.LWM2M:
@@ -582,7 +587,6 @@ export interface CoapDeviceTransportConfiguration {
edrxCycle?: number;
pagingTransmissionWindow?: number;
psmActivityTimer?: number;
- [key: string]: any;
}
export interface Lwm2mDeviceTransportConfiguration {