updated the component and device api's to have as be a parameter for the function
This commit is contained in:
parent
c617ebf868
commit
b62c7dbe5c
39 changed files with 346 additions and 651 deletions
|
|
@ -15,6 +15,7 @@ import DateSelect from "common/time/DateSelect";
|
|||
import { useDeviceAPI } from "hooks";
|
||||
import { Component, Device } from "models";
|
||||
import { Moment } from "moment";
|
||||
import { useGlobalState } from "providers";
|
||||
import React, { useState } from "react";
|
||||
import { downloadJSON } from "utils";
|
||||
|
||||
|
|
@ -27,6 +28,7 @@ interface Props {
|
|||
|
||||
export default function ArcGISDeviceData(props: Props) {
|
||||
const { open, close, device, components } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const [startDate, setStartDate] = useState<Moment>(GetDefaultDateRange().start);
|
||||
const [endDate, setEndDate] = useState<Moment>(GetDefaultDateRange().end);
|
||||
const [includedComponents, setIncludedComponents] = useState<Component[]>([]);
|
||||
|
|
@ -89,7 +91,8 @@ export default function ArcGISDeviceData(props: Props) {
|
|||
limit,
|
||||
0,
|
||||
"asc",
|
||||
"timestamp"
|
||||
"timestamp",
|
||||
as
|
||||
)
|
||||
.then(resp => {
|
||||
downloadJSON(resp.data, filename + ".json");
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import { useDeviceAPI, useSnackbar } from "hooks";
|
|||
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
|
||||
import { useState } from "react";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
import { useGlobalState } from "providers";
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => {
|
||||
return ({
|
||||
|
|
@ -36,6 +37,7 @@ export default function Connection(props: Props) {
|
|||
const deviceAPI = useDeviceAPI();
|
||||
const { success, error } = useSnackbar();
|
||||
const { deviceID, deviceName, open, close } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const [gateway, setGateway] = useState<string>("");
|
||||
const [password, setPassword] = useState<string>("");
|
||||
const [passwordVisible, setPasswordVisible] = useState<boolean>(false);
|
||||
|
|
@ -71,7 +73,7 @@ export default function Connection(props: Props) {
|
|||
let keys = getContextKeys();
|
||||
let types = getContextTypes();
|
||||
deviceAPI
|
||||
.setWifi(deviceID, gateway, password, keys, types)
|
||||
.setWifi(deviceID, gateway, password, keys, types, as)
|
||||
.then(() => success("Connection settings sent to " + deviceName))
|
||||
.catch(() => error("Failed to send connection settings to " + deviceName))
|
||||
.finally(() => handleClose());
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ export default function DevicePresets(props: DevicePresetsProps) {
|
|||
comps = [];
|
||||
setLoading(true);
|
||||
let interactionPromise = interactionAPI.listInteractionsByDevice(deviceIndex, undefined, as);
|
||||
let componentPromise = componentAPI.list(deviceIndex, undefined, [binKey], ["bin"], true);
|
||||
let componentPromise = componentAPI.list(deviceIndex, undefined, [binKey], ["bin"], true, as);
|
||||
let dComponents = new Map<string, Component[]>();
|
||||
Promise.all([componentPromise, interactionPromise])
|
||||
.then(([compResp, interactionResp]) => {
|
||||
|
|
@ -367,13 +367,13 @@ export default function DevicePresets(props: DevicePresetsProps) {
|
|||
//if the device id was passed in the mode was set to storage and we need to set them to off
|
||||
heaters.forEach(heater => {
|
||||
componentAPI
|
||||
.update(deviceIndex, heater.settings)
|
||||
.update(deviceIndex, heater.settings, undefined, undefined, as)
|
||||
.then()
|
||||
.catch();
|
||||
});
|
||||
fans.forEach(fan => {
|
||||
componentAPI
|
||||
.update(deviceIndex, fan.settings)
|
||||
.update(deviceIndex, fan.settings, undefined, undefined, as)
|
||||
.then()
|
||||
.catch();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ const deviceFromForm = (device: Device): Device => {
|
|||
|
||||
export default function DeviceSettings(props: Props) {
|
||||
const classes = useStyles();
|
||||
const [{ user }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
const navigate = useNavigate();
|
||||
const { success, error } = useSnackbar();
|
||||
const deviceAPI = useDeviceAPI();
|
||||
|
|
@ -254,7 +254,7 @@ export default function DeviceSettings(props: Props) {
|
|||
deviceForm.settings.extensionComponents = [compExtOne, compExtTwo, compExtThree];
|
||||
deviceForm.settings.mutations = linearMutations;
|
||||
deviceAPI
|
||||
.update(deviceID, deviceForm.settings)
|
||||
.update(deviceID, deviceForm.settings, as)
|
||||
.then((_response: any) => {
|
||||
success(deviceName + " was successfully updated!");
|
||||
close();
|
||||
|
|
@ -277,7 +277,7 @@ export default function DeviceSettings(props: Props) {
|
|||
const removeDevice = () => {
|
||||
const deviceName = deviceForm.name();
|
||||
deviceAPI
|
||||
.remove(device.id())
|
||||
.remove(device.id(), as)
|
||||
.then((_response: any) => {
|
||||
success(deviceName + " was successfully deleted!");
|
||||
navigate("/");
|
||||
|
|
|
|||
|
|
@ -104,7 +104,8 @@ export default function Device(props: Props) {
|
|||
undefined,
|
||||
[deviceID.toString()],
|
||||
["device"],
|
||||
true
|
||||
true,
|
||||
as
|
||||
);
|
||||
let interactionsPromise = interactionsAPI.listInteractionsByDevice(deviceID, undefined, as);
|
||||
let groupPromise: Promise<any> = Promise.resolve(undefined);
|
||||
|
|
@ -343,7 +344,7 @@ export default function Device(props: Props) {
|
|||
let updatedPreferences = cloneDeep(preferences);
|
||||
updatedPreferences.notify = !preferences.notify;
|
||||
deviceAPI
|
||||
.updatePreferences(deviceID, updatedPreferences)
|
||||
.updatePreferences(deviceID, updatedPreferences, undefined, undefined, as)
|
||||
.then(() => setPreferences(updatedPreferences))
|
||||
.catch(() => {
|
||||
error(
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import {
|
|||
import { GetDeviceProductIcon, GetDeviceProductLabel } from "products/DeviceProduct";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { quack } from "protobuf-ts/quack";
|
||||
import { useComponentAPI, useSnackbar } from "providers";
|
||||
import { useComponentAPI, useGlobalState, useSnackbar } from "providers";
|
||||
import React, { useState } from "react";
|
||||
import DeviceSVG, { PortInformation } from "./deviceSVG";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
|
|
@ -69,6 +69,7 @@ const useStyles = makeStyles((theme: Theme) => {
|
|||
|
||||
export default function DeviceWizard(props: Props) {
|
||||
const { device, components, refreshCallback } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const [componentDialogOpen, setComponentDialogOpen] = useState(false);
|
||||
const [availableOffsets, setAvailableOffsets] = useState<OffsetAvailabilityMap>(new Map());
|
||||
const [availablePositions, setAvailablePositions] = useState<DeviceAvailabilityMap>(new Map());
|
||||
|
|
@ -159,7 +160,7 @@ export default function DeviceWizard(props: Props) {
|
|||
componentSettings.reportPeriodMs = 600000;
|
||||
componentSettings.name = "Port " + selectedPort.label + " Auto Detect";
|
||||
compAPI
|
||||
.add(device.id(), componentSettings)
|
||||
.add(device.id(), componentSettings, as)
|
||||
.then(resp => {
|
||||
success("Added Auto Detect Component to Port");
|
||||
})
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import { Backpack, Device } from "models";
|
|||
import { backpackOptions, genericBackpacks } from "pbHelpers/Backpack";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useGlobalState } from "providers";
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
|
|
@ -34,6 +35,7 @@ export default function ProvisionDevice(props: Props) {
|
|||
const deviceAPI = useDeviceAPI();
|
||||
const backpackAPI = useBackpackAPI();
|
||||
const { error, success, warning, info } = useSnackbar();
|
||||
const [{as}] = useGlobalState();
|
||||
const { isOpen, closeDialogCallback, refreshCallback } = props;
|
||||
const [provisioned, setProvisioned] = useState<boolean>(false);
|
||||
const [idHex, setIdHex] = useState<string>("");
|
||||
|
|
@ -98,7 +100,7 @@ export default function ProvisionDevice(props: Props) {
|
|||
setDeviceLoading(true);
|
||||
const deviceID = parseInt(idHex, 16);
|
||||
deviceAPI
|
||||
.get(deviceID)
|
||||
.get(deviceID, undefined, undefined, undefined, as)
|
||||
.then(response => {
|
||||
let rDevice = Device.any(response.data);
|
||||
setDevice(rDevice);
|
||||
|
|
@ -149,7 +151,7 @@ export default function ProvisionDevice(props: Props) {
|
|||
const submitProvision = () => {
|
||||
setProvisioned(false);
|
||||
deviceAPI
|
||||
.add("", "", assembleBackpack())
|
||||
.add("", "", assembleBackpack(), as)
|
||||
.then((response: any) => {
|
||||
let updatedIdHex = response.data.idHex;
|
||||
let updatedKeyHex = response.data.keyHex;
|
||||
|
|
@ -173,7 +175,7 @@ export default function ProvisionDevice(props: Props) {
|
|||
settings.name = name;
|
||||
settings.description = description;
|
||||
deviceAPI
|
||||
.update(deviceID, settings)
|
||||
.update(deviceID, settings, as)
|
||||
.then(() => {
|
||||
success("Device " + deviceID.toString() + " was successfully updated");
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue