Farmbot-Web-App/frontend/controls/state_to_props.ts

46 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

2017-06-29 12:54:02 -06:00
import { Everything } from "../interfaces";
import {
selectAllPeripherals,
2018-03-09 02:34:24 -07:00
selectAllWebcamFeeds,
2018-03-10 00:17:53 -07:00
selectAllSensors,
2018-07-19 23:48:32 -06:00
selectAllSensorReadings,
2020-02-28 09:35:32 -07:00
maybeGetTimeSettings,
2017-06-29 12:54:02 -06:00
} from "../resources/selectors";
import { Props } from "./interfaces";
2020-02-07 16:06:40 -07:00
import { validFwConfig, validFbosConfig } from "../util";
2018-04-12 17:55:38 -06:00
import { getWebAppConfigValue } from "../config_storage/actions";
2020-02-07 16:06:40 -07:00
import { getFirmwareConfig, getFbosConfig } from "../resources/getters";
2019-02-04 07:32:26 -07:00
import { uniq } from "lodash";
2019-12-27 11:37:54 -07:00
import { getEnv, getShouldDisplayFn } from "../farmware/state_to_props";
2020-02-07 16:06:40 -07:00
import { sourceFbosConfigValue } from "../devices/components/source_config_value";
import { isFwHardwareValue } from "../devices/components/firmware_hardware_support";
2017-06-29 12:54:02 -06:00
export function mapStateToProps(props: Everything): Props {
2018-03-09 02:34:24 -07:00
const fwConfig = validFwConfig(getFirmwareConfig(props.resources.index));
2019-04-09 18:45:51 -06:00
const { mcu_params } = props.bot.hardware;
2019-12-27 11:37:54 -07:00
const shouldDisplay = getShouldDisplayFn(props.resources.index, props.bot);
const env = getEnv(props.resources.index, shouldDisplay, props.bot);
2017-06-29 12:54:02 -06:00
2020-02-07 16:06:40 -07:00
const { configuration } = props.bot.hardware;
const fbosConfig = validFbosConfig(getFbosConfig(props.resources.index));
const sourceFbosConfig = sourceFbosConfigValue(fbosConfig, configuration);
const { value } = sourceFbosConfig("firmware_hardware");
const firmwareHardware = isFwHardwareValue(value) ? value : undefined;
2017-06-29 12:54:02 -06:00
return {
2019-04-09 18:45:51 -06:00
feeds: selectAllWebcamFeeds(props.resources.index),
2017-06-29 12:54:02 -06:00
dispatch: props.dispatch,
bot: props.bot,
2019-04-09 18:45:51 -06:00
peripherals: uniq(selectAllPeripherals(props.resources.index)),
sensors: uniq(selectAllSensors(props.resources.index)),
2018-03-09 02:34:24 -07:00
firmwareSettings: fwConfig || mcu_params,
2019-04-09 18:45:51 -06:00
getWebAppConfigVal: getWebAppConfigValue(() => props),
2019-04-09 19:29:25 -06:00
shouldDisplay,
2018-07-19 23:48:32 -06:00
sensorReadings: selectAllSensorReadings(props.resources.index),
2019-04-09 23:17:03 -06:00
timeSettings: maybeGetTimeSettings(props.resources.index),
2019-12-27 11:37:54 -07:00
env,
2020-02-07 16:06:40 -07:00
firmwareHardware,
2017-06-29 12:54:02 -06:00
};
}