refactoring
This commit is contained in:
parent
c4441eba72
commit
f97598ee08
@ -11,9 +11,9 @@ export abstract class GatewayConnectorVersionProcessor<BasicConfig> {
|
|||||||
|
|
||||||
getProcessedByVersion(): BasicConfig {
|
getProcessedByVersion(): BasicConfig {
|
||||||
if (this.isVersionUpdateNeeded()) {
|
if (this.isVersionUpdateNeeded()) {
|
||||||
return this.configVersion > this.gatewayVersion
|
return this.configVersion < this.gatewayVersion
|
||||||
? this.getDowngradedVersion()
|
? this.getUpgradedVersion()
|
||||||
: this.getUpgradedVersion();
|
: this.getDowngradedVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.connector.configurationJson as unknown as BasicConfig;
|
return this.connector.configurationJson as unknown as BasicConfig;
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
import {
|
import { isEqual } from '@core/utils';
|
||||||
GatewayConnectorVersionProcessor
|
|
||||||
} from '@home/components/widget/lib/gateway/abstract/gateway-connector-version-processor.abstract';
|
|
||||||
import {
|
import {
|
||||||
GatewayConnector,
|
GatewayConnector,
|
||||||
MQTTBasicConfig, MQTTBasicConfig_v3_5_2,
|
MQTTBasicConfig,
|
||||||
|
MQTTBasicConfig_v3_5_2,
|
||||||
MQTTLegacyBasicConfig,
|
MQTTLegacyBasicConfig,
|
||||||
RequestMappingData,
|
RequestMappingData,
|
||||||
RequestType,
|
RequestType,
|
||||||
} from '@home/components/widget/lib/gateway/gateway-widget.models';
|
} from '../gateway-widget.models';
|
||||||
import { isEqual } from '@core/utils';
|
import { MqttVersionMappingUtil } from '../utils/mqtt-version-mapping.util';
|
||||||
import { MqttVersionMappingUtil } from '@home/components/widget/lib/gateway/utils/mqtt-version-mapping.util';
|
import { GatewayConnectorVersionProcessor } from './gateway-connector-version-processor.abstract';
|
||||||
|
|
||||||
export class MqttVersionProcessor extends GatewayConnectorVersionProcessor<MQTTBasicConfig> {
|
export class MqttVersionProcessor extends GatewayConnectorVersionProcessor<MQTTBasicConfig> {
|
||||||
private readonly mqttRequestTypeKeys = Object.values(RequestType);
|
private readonly mqttRequestTypeKeys = Object.values(RequestType);
|
||||||
@ -20,7 +19,7 @@ export class MqttVersionProcessor extends GatewayConnectorVersionProcessor<MQTTB
|
|||||||
) {
|
) {
|
||||||
super(gatewayVersionStr, connector);
|
super(gatewayVersionStr, connector);
|
||||||
}
|
}
|
||||||
getUpgradedVersion(): MQTTBasicConfig {
|
getUpgradedVersion(): MQTTBasicConfig_v3_5_2 {
|
||||||
const {
|
const {
|
||||||
connectRequests,
|
connectRequests,
|
||||||
disconnectRequests,
|
disconnectRequests,
|
||||||
@ -41,13 +40,13 @@ export class MqttVersionProcessor extends GatewayConnectorVersionProcessor<MQTTB
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.mqttRequestTypeKeys.forEach((key: RequestType) => {
|
this.mqttRequestTypeKeys.forEach((key: RequestType) => {
|
||||||
const { [key]: removedKey, ...rest } = configurationJson as MQTTLegacyBasicConfig;
|
const { [key]: removedValue, ...rest } = configurationJson as MQTTLegacyBasicConfig;
|
||||||
configurationJson = { ...rest } as any;
|
configurationJson = { ...rest } as any;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.cleanUpConfigJson(configurationJson as MQTTBasicConfig_v3_5_2);
|
this.cleanUpConfigJson(configurationJson as MQTTBasicConfig_v3_5_2);
|
||||||
|
|
||||||
return configurationJson as MQTTBasicConfig;
|
return configurationJson as MQTTBasicConfig_v3_5_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDowngradedVersion(): MQTTLegacyBasicConfig {
|
getDowngradedVersion(): MQTTLegacyBasicConfig {
|
||||||
|
|||||||
@ -32,7 +32,9 @@ export abstract class AbstractMqttBasicConfigComponent<BasicConfig> implements C
|
|||||||
|
|
||||||
basicFormGroup: FormGroup;
|
basicFormGroup: FormGroup;
|
||||||
mappingTypes = MappingType;
|
mappingTypes = MappingType;
|
||||||
|
|
||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
|
|
||||||
private onChange: (value: BasicConfig) => void;
|
private onChange: (value: BasicConfig) => void;
|
||||||
private onTouched: () => void;
|
private onTouched: () => void;
|
||||||
|
|
||||||
|
|||||||
@ -80,8 +80,8 @@ export class MqttBasicConfigComponent extends AbstractMqttBasicConfigComponent<M
|
|||||||
maxNumberOfWorkers: broker.maxNumberOfWorkers,
|
maxNumberOfWorkers: broker.maxNumberOfWorkers,
|
||||||
maxMessageNumberPerWorker: broker.maxMessageNumberPerWorker,
|
maxMessageNumberPerWorker: broker.maxMessageNumberPerWorker,
|
||||||
} : {},
|
} : {},
|
||||||
mapping: mapping || [],
|
mapping: mapping ?? [],
|
||||||
broker: broker || {},
|
broker: broker ?? {},
|
||||||
requestsMapping: this.getRequestDataArray(requestsMapping as Record<RequestType, RequestMappingData[]>),
|
requestsMapping: this.getRequestDataArray(requestsMapping as Record<RequestType, RequestMappingData[]>),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -243,10 +243,6 @@ export class GatewayConnectorComponent extends PageComponent implements AfterVie
|
|||||||
delete value.class;
|
delete value.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.gatewayVersion && !value.configVersion) {
|
|
||||||
value.configVersion = this.gatewayVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
value.ts = Date.now();
|
value.ts = Date.now();
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@ -482,7 +478,7 @@ export class GatewayConnectorComponent extends PageComponent implements AfterVie
|
|||||||
value.configurationJson = {} as ConnectorBaseConfig;
|
value.configurationJson = {} as ConnectorBaseConfig;
|
||||||
}
|
}
|
||||||
value.basicConfig = value.configurationJson;
|
value.basicConfig = value.configurationJson;
|
||||||
this.updateConnector({...value, configVersion: this.gatewayVersion ?? ''});
|
this.updateConnector(value);
|
||||||
this.generate('basicConfig.broker.clientId');
|
this.generate('basicConfig.broker.clientId');
|
||||||
setTimeout(() => this.saveConnector());
|
setTimeout(() => this.saveConnector());
|
||||||
});
|
});
|
||||||
|
|||||||
@ -40,7 +40,7 @@ export class MqttVersionMappingUtil {
|
|||||||
['attributeNameExpressionSource', 'responseTopicQoS', 'extensionConfig'];
|
['attributeNameExpressionSource', 'responseTopicQoS', 'extensionConfig'];
|
||||||
|
|
||||||
static mapMappingToUpgradedVersion(
|
static mapMappingToUpgradedVersion(
|
||||||
mapping: LegacyConverterConnectorMapping[] | ConverterConnectorMapping[]
|
mapping: LegacyConverterConnectorMapping[]
|
||||||
): ConverterConnectorMapping[] {
|
): ConverterConnectorMapping[] {
|
||||||
return mapping?.map(({ converter, topicFilter, subscriptionQos = 1 }) => {
|
return mapping?.map(({ converter, topicFilter, subscriptionQos = 1 }) => {
|
||||||
const deviceInfo = converter.deviceInfo ?? this.extractConverterDeviceInfo(converter);
|
const deviceInfo = converter.deviceInfo ?? this.extractConverterDeviceInfo(converter);
|
||||||
@ -54,12 +54,12 @@ export class MqttVersionMappingUtil {
|
|||||||
this.cleanUpOldFields(newConverter);
|
this.cleanUpOldFields(newConverter);
|
||||||
|
|
||||||
return { converter: newConverter, topicFilter, subscriptionQos };
|
return { converter: newConverter, topicFilter, subscriptionQos };
|
||||||
});
|
}) as ConverterConnectorMapping[];
|
||||||
}
|
}
|
||||||
|
|
||||||
static mapRequestsToUpgradedVersion(
|
static mapRequestsToUpgradedVersion(
|
||||||
requestMapping: Record<RequestType,
|
requestMapping: Record<RequestType,
|
||||||
RequestMappingData[] | LegacyRequestMappingData[]>
|
LegacyRequestMappingData[]>
|
||||||
): Record<RequestType, RequestMappingData[]> {
|
): Record<RequestType, RequestMappingData[]> {
|
||||||
return this.mqttRequestTypeKeys.reduce((acc, key: RequestType) => {
|
return this.mqttRequestTypeKeys.reduce((acc, key: RequestType) => {
|
||||||
if (!requestMapping[key]) {
|
if (!requestMapping[key]) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user