Farmbot-Web-App/frontend/devices/components/source_config_value.ts

31 lines
1.1 KiB
TypeScript

import {
Configuration, ConfigurationName, McuParams, McuParamName,
} from "farmbot";
import { SourceFbosConfig, SourceFwConfig } from "../interfaces";
import { FbosConfig } from "farmbot/dist/resources/configs/fbos";
import { FirmwareConfig } from "farmbot/dist/resources/configs/firmware";
export const sourceFbosConfigValue =
(apiConfig: FbosConfig | undefined, botConfig: Configuration,
): SourceFbosConfig =>
(setting: ConfigurationName) => {
const apiValue = apiConfig && apiConfig[setting as keyof FbosConfig];
const botValue = botConfig[setting];
return {
value: apiConfig ? apiValue : botValue,
consistent: apiConfig ? apiValue === botValue : true
};
};
export const sourceFwConfigValue =
(apiConfig: FirmwareConfig | undefined, botConfig: McuParams,
): SourceFwConfig =>
(setting: McuParamName) => {
const apiValue = apiConfig && apiConfig[setting];
const botValue = botConfig[setting];
return {
value: apiConfig ? apiValue : botValue,
consistent: apiConfig ? apiValue === botValue : true
};
};