<commit_before>import * as React from "react";
import { t } from "i18next";
import { BotState } from "../interfaces";
import { AuthState } from "../../auth/interfaces";
import {
  changeDevice,
  addDevice,
  saveAccountChanges,
  reboot,
  powerOff,
  factoryReset
} from "../actions";
import { FwUpdateButton } from "./fw_update_button";
import { OsUpdateButton } from "./os_update_button";
import { devices } from "../../device";
import { FBSelect, DropDownItem } from "../../ui/index";
import { Dictionary } from "farmbot/dist";
const CAMERA_CHOICES = [
  { label: "USB Camera", value: "USB" },
  { label: "Raspberry Pi Camera", value: "RPI" }
];

interface Props {
  bot: BotState;
  auth: AuthState;
  dispatch: Function;
}

interface State {
  cameraStatus: "" | "sending" | "done" | "error";
}

export class FarmbotOsSettings extends React.Component<Props, State> {
  constructor() {
    super();
    this.state = { cameraStatus: "" };
  }
  changeBot(e: React.MouseEvent<HTMLInputElement>) {
    e.preventDefault();
    console.warn("If you are reading this method, refactor NOW! -RC");
    let updates =
      _.object([[e.currentTarget.name, e.currentTarget.value]]);
    this.props.dispatch(changeDevice(updates));
  }

  saveBot(e: React.MouseEvent<{}>) {
    e.preventDefault();
    let form = this.props.bot.account;
    this.props.dispatch(addDevice(form));
  }


  updateBot(e: React.MouseEvent<{}>) {
    this.props.dispatch(saveAccountChanges);
  }

  sendOffConfig = (e: DropDownItem) => {
    let message = { "camera": JSON.stringify(e.value) };
    this.setState({ cameraStatus: "sending" });
    setTimeout(this.setState({ cameraStatus: "" }), 10000);
    devices
      .current
      .setUserEnv(message)
      .then(() => { this.setState({ cameraStatus: "done" }); })
      .catch(() => { this.setState({ cameraStatus: "error" }); });
  }

  render() {
    return <div className="col-sm-12">
      <form onSubmit={this.saveBot.bind(this)}>
        <div className="row">
          <div className="col-sm-12">
            <button type="submit"
              className={`button-like green widget-control`}
              onClick={this.updateBot
                .bind(this)}>
              {t("SAVE")} {
                this.props.bot.account
                  .dirty ? "*" : ""}
            </button>
            <div className="widget-header">
              <h5>{t("DEVICE")}</h5>
              <i className={`fa
                            fa-question-circle widget-help-icon`}>
                <div className={`widget-help-text`}>
                  {t(`This widget shows device information.`)}
                </div>
              </i>
            </div>
          </div>
        </div>
        <div className="row">
          <div className="col-sm-12">
            <div className="widget-content">
              <table className="plain">
                <tbody>
                  <tr>
                    <td>
                      <label>
                        {t("NAME")}
                      </label>
                    </td>
                    <td colSpan={2}>
                      <input name="name"
                        onChange={this.changeBot.bind(this)}
                        value={this.props.bot.account.name} />
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("NETWORK")}</label>
                    </td>
                    <td colSpan={2}>
                      <p> {`mqtt://${this.props.auth.token.unencoded.mqtt}`} </p>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("CONTROLLER")}</label>
                    </td>
                    <td className="devices-pad">
                      <p>
                        {t("Version")} {String(this.props.bot.hardware
                          .informational_settings.controller_version)
                          || t("Not Connected to bot")}
                      </p>
                      <OsUpdateButton { ...this.props } />
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("FIRMWARE")}</label>
                    </td>
                    <td className="devices-pad">
                      <p>
                        {t("Version")} {
                          String(this.props.bot.hardware.mcu_params.param_version)
                          || t("Not Connected to bot")
                        }
                      </p>
                      <FwUpdateButton { ...this.props } />
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("RESTART FARMBOT")} </label>
                    </td>
                    <td>
                      <p>
                        {t(`This will restart FarmBot's Raspberry
                                            Pi and controller software.`)}
                      </p>
                    </td>
                    <td>
                      <button type="button"
                        className="button-like yellow"
                        onClick={reboot}>
                        {t("RESTART")}
                      </button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("SHUTDOWN FARMBOT")}</label>
                    </td><commit_msg>Add Firmware version<commit_after>import * as React from "react";
import { t } from "i18next";
import { BotState } from "../interfaces";
import { AuthState } from "../../auth/interfaces";
import {
  changeDevice,
  addDevice,
  saveAccountChanges,
  reboot,
  powerOff,
  factoryReset
} from "../actions";
import { FwUpdateButton } from "./fw_update_button";
import { OsUpdateButton } from "./os_update_button";
import { devices } from "../../device";
import { FBSelect, DropDownItem } from "../../ui/index";
import { Dictionary } from "farmbot/dist";
const CAMERA_CHOICES = [
  { label: "USB Camera", value: "USB" },
  { label: "Raspberry Pi Camera", value: "RPI" }
];

interface Props {
  bot: BotState;
  auth: AuthState;
  dispatch: Function;
}

interface State {
  cameraStatus: "" | "sending" | "done" | "error";
}

export class FarmbotOsSettings extends React.Component<Props, State> {
  constructor() {
    super();
    this.state = { cameraStatus: "" };
  }
  changeBot(e: React.MouseEvent<HTMLInputElement>) {
    e.preventDefault();
    console.warn("If you are reading this method, refactor NOW! -RC");
    let updates =
      _.object([[e.currentTarget.name, e.currentTarget.value]]);
    this.props.dispatch(changeDevice(updates));
  }

  saveBot(e: React.MouseEvent<{}>) {
    e.preventDefault();
    let form = this.props.bot.account;
    this.props.dispatch(addDevice(form));
  }


  updateBot(e: React.MouseEvent<{}>) {
    this.props.dispatch(saveAccountChanges);
  }

  sendOffConfig = (e: DropDownItem) => {
    let message = { "camera": JSON.stringify(e.value) };
    this.setState({ cameraStatus: "sending" });
    setTimeout(this.setState({ cameraStatus: "" }), 10000);
    devices
      .current
      .setUserEnv(message)
      .then(() => { this.setState({ cameraStatus: "done" }); })
      .catch(() => { this.setState({ cameraStatus: "error" }); });
  }

  render() {
    let fwvers = _.get(this
      .props
      .bot
      .hardware
      .informational_settings,
      "controller_version",
      t("Not Connected to bot"));
    return <div className="col-sm-12">
      <form onSubmit={this.saveBot.bind(this)}>
        <div className="row">
          <div className="col-sm-12">
            <button type="submit"
              className={`button-like green widget-control`}
              onClick={this.updateBot
                .bind(this)}>
              {t("SAVE")} {
                this.props.bot.account
                  .dirty ? "*" : ""}
            </button>
            <div className="widget-header">
              <h5>{t("DEVICE")}</h5>
              <i className={`fa
                            fa-question-circle widget-help-icon`}>
                <div className={`widget-help-text`}>
                  {t(`This widget shows device information.`)}
                </div>
              </i>
            </div>
          </div>
        </div>
        <div className="row">
          <div className="col-sm-12">
            <div className="widget-content">
              <table className="plain">
                <tbody>
                  <tr>
                    <td>
                      <label>
                        {t("NAME")}
                      </label>
                    </td>
                    <td colSpan={2}>
                      <input name="name"
                        onChange={this.changeBot.bind(this)}
                        value={this.props.bot.account.name} />
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("NETWORK")}</label>
                    </td>
                    <td colSpan={2}>
                      <p> {`mqtt://${this.props.auth.token.unencoded.mqtt}`} </p>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("CONTROLLER")}</label>
                    </td>
                    <td className="devices-pad">
                      <p>
                        {t("Version")} {String(this.props.bot.hardware
                          .informational_settings.controller_version)
                          || t("Not Connected to bot")}
                      </p>
                      <OsUpdateButton { ...this.props } />
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("FIRMWARE")}</label>
                    </td>
                    <td className="devices-pad">
                      <p>
                        {t("Version")} {fwvers}
                      </p>
                      <FwUpdateButton { ...this.props } />
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("RESTART FARMBOT")} </label>
                    </td>
                    <td>
                      <p>
                        {t(`This will restart FarmBot's Raspberry
                                            Pi and controller software.`)}
                      </p>
                    </td>
                    <td>
                      <button type="button"
                        className="button-like yellow"
                        onClick={reboot}>
                        {t("RESTART")}
                      </button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <label>{t("SHUTDOWN FARMBOT")}</label>
                    </td>
{'fraction_non_alphanumeric': 0.14315559996366609, 'fraction_numerical': 0.003088382232718685, 'mean_word_length': 1.2006795922446531, 'pattern_counts': {'":': 2, '<': 173, '<?xml version=': 0, '>': 179, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4731567', 'n_tokens_mistral': 3038, 'n_tokens_neox': 2880, 'n_words': 569}