Migrate off of old FBJS getState() functions
parent
9ab6fa3d81
commit
f0a49bf5b3
|
@ -53,7 +53,7 @@
|
|||
"enzyme": "^3.1.0",
|
||||
"enzyme-adapter-react-16": "^1.1.0",
|
||||
"extract-text-webpack-plugin": "3.0.2",
|
||||
"farmbot": "5.4.1",
|
||||
"farmbot": "6.0.0-rc2",
|
||||
"farmbot-toastr": "^1.0.3",
|
||||
"fastclick": "^1.0.6",
|
||||
"file-loader": "1.1.7",
|
||||
|
|
|
@ -27,20 +27,23 @@ import {
|
|||
} from "../ping_mqtt";
|
||||
import { Farmbot, Dictionary } from "farmbot";
|
||||
import { dispatchNetworkDown, dispatchNetworkUp } from "../index";
|
||||
import { FarmBotInternalConfig } from "farmbot/dist/config";
|
||||
|
||||
const TOO_LATE_TIME_DIFF = ACTIVE_THRESHOLD + 1;
|
||||
const ACCEPTABLE_TIME_DIFF = ACTIVE_THRESHOLD - 1;
|
||||
|
||||
let state: Dictionary<string | number | boolean> = {
|
||||
let state: Partial<FarmBotInternalConfig> = {
|
||||
[LAST_IN]: 123, [LAST_OUT]: 456
|
||||
};
|
||||
|
||||
function fakeBot(): Farmbot {
|
||||
const fb: Partial<Farmbot> = {
|
||||
setState: jest.fn(),
|
||||
setConfig: jest.fn(),
|
||||
publish: jest.fn(),
|
||||
on: jest.fn(),
|
||||
getState() { return state; }
|
||||
getConfig(key: keyof FarmBotInternalConfig) {
|
||||
return (state as FarmBotInternalConfig)[key];
|
||||
}
|
||||
};
|
||||
|
||||
return fb as Farmbot;
|
||||
|
@ -63,12 +66,12 @@ describe("ping util", () => {
|
|||
it("sets the LAST_PING_(IN|OUT) in bot state", () => {
|
||||
const bot = fakeBot();
|
||||
writePing(bot, "in");
|
||||
expect(bot.setState)
|
||||
.toHaveBeenCalledWith(LAST_IN, expect.any(Number));
|
||||
expect(bot.getConfig)
|
||||
.toHaveBeenCalledWith(LAST_IN);
|
||||
jest.clearAllMocks();
|
||||
writePing(bot, "out");
|
||||
expect(bot.setState)
|
||||
.toHaveBeenCalledWith(LAST_OUT, expect.any(Number));
|
||||
expect(bot.getConfig)
|
||||
.toHaveBeenCalledWith(LAST_OUT);
|
||||
});
|
||||
|
||||
it("reads LAST_PING_(IN|OUT)", () => {
|
||||
|
|
|
@ -4,24 +4,25 @@ import { isNumber } from "lodash";
|
|||
import axios from "axios";
|
||||
import { API } from "../api/index";
|
||||
import { timestamp } from "../util";
|
||||
import { FarmBotInternalConfig } from "farmbot/dist/config";
|
||||
|
||||
export const PING_INTERVAL = 3000;
|
||||
export const ACTIVE_THRESHOLD = PING_INTERVAL * 2;
|
||||
|
||||
const label = "ping";
|
||||
export const LAST_IN = "LAST_PING_IN";
|
||||
export const LAST_OUT = "LAST_PING_OUT";
|
||||
export const LAST_IN: keyof FarmBotInternalConfig = "LAST_PING_IN";
|
||||
export const LAST_OUT: keyof FarmBotInternalConfig = "LAST_PING_OUT";
|
||||
export const PING: Readonly<RpcRequest> = { kind: "rpc_request", args: { label } };
|
||||
|
||||
type Direction = "in" | "out";
|
||||
|
||||
export function writePing(bot: Farmbot, direction: Direction) {
|
||||
const dir = direction === "out" ? LAST_OUT : LAST_IN;
|
||||
bot.setState(dir, timestamp());
|
||||
bot.setConfig(dir, timestamp());
|
||||
}
|
||||
|
||||
export function readPing(bot: Farmbot, direction: Direction): number | undefined {
|
||||
const val = bot.getState()[direction === "out" ? LAST_OUT : LAST_IN];
|
||||
const val = bot.getConfig(direction === "out" ? LAST_OUT : LAST_IN);
|
||||
return isNumber(val) ? val : undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as React from "react";
|
|||
import { Farmbot } from "farmbot";
|
||||
import { moveRelative } from "../devices/actions";
|
||||
import { DirectionButtonProps, Payl } from "./interfaces";
|
||||
import { CONFIG_DEFAULTS } from "farmbot/dist/config";
|
||||
|
||||
export function directionDisabled(props: DirectionButtonProps): boolean {
|
||||
const {
|
||||
|
@ -42,7 +43,7 @@ export function calculateDistance(props: DirectionButtonProps) {
|
|||
|
||||
export class DirectionButton extends React.Component<DirectionButtonProps, {}> {
|
||||
sendCommand = () => {
|
||||
const payload: Payl = { speed: Farmbot.defaults.speed, x: 0, y: 0, z: 0 };
|
||||
const payload: Payl = { speed: CONFIG_DEFAULTS.speed, x: 0, y: 0, z: 0 };
|
||||
payload[this.props.axis] = calculateDistance(this.props);
|
||||
moveRelative(payload);
|
||||
}
|
||||
|
|
|
@ -3,14 +3,14 @@ import { t } from "i18next";
|
|||
import { getDevice } from "../../../device";
|
||||
import { Axis } from "../../interfaces";
|
||||
import { HomingRowProps } from "../interfaces";
|
||||
import { Farmbot } from "farmbot/dist";
|
||||
import { LockableButton } from "../lockable_button";
|
||||
import { axisTrackingStatus } from "../axis_tracking_status";
|
||||
import { ToolTips } from "../../../constants";
|
||||
import { SpacePanelToolTip } from "../space_panel_tool_tip";
|
||||
import { Row, Col } from "../../../ui/index";
|
||||
import { CONFIG_DEFAULTS } from "farmbot/dist/config";
|
||||
|
||||
const speed = Farmbot.defaults.speed;
|
||||
const speed = CONFIG_DEFAULTS.speed;
|
||||
const findHome =
|
||||
(axis: Axis) => getDevice().findHome({ speed, axis }).catch(() => { });
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Farmbot, toPairs, rpcRequest } from "farmbot";
|
||||
import { Farmbot, rpcRequest } from "farmbot";
|
||||
import { createTransferCert } from "./create_transfer_cert";
|
||||
|
||||
export interface TransferProps {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import * as React from "react";
|
||||
import { StepButton } from "./step_buttons/index";
|
||||
import { t } from "i18next";
|
||||
import { Farmbot } from "farmbot";
|
||||
import { scrollToBottom } from "../util";
|
||||
import { Row, ToolTip } from "../ui/index";
|
||||
import { TaggedSequence } from "../resources/tagged_resources";
|
||||
import { ToolTips } from "../constants";
|
||||
import { CONFIG_DEFAULTS } from "farmbot/dist/config";
|
||||
|
||||
interface StepButtonProps {
|
||||
dispatch: Function;
|
||||
|
@ -31,7 +31,7 @@ export function StepButtonCluster({ dispatch, current }: StepButtonProps) {
|
|||
z: 0
|
||||
},
|
||||
},
|
||||
speed: Farmbot.defaults.speed
|
||||
speed: CONFIG_DEFAULTS.speed
|
||||
}
|
||||
}}
|
||||
color="blue">
|
||||
|
@ -41,7 +41,7 @@ export function StepButtonCluster({ dispatch, current }: StepButtonProps) {
|
|||
current={current}
|
||||
step={{
|
||||
kind: "move_relative",
|
||||
args: { x: 0, y: 0, z: 0, speed: Farmbot.defaults.speed }
|
||||
args: { x: 0, y: 0, z: 0, speed: CONFIG_DEFAULTS.speed }
|
||||
}}
|
||||
color="green">
|
||||
{t("MOVE RELATIVE")}
|
||||
|
|
|
@ -2266,9 +2266,9 @@ farmbot-toastr@^1.0.0, farmbot-toastr@^1.0.3:
|
|||
farmbot-toastr "^1.0.0"
|
||||
typescript "^2.3.4"
|
||||
|
||||
farmbot@5.4.1:
|
||||
version "5.4.1"
|
||||
resolved "https://registry.yarnpkg.com/farmbot/-/farmbot-5.4.1.tgz#7742e5ca1f970b58d62c5be48dafcc313637f3b3"
|
||||
farmbot@6.0.0-rc2:
|
||||
version "6.0.0-rc2"
|
||||
resolved "https://registry.yarnpkg.com/farmbot/-/farmbot-6.0.0-rc2.tgz#614e418de2264d8366ef1e8fd83121fc18f40356"
|
||||
dependencies:
|
||||
mqtt "2.15.0"
|
||||
|
||||
|
|
Loading…
Reference in New Issue