2017-06-29 12:54:02 -06:00
|
|
|
import * as React from "react";
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
import { HardwareSettings } from "./components/hardware_settings";
|
|
|
|
import { FarmbotOsSettings } from "./components/farmbot_os_settings";
|
2018-01-20 07:46:44 -07:00
|
|
|
import { Page, Col, Row } from "../ui/index";
|
2017-06-29 12:54:02 -06:00
|
|
|
import { mapStateToProps } from "./state_to_props";
|
|
|
|
import { Props } from "./interfaces";
|
2017-09-26 13:05:01 -06:00
|
|
|
import { ConnectivityPanel } from "./connectivity/index";
|
2017-09-27 21:41:34 -06:00
|
|
|
import {
|
2017-09-28 10:15:55 -06:00
|
|
|
botToMQTT, botToAPI, browserToMQTT, botToFirmware, browserToAPI
|
2017-09-27 21:41:34 -06:00
|
|
|
} from "./connectivity/status_checks";
|
2017-09-28 10:15:55 -06:00
|
|
|
import { Diagnosis, DiagnosisName } from "./connectivity/diagnosis";
|
2017-09-26 13:05:01 -06:00
|
|
|
import { StatusRowProps } from "./connectivity/connectivity_row";
|
2017-11-01 08:11:18 -06:00
|
|
|
import { resetConnectionInfo } from "./actions";
|
2017-11-30 20:43:35 -07:00
|
|
|
import { PinBindings } from "./components/pin_bindings";
|
2018-06-18 15:12:00 -06:00
|
|
|
import { selectAllDiagnosticDumps } from "../resources/selectors";
|
2017-09-25 12:37:24 -06:00
|
|
|
|
2017-06-29 12:54:02 -06:00
|
|
|
@connect(mapStateToProps)
|
2017-09-25 16:04:33 -06:00
|
|
|
export class Devices extends React.Component<Props, {}> {
|
|
|
|
state = { online: navigator.onLine };
|
2017-09-26 09:26:42 -06:00
|
|
|
|
|
|
|
/** A record of all the things we know about connectivity right now. */
|
2017-09-28 10:15:55 -06:00
|
|
|
get flags(): Record<DiagnosisName, StatusRowProps> {
|
2017-09-27 21:41:34 -06:00
|
|
|
const fwVersion = this.props.bot.hardware
|
|
|
|
.informational_settings.firmware_version;
|
2017-10-02 08:58:03 -06:00
|
|
|
|
2017-09-26 09:26:42 -06:00
|
|
|
return {
|
2017-10-03 14:59:39 -06:00
|
|
|
userMQTT: browserToMQTT(this.props.userToMqtt),
|
2017-10-02 08:58:03 -06:00
|
|
|
userAPI: browserToAPI(this.props.userToApi),
|
|
|
|
botMQTT: botToMQTT(this.props.botToMqtt),
|
2017-10-03 14:59:39 -06:00
|
|
|
botAPI: botToAPI(this.props.deviceAccount.body.last_saw_api),
|
2017-09-28 10:15:55 -06:00
|
|
|
botFirmware: botToFirmware(fwVersion),
|
2017-09-26 09:26:42 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Shuffle these around to change the ordering of the status table. */
|
|
|
|
get rowData(): StatusRowProps[] {
|
2017-09-27 21:41:34 -06:00
|
|
|
return [
|
2017-09-28 10:15:55 -06:00
|
|
|
this.flags.userAPI,
|
2017-09-27 21:41:34 -06:00
|
|
|
this.flags.userMQTT,
|
|
|
|
this.flags.botMQTT,
|
|
|
|
this.flags.botAPI,
|
2017-09-28 10:15:55 -06:00
|
|
|
this.flags.botFirmware,
|
2017-09-27 21:41:34 -06:00
|
|
|
];
|
2017-09-25 12:37:24 -06:00
|
|
|
}
|
|
|
|
|
2017-09-26 13:05:01 -06:00
|
|
|
refresh = () => {
|
2018-03-13 16:37:24 -06:00
|
|
|
this.props.dispatch(resetConnectionInfo());
|
2017-09-26 13:05:01 -06:00
|
|
|
};
|
|
|
|
|
2017-06-29 12:54:02 -06:00
|
|
|
render() {
|
|
|
|
if (this.props.auth) {
|
2018-01-24 17:32:50 -07:00
|
|
|
const { botToMqtt } = this.props;
|
|
|
|
const botToMqttStatus = botToMqtt ? botToMqtt.state : "down";
|
2018-01-25 13:10:50 -07:00
|
|
|
const botToMqttLastSeen = (botToMqtt && botToMqttStatus === "up")
|
|
|
|
? botToMqtt.at
|
|
|
|
: "";
|
2017-06-29 12:54:02 -06:00
|
|
|
return <Page className="devices">
|
2017-10-25 17:02:39 -06:00
|
|
|
<Row>
|
|
|
|
<Col xs={12} sm={6}>
|
|
|
|
<FarmbotOsSettings
|
2018-06-18 15:12:00 -06:00
|
|
|
diagnostics={selectAllDiagnosticDumps(this.props.resources)}
|
2017-10-25 17:02:39 -06:00
|
|
|
account={this.props.deviceAccount}
|
|
|
|
dispatch={this.props.dispatch}
|
|
|
|
bot={this.props.bot}
|
2018-01-24 17:32:50 -07:00
|
|
|
botToMqttLastSeen={botToMqttLastSeen}
|
2018-01-27 02:29:13 -07:00
|
|
|
botToMqttStatus={botToMqttStatus}
|
2018-03-07 22:08:00 -07:00
|
|
|
sourceFbosConfig={this.props.sourceFbosConfig}
|
2018-03-10 02:42:15 -07:00
|
|
|
shouldDisplay={this.props.shouldDisplay}
|
|
|
|
isValidFbosConfig={this.props.isValidFbosConfig} />
|
2017-10-25 17:02:39 -06:00
|
|
|
<ConnectivityPanel
|
|
|
|
status={this.props.deviceAccount.specialStatus}
|
|
|
|
onRefresh={this.refresh}
|
|
|
|
rowData={this.rowData}>
|
|
|
|
<Diagnosis
|
|
|
|
userAPI={!!this.flags.userAPI}
|
|
|
|
userMQTT={!!this.flags.userMQTT.connectionStatus}
|
|
|
|
botMQTT={!!this.flags.botMQTT.connectionStatus}
|
|
|
|
botAPI={!!this.flags.botAPI.connectionStatus}
|
|
|
|
botFirmware={!!this.flags.botFirmware.connectionStatus} />
|
|
|
|
</ConnectivityPanel>
|
|
|
|
</Col>
|
|
|
|
<Col xs={12} sm={6}>
|
|
|
|
<HardwareSettings
|
|
|
|
controlPanelState={this.props.bot.controlPanelState}
|
|
|
|
dispatch={this.props.dispatch}
|
2018-01-15 09:36:10 -07:00
|
|
|
bot={this.props.bot}
|
2018-01-27 02:29:13 -07:00
|
|
|
botToMqttStatus={botToMqttStatus}
|
2018-05-02 01:05:02 -06:00
|
|
|
shouldDisplay={this.props.shouldDisplay}
|
2018-03-08 21:03:02 -07:00
|
|
|
sourceFbosConfig={this.props.sourceFbosConfig}
|
2018-03-09 02:34:24 -07:00
|
|
|
sourceFwConfig={this.props.sourceFwConfig}
|
2018-03-08 21:03:02 -07:00
|
|
|
firmwareConfig={this.props.firmwareConfig} />
|
2017-11-30 20:43:35 -07:00
|
|
|
{this.props.bot.hardware.gpio_registry &&
|
|
|
|
<PinBindings
|
|
|
|
dispatch={this.props.dispatch}
|
|
|
|
bot={this.props.bot}
|
2018-01-15 09:36:10 -07:00
|
|
|
resources={this.props.resources}
|
2018-03-13 18:34:30 -06:00
|
|
|
botToMqttStatus={botToMqttStatus}
|
|
|
|
shouldDisplay={this.props.shouldDisplay} />}
|
2017-10-25 17:02:39 -06:00
|
|
|
</Col>
|
|
|
|
</Row>
|
2017-06-29 12:54:02 -06:00
|
|
|
</Page>;
|
|
|
|
} else {
|
|
|
|
throw new Error("Log in first");
|
|
|
|
}
|
|
|
|
}
|
2017-07-04 07:20:51 -06:00
|
|
|
}
|