|
|
|
@ -35,6 +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'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'tb-coap-device-profile-transport-configuration', |
|
|
|
@ -48,15 +49,16 @@ import { takeUntil } from 'rxjs/operators'; |
|
|
|
}) |
|
|
|
export class CoapDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, OnDestroy { |
|
|
|
|
|
|
|
coapTransportDeviceTypes = Object.keys(CoapTransportDeviceType); |
|
|
|
|
|
|
|
coapTransportDeviceTypes = Object.values(CoapTransportDeviceType); |
|
|
|
coapTransportDeviceTypeTranslations = coapDeviceTypeTranslationMap; |
|
|
|
|
|
|
|
transportPayloadTypes = Object.keys(TransportPayloadType); |
|
|
|
|
|
|
|
transportPayloadTypes = Object.values(TransportPayloadType); |
|
|
|
transportPayloadTypeTranslations = transportPayloadTypeTranslationMap; |
|
|
|
|
|
|
|
coapDeviceProfileTransportConfigurationFormGroup: FormGroup; |
|
|
|
powerMods = Object.values(PowerMode); |
|
|
|
powerModeTranslationMap = PowerModeTranslationMap; |
|
|
|
|
|
|
|
coapTransportConfigurationFormGroup: FormGroup; |
|
|
|
|
|
|
|
private destroy$ = new Subject(); |
|
|
|
private requiredValue: boolean; |
|
|
|
@ -95,19 +97,48 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control |
|
|
|
} |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
this.coapDeviceProfileTransportConfigurationFormGroup = this.fb.group({ |
|
|
|
this.coapTransportConfigurationFormGroup = this.fb.group({ |
|
|
|
coapDeviceTypeConfiguration: this.fb.group({ |
|
|
|
coapDeviceType: [CoapTransportDeviceType.DEFAULT, Validators.required], |
|
|
|
transportPayloadTypeConfiguration: this.transportPayloadTypeConfiguration |
|
|
|
}) |
|
|
|
} |
|
|
|
coapDeviceType: [CoapTransportDeviceType.DEFAULT, Validators.required], |
|
|
|
transportPayloadTypeConfiguration: this.transportPayloadTypeConfiguration, |
|
|
|
}), |
|
|
|
clientSettings: this.fb.group({ |
|
|
|
powerMode: [PowerMode.DRX, Validators.required], |
|
|
|
edrxCycle: [{disabled: true, value: 0}], |
|
|
|
psmActivityTimer: [{disabled: true, value: 0}], |
|
|
|
pagingTransmissionWindow: [{disabled: true, value: 0}] |
|
|
|
})} |
|
|
|
); |
|
|
|
this.coapDeviceProfileTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').valueChanges.pipe( |
|
|
|
this.coapTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').valueChanges.pipe( |
|
|
|
takeUntil(this.destroy$) |
|
|
|
).subscribe(coapDeviceType => { |
|
|
|
this.updateCoapDeviceTypeBasedControls(coapDeviceType, true); |
|
|
|
}); |
|
|
|
this.coapDeviceProfileTransportConfigurationFormGroup.valueChanges.pipe( |
|
|
|
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.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle') |
|
|
|
.setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow') |
|
|
|
.setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]); |
|
|
|
this.clearValidatorsPSKMode(); |
|
|
|
} else if (powerMode === PowerMode.PSM) { |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').enable({emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer') |
|
|
|
.setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]); |
|
|
|
this.clearValidatorsEdrxMode(); |
|
|
|
} else { |
|
|
|
this.clearValidatorsEdrxMode(); |
|
|
|
this.clearValidatorsPSKMode(); |
|
|
|
} |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').updateValueAndValidity({emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').updateValueAndValidity({emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').updateValueAndValidity({emitEvent: false}); |
|
|
|
}); |
|
|
|
this.coapTransportConfigurationFormGroup.valueChanges.pipe( |
|
|
|
takeUntil(this.destroy$) |
|
|
|
).subscribe(() => { |
|
|
|
this.updateModel(); |
|
|
|
@ -120,19 +151,19 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control |
|
|
|
} |
|
|
|
|
|
|
|
get coapDeviceTypeDefault(): boolean { |
|
|
|
const coapDeviceType = this.coapDeviceProfileTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').value; |
|
|
|
const coapDeviceType = this.coapTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').value; |
|
|
|
return coapDeviceType === CoapTransportDeviceType.DEFAULT; |
|
|
|
} |
|
|
|
|
|
|
|
get protoPayloadType(): boolean { |
|
|
|
const transportPayloadTypePath = 'coapDeviceTypeConfiguration.transportPayloadTypeConfiguration.transportPayloadType'; |
|
|
|
const transportPayloadType = this.coapDeviceProfileTransportConfigurationFormGroup.get(transportPayloadTypePath).value; |
|
|
|
const transportPayloadType = this.coapTransportConfigurationFormGroup.get(transportPayloadTypePath).value; |
|
|
|
return transportPayloadType === TransportPayloadType.PROTOBUF; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private updateCoapDeviceTypeBasedControls(type: CoapTransportDeviceType, forceUpdated = false) { |
|
|
|
const coapDeviceTypeConfigurationFormGroup = this.coapDeviceProfileTransportConfigurationFormGroup |
|
|
|
const coapDeviceTypeConfigurationFormGroup = this.coapTransportConfigurationFormGroup |
|
|
|
.get('coapDeviceTypeConfiguration') as FormGroup; |
|
|
|
if (forceUpdated) { |
|
|
|
coapDeviceTypeConfigurationFormGroup.patchValue({ |
|
|
|
@ -149,26 +180,41 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control |
|
|
|
setDisabledState(isDisabled: boolean): void { |
|
|
|
this.disabled = isDisabled; |
|
|
|
if (this.disabled) { |
|
|
|
this.coapDeviceProfileTransportConfigurationFormGroup.disable({emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.disable({emitEvent: false}); |
|
|
|
} else { |
|
|
|
this.coapDeviceProfileTransportConfigurationFormGroup.enable({emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.enable({emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.powerMode').updateValueAndValidity({onlySelf: true}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
writeValue(value: CoapDeviceProfileTransportConfiguration | null): void { |
|
|
|
if (isDefinedAndNotNull(value)) { |
|
|
|
this.coapDeviceProfileTransportConfigurationFormGroup.patchValue(value, {emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.patchValue(value, {emitEvent: false}); |
|
|
|
this.updateCoapDeviceTypeBasedControls(value.coapDeviceTypeConfiguration?.coapDeviceType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private updateModel() { |
|
|
|
let configuration: DeviceProfileTransportConfiguration = null; |
|
|
|
if (this.coapDeviceProfileTransportConfigurationFormGroup.valid) { |
|
|
|
configuration = this.coapDeviceProfileTransportConfigurationFormGroup.value; |
|
|
|
if (this.coapTransportConfigurationFormGroup.valid) { |
|
|
|
configuration = this.coapTransportConfigurationFormGroup.value; |
|
|
|
configuration.type = DeviceTransportType.COAP; |
|
|
|
} |
|
|
|
this.propagateChange(configuration); |
|
|
|
} |
|
|
|
|
|
|
|
private clearValidatorsPSKMode() { |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').disable({emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').reset(0, {emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').clearValidators(); |
|
|
|
} |
|
|
|
|
|
|
|
private clearValidatorsEdrxMode() { |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').disable({emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').reset(0, {emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').clearValidators(); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').disable({emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').reset(0, {emitEvent: false}); |
|
|
|
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').clearValidators(); |
|
|
|
} |
|
|
|
} |
|
|
|
|