working on storage building the stuff to send up
This commit is contained in:
parent
7e6b41273b
commit
2c6799bcc1
2 changed files with 69 additions and 7 deletions
|
|
@ -1,18 +1,26 @@
|
||||||
import { Box, DialogContent, DialogTitle, DialogActions } from "@mui/material";
|
import { DialogContent, DialogTitle, DialogActions } from "@mui/material";
|
||||||
import { ComponentSet } from "bin/conditioning/pickComponentSet";
|
import { Component, Device, Interaction } from "models";
|
||||||
import { Device, Interaction } from "models";
|
import { Ambient } from "models/Ambient";
|
||||||
|
import { Controller } from "models/Controller";
|
||||||
|
import { GrainCable } from "models/GrainCable";
|
||||||
|
import { Plenum } from "models/Plenum";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import React from "react";
|
import { quack } from "protobuf-ts/quack";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { DeviceChangeData } from "./BinModeController";
|
||||||
|
import { useInteractionsAPI } from "providers";
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
|
|
||||||
interface InteractionToRemove {
|
interface InteractionToRemove {
|
||||||
deviceID: number,
|
deviceID: number,
|
||||||
//interactions:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
// the devices connected to the bin
|
// the devices connected to the bin
|
||||||
devices: Device[]
|
devices: Device[]
|
||||||
confirm: (conflictingInteractions: Interaction[], deviceId: number, newInteractions: pond.MultiInteractionSettings, componentSets: ComponentSet[]) => void
|
deviceComponents: Map<number, Component[]>
|
||||||
|
binPrefs?: Map<string, pond.BinComponentPreferences>
|
||||||
|
confirm: (deviceData: DeviceChangeData[]) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,6 +29,58 @@ interface Props {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export default function StorageMode(props: Props){
|
export default function StorageMode(props: Props){
|
||||||
|
const {devices, deviceComponents, binPrefs} = props
|
||||||
|
const interactionsAPI = useInteractionsAPI()
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
let interactionPromises: Promise<Interaction[]>[] = []
|
||||||
|
let deviceContext: {device: Device, plenums: Plenum[], ambients: Ambient[], cables: GrainCable[], controllers: Controller[]}[] = []
|
||||||
|
devices.forEach(device => {
|
||||||
|
let plenums: Plenum[] = []
|
||||||
|
let ambients: Ambient[] = []
|
||||||
|
let cables: GrainCable[] = [] //since this mode is going to add notification interactions to cables they should be filtered as well
|
||||||
|
let controllers: Controller[] = [] //because storage is just setting things to false i dont think i need to seperate fans from heaters
|
||||||
|
//sort the components into the plenum, ambient, grain cable, and controller arrays
|
||||||
|
deviceComponents.get(device.id())!.forEach(comp => {
|
||||||
|
let pref = binPrefs?.get(comp.key());
|
||||||
|
if (pref) {
|
||||||
|
if (pref.type) {
|
||||||
|
if (pref.type === pond.BinComponent.BIN_COMPONENT_PLENUM){
|
||||||
|
plenums.push(Plenum.create(comp));
|
||||||
|
//sourceMap.set(comp.locationString(), comp)
|
||||||
|
}
|
||||||
|
if (pref.type === pond.BinComponent.BIN_COMPONENT_AMBIENT){
|
||||||
|
ambients.push(Ambient.create(comp));
|
||||||
|
//sourceMap.set(comp.locationString(), comp)
|
||||||
|
}
|
||||||
|
if (pref.type === pond.BinComponent.BIN_COMPONENT_HEATER || pref.type === pond.BinComponent.BIN_COMPONENT_FAN) {
|
||||||
|
let controller = Controller.create(comp);
|
||||||
|
controller.settings.defaultOutputState = quack.OutputMode.OUTPUT_MODE_OFF;
|
||||||
|
controllers.push(controller);
|
||||||
|
//sinkMap.set(comp.locationString(), comp)
|
||||||
|
}
|
||||||
|
if (pref.type === pond.BinComponent.BIN_COMPONENT_GRAIN_CABLE){
|
||||||
|
let cable = GrainCable.create(comp)
|
||||||
|
cables.push(cable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//after sorting it will need to load the interactions for the device
|
||||||
|
deviceContext.push({device, plenums, ambients, cables, controllers})
|
||||||
|
interactionPromises.push(interactionsAPI.listInteractionsByDevice(device.id()))
|
||||||
|
})
|
||||||
|
|
||||||
|
Promise.all(interactionPromises).then(resp => {
|
||||||
|
//the index of this should match the device index in the devices array
|
||||||
|
resp.forEach((interactions,i) => {
|
||||||
|
interactions.forEach(interaction => {
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
},[devices, binPrefs, deviceComponents])
|
||||||
|
|
||||||
//load the interactions for all of the bins connected devices
|
//load the interactions for all of the bins connected devices
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,9 @@ export class Plenum {
|
||||||
return quack.ComponentID.fromObject({
|
return quack.ComponentID.fromObject({
|
||||||
type: this.settings.type,
|
type: this.settings.type,
|
||||||
addressType: this.settings.addressType,
|
addressType: this.settings.addressType,
|
||||||
address: this.settings.address
|
address: this.settings.address,
|
||||||
|
expansionLine: this.settings.expansionLine,
|
||||||
|
muxLine: this.settings.muxLine
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue