Farmbot-Web-App/frontend/connectivity/interfaces.ts

72 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

import { TaggedResource } from "farmbot";
2019-09-06 08:33:23 -06:00
import { PingDictionary } from "../devices/connectivity/qos";
2017-10-04 09:17:16 -06:00
2018-01-14 19:07:35 -07:00
export type NetworkState = "up" | "down";
2017-09-29 13:46:08 -06:00
/** Description of a connection between two points on the network. */
export interface ConnectionStatus {
2018-01-14 19:07:35 -07:00
state: NetworkState;
at: number;
2017-09-28 12:07:34 -06:00
}
2017-09-29 13:46:08 -06:00
export interface EdgeStatus {
name: Edge;
status: ConnectionStatus;
}
/** Name of a connection between two points. "." can be read as "to".
* Example: "user.mqtt" => "User to MQTT". */
2017-10-02 08:58:03 -06:00
export type Edge =
| "bot.mqtt"
| "user.mqtt"
| "user.api";
2017-09-29 13:46:08 -06:00
2017-11-20 12:44:46 -07:00
type ConnectionRecord = Record<Edge, ConnectionStatus | undefined>;
2017-09-29 13:46:08 -06:00
/** Mapping of known connection status.
* An `undefined` value means we don't know. */
export type ConnectionState = {
uptime: ConnectionRecord;
2019-09-06 08:33:23 -06:00
pings: PingDictionary;
};
2017-11-10 14:33:48 -07:00
export interface UpdateMqttData<T extends TaggedResource> {
2017-11-10 14:33:48 -07:00
status: "UPDATE"
kind: T["kind"];
body: T["body"];
2017-11-10 14:33:48 -07:00
id: number;
sessionId: string;
}
export interface DeleteMqttData<T extends TaggedResource> {
2017-11-10 14:33:48 -07:00
status: "DELETE"
kind: T["kind"];
2017-11-10 14:33:48 -07:00
id: number;
}
export interface BadMqttData {
status: "ERR";
reason: string;
}
export interface SkipMqttData {
status: "SKIP";
}
export type MqttDataResult<T extends TaggedResource> =
| UpdateMqttData<T>
| DeleteMqttData<T>
2017-11-10 14:33:48 -07:00
| SkipMqttData
| BadMqttData;
export enum Reason {
BAD_KIND = "missing `kind`",
BAD_ID = "No ID or invalid ID.",
BAD_CHAN = "Expected exactly 5 segments in channel"
}
export interface SyncPayload {
args: { label: string; };
body: object | undefined;
}