refactor: replace deprecated getPressureUnit and getTemperatureUnit functions with user model methods

Updated the GateDeviceInteraction and MeasurementDescriber components to utilize user.pressureUnit() instead of the deprecated getPressureUnit() function. Added deprecation comments in units.ts for clarity on the transition to User.tempUnit() and User.pressureUnit().
This commit is contained in:
csawatzky 2026-03-25 16:23:56 -06:00
parent ccabbbbd17
commit a2944d7a60
3 changed files with 10 additions and 9 deletions

View file

@ -7,8 +7,6 @@ import moment from "moment";
import { pond, quack } from "protobuf-ts/pond"; import { pond, quack } from "protobuf-ts/pond";
import { useGlobalState, useInteractionsAPI, useSnackbar } from "providers"; import { useGlobalState, useInteractionsAPI, useSnackbar } from "providers";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { getPressureUnit } from "utils";
interface Props { interface Props {
open: boolean; open: boolean;
close: (canceled: boolean) => void; close: (canceled: boolean) => void;
@ -186,9 +184,9 @@ export default function GateDeviceInteraction(props: Props) {
//need to make sure the redthreshold is in pascals //need to make sure the redthreshold is in pascals
let thresholdPascals = 0 let thresholdPascals = 0
if(!isNaN(parseFloat(redThreshold))){ if(!isNaN(parseFloat(redThreshold))){
if(getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS){ if(user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS){
thresholdPascals = parseFloat(redThreshold)*1000 thresholdPascals = parseFloat(redThreshold)*1000
}else if (getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER){ }else if (user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER){
thresholdPascals = parseFloat(redThreshold)*249 thresholdPascals = parseFloat(redThreshold)*249
} }
} }
@ -346,8 +344,8 @@ export default function GateDeviceInteraction(props: Props) {
when the difference between the pressures falls within this range and vice versa: when the difference between the pressures falls within this range and vice versa:
</Typography> </Typography>
<br /> <br />
<Typography>Upper Limit: {getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (highDelta/249.089).toFixed(2) + " iwg" : highDelta/1000 + " kPa"}</Typography> <Typography>Upper Limit: {user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (highDelta/249.089).toFixed(2) + " iwg" : highDelta/1000 + " kPa"}</Typography>
<Typography>Lower Limit: {getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (lowDelta/249.089).toFixed(2) + " iwg" : lowDelta/1000 + " kPa"}</Typography> <Typography>Lower Limit: {user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (lowDelta/249.089).toFixed(2) + " iwg" : lowDelta/1000 + " kPa"}</Typography>
<br /> <br />
<Typography>If you would like to have the interactions set in such a way that if the average pressure falls below a given value set the use off condition and set the value to use</Typography> <Typography>If you would like to have the interactions set in such a way that if the average pressure falls below a given value set the use off condition and set the value to use</Typography>
@ -372,7 +370,7 @@ export default function GateDeviceInteraction(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? "iwg" : "kPa"} {user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? "iwg" : "kPa"}
</InputAdornment> </InputAdornment>
) )
}} }}

View file

@ -19,7 +19,7 @@ import { pond } from "protobuf-ts/pond";
import { quack } from "protobuf-ts/quack"; import { quack } from "protobuf-ts/quack";
import { getTextSecondary } from "theme/text"; import { getTextSecondary } from "theme/text";
// import { getTextSecondary } from "theme"; // import { getTextSecondary } from "theme";
import { getDistanceUnit, getPressureUnit, roundTo } from "utils"; import { getDistanceUnit, roundTo } from "utils";
import { extract } from "utils/types"; import { extract } from "utils/types";
interface Enumeration { interface Enumeration {
@ -235,7 +235,8 @@ export class MeasurementDescriber {
} }
break; break;
case quack.MeasurementType.MEASUREMENT_TYPE_PRESSURE: case quack.MeasurementType.MEASUREMENT_TYPE_PRESSURE:
let pressureUnit = getPressureUnit(); let pressureUnit =
user?.pressureUnit() ?? pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER;
let isIWG = pressureUnit === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER; let isIWG = pressureUnit === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER;
this.details.label = "Pressure"; this.details.label = "Pressure";
this.details.unit = isIWG ? "iwg" : "kPa"; this.details.unit = isIWG ? "iwg" : "kPa";

View file

@ -1,5 +1,6 @@
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
//function is deprecated, use User.tempUnit() instead
export function getTemperatureUnit(): pond.TemperatureUnit { export function getTemperatureUnit(): pond.TemperatureUnit {
return localStorage.getItem("temperature") === "f" return localStorage.getItem("temperature") === "f"
? pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
@ -31,6 +32,7 @@ export const fahrenheitToCelsius = (fahrenheit: number) => {
return (fahrenheit - 32) * (5 / 9); return (fahrenheit - 32) * (5 / 9);
}; };
// function is deprecated, use User.pressureUnit() instead
export function getPressureUnit(): pond.PressureUnit { export function getPressureUnit(): pond.PressureUnit {
return localStorage.getItem("pressure") === "kpa" return localStorage.getItem("pressure") === "kpa"
? pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS ? pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS