updated as in the objectHeaterApi

This commit is contained in:
csawatzky 2025-04-21 14:39:04 -06:00
parent 59356aad27
commit 29902bc40b
6 changed files with 25 additions and 22 deletions

View file

@ -122,7 +122,7 @@ export default function SiteDrawer(props: Props) {
"write", "write",
"grant", "grant",
"revoke" "revoke"
]) ], as)
.then(resp => { .then(resp => {
setLinkDrawer(false); setLinkDrawer(false);
reLoadSites(); reLoadSites();
@ -184,7 +184,7 @@ export default function SiteDrawer(props: Props) {
return ( return (
<React.Fragment> <React.Fragment>
{/* {deviceLinkDrawer()} */} {deviceLinkDrawer()}
<DisplayDrawer <DisplayDrawer
open={open} open={open}
onClose={closeDrawer} onClose={closeDrawer}

View file

@ -138,7 +138,7 @@ export default function ObjectHeaterSettings(props: Props) {
settings.airCirculation = airCirculation; settings.airCirculation = airCirculation;
settings.mutations = linearMutations; settings.mutations = linearMutations;
objectHeaterAPI objectHeaterAPI
.updateObjectHeater(heater.key, heaterName, settings) .updateObjectHeater(heater.key, heaterName, settings, as)
.then(resp => { .then(resp => {
openSnack("Heater update"); openSnack("Heater update");
let updatedHeater = heater; let updatedHeater = heater;
@ -161,7 +161,7 @@ export default function ObjectHeaterSettings(props: Props) {
mutations: linearMutations mutations: linearMutations
}); });
objectHeaterAPI objectHeaterAPI
.addObjectHeater(heaterName, settings) .addObjectHeater(heaterName, settings, as)
.then(resp => { .then(resp => {
openSnack("New heater added"); openSnack("New heater added");
let newHeater = ObjectHeater.create( let newHeater = ObjectHeater.create(
@ -178,7 +178,7 @@ export default function ObjectHeaterSettings(props: Props) {
const removeHeater = () => { const removeHeater = () => {
if (heater) { if (heater) {
objectHeaterAPI objectHeaterAPI
.removeObjectHeater(heater.key) .removeObjectHeater(heater.key, as)
.then(resp => { .then(resp => {
openSnack("Heater Removed"); openSnack("Heater Removed");
setRemoveDialog(false); setRemoveDialog(false);

View file

@ -140,7 +140,7 @@ export default function Heater() {
} else { } else {
//if the heater was not carried from the heaters page, ie. page was reloaded, we will need to load the heater from the backend //if the heater was not carried from the heaters page, ie. page was reloaded, we will need to load the heater from the backend
heaterAPI heaterAPI
.getObjectHeater(heaterID) .getObjectHeater(heaterID, as)
.then(resp => { .then(resp => {
let h = ObjectHeater.any(resp.data.heater); let h = ObjectHeater.any(resp.data.heater);
setHeater(h); setHeater(h);
@ -192,7 +192,7 @@ export default function Heater() {
let deviceID = displayDevice.device?.settings?.deviceId; let deviceID = displayDevice.device?.settings?.deviceId;
if (deviceID) { if (deviceID) {
heaterAPI heaterAPI
.updateLink(heater.key, "objectHeater", deviceID.toString(), "device", []) .updateLink(heater.key, "objectHeater", deviceID.toString(), "device", [], as)
.then(resp => { .then(resp => {
if (deviceID) { if (deviceID) {
devices.delete(deviceID.toString()); devices.delete(deviceID.toString());
@ -205,7 +205,7 @@ export default function Heater() {
let updatedHeater = heater; let updatedHeater = heater;
updatedHeater.settings.mutations = []; updatedHeater.settings.mutations = [];
heaterAPI heaterAPI
.updateObjectHeater(heater.key, heater.name, updatedHeater.settings) .updateObjectHeater(heater.key, heater.name, updatedHeater.settings, as)
.then(resp => { .then(resp => {
setHeater(updatedHeater); setHeater(updatedHeater);
setDisplayedMutations([...updatedHeater.settings.mutations]); setDisplayedMutations([...updatedHeater.settings.mutations]);
@ -234,7 +234,7 @@ export default function Heater() {
"write", "write",
"grant", "grant",
"revoke" "revoke"
]) ], as)
.then(resp => { .then(resp => {
if (deviceID) { if (deviceID) {
devices.set(deviceID.toString(), dev); devices.set(deviceID.toString(), dev);

View file

@ -155,7 +155,7 @@ export default function Heaters() {
"write", "write",
"grant", "grant",
"revoke" "revoke"
]) ], as)
.then(resp => { .then(resp => {
if (deviceID) { if (deviceID) {
devices.set(deviceID.toString(), dev); devices.set(deviceID.toString(), dev);

View file

@ -178,7 +178,7 @@ export default function Site() {
"write", "write",
"grant", "grant",
"revoke" "revoke"
]) ], as)
.then(resp => { .then(resp => {
if (deviceID) { if (deviceID) {
devices.set(deviceID.toString(), dev); devices.set(deviceID.toString(), dev);

View file

@ -9,9 +9,10 @@ import { pondURL } from "./pond";
export interface IObjectHeaterAPIContext { export interface IObjectHeaterAPIContext {
addObjectHeater: ( addObjectHeater: (
name: string, name: string,
heater: pond.ObjectHeaterSettings heater: pond.ObjectHeaterSettings,
as?: string
) => Promise<AxiosResponse<pond.AddObjectHeaterResponse>>; ) => Promise<AxiosResponse<pond.AddObjectHeaterResponse>>;
getObjectHeater: (key: string) => Promise<AxiosResponse<pond.GetObjectHeaterResponse>>; getObjectHeater: (key: string, as?: string) => Promise<AxiosResponse<pond.GetObjectHeaterResponse>>;
listObjectHeaters: ( listObjectHeaters: (
limit: number, limit: number,
offset: number, offset: number,
@ -24,19 +25,20 @@ export interface IObjectHeaterAPIContext {
types?: string[], types?: string[],
numerical?: boolean numerical?: boolean
) => Promise<AxiosResponse<pond.ListObjectHeatersResponse>>; ) => Promise<AxiosResponse<pond.ListObjectHeatersResponse>>;
removeObjectHeater: (key: string) => Promise<AxiosResponse<pond.RemoveObjectHeaterResponse>>; removeObjectHeater: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveObjectHeaterResponse>>;
updateObjectHeater: ( updateObjectHeater: (
key: string, key: string,
name: string, name: string,
settings: pond.ObjectHeaterSettings, settings: pond.ObjectHeaterSettings,
asRoot?: true as?: string
) => Promise<AxiosResponse<pond.UpdateObjectHeaterResponse>>; ) => Promise<AxiosResponse<pond.UpdateObjectHeaterResponse>>;
updateLink: ( updateLink: (
parentKey: string, parentKey: string,
parentType: string, parentType: string,
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: string[] permissions: string[],
as?: string
) => Promise<any>; ) => Promise<any>;
listObjectHeatersPageData: ( listObjectHeatersPageData: (
limit: number, limit: number,
@ -58,9 +60,9 @@ interface Props {}
export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) { export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
const [{ as }] = useGlobalState(); //const [{ as }] = useGlobalState();
const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings) => { const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings, as?: string) => {
if (as) if (as)
return post<pond.AddObjectHeaterResponse>( return post<pond.AddObjectHeaterResponse>(
pondURL("/objectHeaters?name=" + name + "&as=" + as), pondURL("/objectHeaters?name=" + name + "&as=" + as),
@ -69,14 +71,14 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
return post<pond.AddObjectHeaterResponse>(pondURL("/objectHeaters?name=" + name), settings); return post<pond.AddObjectHeaterResponse>(pondURL("/objectHeaters?name=" + name), settings);
}; };
const getObjectHeater = (key: string) => { const getObjectHeater = (key: string, as?: string) => {
if (as) { if (as) {
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as)); return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as));
} }
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key)); return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key));
}; };
const removeObjectHeater = (key: string) => { const removeObjectHeater = (key: string, as?: string) => {
if (as) if (as)
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as)); return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as));
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key)); return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key));
@ -113,7 +115,7 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
); );
}; };
const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings) => { const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings, as?: string) => {
if (as) { if (as) {
return put<pond.UpdateObjectHeaterResponse>( return put<pond.UpdateObjectHeaterResponse>(
pondURL("/objectHeaters/" + key + "?as=" + as + "&name=" + name), pondURL("/objectHeaters/" + key + "?as=" + as + "&name=" + name),
@ -131,7 +133,8 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
parentType: string, parentType: string,
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: string[] permissions: string[],
as?: string
) => { ) => {
if (as) if (as)
return post(pondURL(`/objectHeaters/` + parentID + `/link?as=${as}`), { return post(pondURL(`/objectHeaters/` + parentID + `/link?as=${as}`), {