import React from 'react'; import { ValidatorForm, TextValidator, SelectValidator } from 'react-material-ui-form-validator'; import { Checkbox, Typography, Box, Link, withWidth, WithWidthProps } from '@material-ui/core'; import SaveIcon from '@material-ui/icons/Save'; import MenuItem from '@material-ui/core/MenuItem'; import Grid from '@material-ui/core/Grid'; import { redirectingAuthorizedFetch, withAuthenticatedContext, AuthenticatedContextProps } from "../authentication"; import { RestFormProps, FormActions, FormButton, BlockFormControlLabel } from '../components'; import { isIP, optional } from '../validators'; import { EMSESPSettings } from './EMSESPtypes'; import { boardProfileSelectItems } from './EMSESPBoardProfiles'; import { ENDPOINT_ROOT } from "../api"; export const BOARD_PROFILE_ENDPOINT = ENDPOINT_ROOT + "boardProfile"; type EMSESPSettingsFormProps = RestFormProps & AuthenticatedContextProps & WithWidthProps; interface EMSESPSettingsFormState { processing: boolean; } class EMSESPSettingsForm extends React.Component { state: EMSESPSettingsFormState = { processing: false } componentDidMount() { ValidatorForm.addValidationRule('isOptionalIP', optional(isIP)); } changeBoardProfile = (event: React.ChangeEvent) => { const { data, setData } = this.props; setData({ ...data, board_profile: event.target.value }); if (event.target.value === "CUSTOM") return; this.setState({ processing: true }); redirectingAuthorizedFetch(BOARD_PROFILE_ENDPOINT, { method: "POST", body: JSON.stringify({ code: event.target.value }), headers: { "Content-Type": "application/json", }, }) .then((response) => { if (response.status === 200) { return response.json(); } throw Error("Unexpected response code: " + response.status); }) .then((json) => { this.props.enqueueSnackbar("Profile loaded", { variant: 'success' }); setData({ ...data, led_gpio: json.led_gpio, dallas_gpio: json.dallas_gpio, rx_gpio: json.rx_gpio, tx_gpio: json.tx_gpio, pbutton_gpio: json.pbutton_gpio, board_profile: event.target.value }); this.setState({ processing: false }); }) .catch((error) => { this.props.enqueueSnackbar( error.message || "Problem fetching board profile", { variant: "warning" } ); this.setState({ processing: false }); }); }; render() { const { data, saveData, handleValueChange } = this.props; return ( Modify any of the EMS-ESP settings here. For help refer to the {'online documentation'}.

EMS Bus Off EMS EMS+ HT3 Hardware Service Key (0x0B) Modem (0x0D) Terminal (0x0A) Time Module (0x0F) Alarm Module (0x12)

Board Profile Select a pre-configured board layout to automatically set the GPIO pins, or set your own custom configuration {boardProfileSelectItems()} Custom... { (data.board_profile === "CUSTOM") && }

Options { data.dallas_gpio !== 0 && } label="Enable Dallas parasite mode" /> } { data.led_gpio !== 0 && } label = "Hide LED" /> } } label="Shower Timer" /> {/* } label="Shower Alert" /> */} } label="Enable API write commands" /> } label="Enable ADC" />

Syslog } label="Enable Syslog" /> { data.syslog_enabled && OFF ERR NOTICE INFO DEBUG ALL } label="Output EMS telegrams in raw format" /> }

} variant="contained" color="primary" type="submit"> Save
); } } export default withAuthenticatedContext(withWidth()(EMSESPSettingsForm));