diff --git a/src/bin/binModes/StorageMode.tsx b/src/bin/binModes/StorageMode.tsx index 6d61c3a..70c4f72 100644 --- a/src/bin/binModes/StorageMode.tsx +++ b/src/bin/binModes/StorageMode.tsx @@ -1,18 +1,26 @@ -import { Box, DialogContent, DialogTitle, DialogActions } from "@mui/material"; -import { ComponentSet } from "bin/conditioning/pickComponentSet"; -import { Device, Interaction } from "models"; +import { DialogContent, DialogTitle, DialogActions } from "@mui/material"; +import { Component, 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 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 { deviceID: number, - //interactions: } interface Props { // the devices connected to the bin devices: Device[] - confirm: (conflictingInteractions: Interaction[], deviceId: number, newInteractions: pond.MultiInteractionSettings, componentSets: ComponentSet[]) => void + deviceComponents: Map + binPrefs?: Map + confirm: (deviceData: DeviceChangeData[]) => void } /** @@ -21,6 +29,58 @@ interface Props { * @returns */ export default function StorageMode(props: Props){ + const {devices, deviceComponents, binPrefs} = props + const interactionsAPI = useInteractionsAPI() + + useEffect(()=>{ + let interactionPromises: Promise[] = [] + 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 diff --git a/src/models/Plenum.ts b/src/models/Plenum.ts index b88b8a0..5ec161f 100644 --- a/src/models/Plenum.ts +++ b/src/models/Plenum.ts @@ -108,7 +108,9 @@ export class Plenum { return quack.ComponentID.fromObject({ type: this.settings.type, addressType: this.settings.addressType, - address: this.settings.address + address: this.settings.address, + expansionLine: this.settings.expansionLine, + muxLine: this.settings.muxLine }); }