From a2944d7a60abc011a3ed5f8bea30c87d1cd51b00 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Wed, 25 Mar 2026 16:23:56 -0600 Subject: [PATCH] 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(). --- src/gate/GateDeviceInteraction.tsx | 12 +++++------- src/pbHelpers/MeasurementDescriber.ts | 5 +++-- src/utils/units.ts | 2 ++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/gate/GateDeviceInteraction.tsx b/src/gate/GateDeviceInteraction.tsx index 0303123..561a547 100644 --- a/src/gate/GateDeviceInteraction.tsx +++ b/src/gate/GateDeviceInteraction.tsx @@ -7,8 +7,6 @@ import moment from "moment"; import { pond, quack } from "protobuf-ts/pond"; import { useGlobalState, useInteractionsAPI, useSnackbar } from "providers"; import React, { useEffect, useState } from "react"; -import { getPressureUnit } from "utils"; - interface Props { open: boolean; close: (canceled: boolean) => void; @@ -186,9 +184,9 @@ export default function GateDeviceInteraction(props: Props) { //need to make sure the redthreshold is in pascals let thresholdPascals = 0 if(!isNaN(parseFloat(redThreshold))){ - if(getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS){ + if(user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS){ 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 } } @@ -346,8 +344,8 @@ export default function GateDeviceInteraction(props: Props) { when the difference between the pressures falls within this range and vice versa:
- Upper Limit: {getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (highDelta/249.089).toFixed(2) + " iwg" : highDelta/1000 + " kPa"} - Lower Limit: {getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (lowDelta/249.089).toFixed(2) + " iwg" : lowDelta/1000 + " kPa"} + Upper Limit: {user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (highDelta/249.089).toFixed(2) + " iwg" : highDelta/1000 + " kPa"} + Lower Limit: {user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (lowDelta/249.089).toFixed(2) + " iwg" : lowDelta/1000 + " kPa"}
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 @@ -372,7 +370,7 @@ export default function GateDeviceInteraction(props: Props) { InputProps={{ endAdornment: ( - {getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? "iwg" : "kPa"} + {user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? "iwg" : "kPa"} ) }} diff --git a/src/pbHelpers/MeasurementDescriber.ts b/src/pbHelpers/MeasurementDescriber.ts index b88f494..903987f 100644 --- a/src/pbHelpers/MeasurementDescriber.ts +++ b/src/pbHelpers/MeasurementDescriber.ts @@ -19,7 +19,7 @@ import { pond } from "protobuf-ts/pond"; import { quack } from "protobuf-ts/quack"; import { getTextSecondary } from "theme/text"; // import { getTextSecondary } from "theme"; -import { getDistanceUnit, getPressureUnit, roundTo } from "utils"; +import { getDistanceUnit, roundTo } from "utils"; import { extract } from "utils/types"; interface Enumeration { @@ -235,7 +235,8 @@ export class MeasurementDescriber { } break; 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; this.details.label = "Pressure"; this.details.unit = isIWG ? "iwg" : "kPa"; diff --git a/src/utils/units.ts b/src/utils/units.ts index 41b3601..a9ef570 100644 --- a/src/utils/units.ts +++ b/src/utils/units.ts @@ -1,5 +1,6 @@ import { pond } from "protobuf-ts/pond"; +//function is deprecated, use User.tempUnit() instead export function getTemperatureUnit(): pond.TemperatureUnit { return localStorage.getItem("temperature") === "f" ? pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT @@ -31,6 +32,7 @@ export const fahrenheitToCelsius = (fahrenheit: number) => { return (fahrenheit - 32) * (5 / 9); }; +// function is deprecated, use User.pressureUnit() instead export function getPressureUnit(): pond.PressureUnit { return localStorage.getItem("pressure") === "kpa" ? pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS