import { Component } from 'react'; import { ValidatorForm, TextValidator, SelectValidator } from 'react-material-ui-form-validator'; import { Checkbox, Typography, Box, Link, withWidth, WithWidthProps, Grid } from '@material-ui/core'; import SaveIcon from '@material-ui/icons/Save'; import MenuItem from '@material-ui/core/MenuItem'; import { redirectingAuthorizedFetch, withAuthenticatedContext, AuthenticatedContextProps } from '../authentication'; import { RestFormProps, FormActions, FormButton, BlockFormControlLabel } from '../components'; import { isIPv4, optional, isHostname, or } 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 Component { state: EMSESPSettingsFormState = { processing: false }; componentDidMount() { ValidatorForm.addValidationRule( 'isOptionalIPorHost', optional(or(isIPv4, isHostname)) ); } 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 ( Refer to the {' documentation'}  for information on each setting

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. Select "Custom..." to view or manually edit the values. {boardProfileSelectItems()} Custom... {data.board_profile === 'CUSTOM' && ( )}

General Options {data.led_gpio !== 0 && ( } label="Hide LED" /> )} {data.dallas_gpio !== 0 && ( } label="Use Dallas Sensor parasite power" /> )} } label="Enable ADC" /> } label="Run at a lower CPU clock speed" /> } label="Bypass Access Token authorization on API calls" /> } label="Enable Shower Timer" /> } label="Enable Shower Alert" />

Formatting Options "on"/"off" "ON"/"OFF" true/false 1/0 Text Number ID Number Name

Syslog } label="Enable Syslog" /> {data.syslog_enabled && ( OFF ERR NOTICE INFO DEBUG ALL } label="Output EMS telegrams as hexadecimal bytes" /> )}

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