Document that AdjustmentOptions are non-nullable
This commit is contained in:
@@ -5,9 +5,8 @@ import { WeatherProvider } from "../weatherProviders/WeatherProvider";
|
||||
export interface AdjustmentMethod {
|
||||
/**
|
||||
* Calculates the percentage that should be used to scale watering time.
|
||||
* @param adjustmentOptions The user-specified options for the calculation, or undefined/null if no custom values
|
||||
* are to be used. No checks will be made to ensure the AdjustmentOptions are the correct type that the function
|
||||
* is expecting or to ensure that any of its fields are valid.
|
||||
* @param adjustmentOptions The user-specified options for the calculation. No checks will be made to ensure the
|
||||
* AdjustmentOptions are the correct type that the function is expecting or to ensure that any of its fields are valid.
|
||||
* @param wateringData The basic weather information of the watering site. This may be undefined if an error occurred
|
||||
* while retrieving the data.
|
||||
* @param coordinates The coordinates of the watering site.
|
||||
|
||||
@@ -7,7 +7,7 @@ import { WateringData } from "../../types";
|
||||
*/
|
||||
async function calculateRainDelayWateringScale( adjustmentOptions: RainDelayAdjustmentOptions, wateringData: WateringData | undefined ): Promise< AdjustmentMethodResponse > {
|
||||
const raining = wateringData && wateringData.raining;
|
||||
const d = adjustmentOptions && adjustmentOptions.hasOwnProperty( "d" ) ? adjustmentOptions.d : 24;
|
||||
const d = adjustmentOptions.hasOwnProperty( "d" ) ? adjustmentOptions.d : 24;
|
||||
return {
|
||||
scale: undefined,
|
||||
rawData: { raining: raining ? 1 : 0 },
|
||||
|
||||
@@ -40,18 +40,15 @@ async function calculateZimmermanWateringScale( adjustmentOptions: ZimmermanAdju
|
||||
let humidityBase = 30, tempBase = 70, precipBase = 0;
|
||||
|
||||
// Get baseline conditions for 100% water level, if provided
|
||||
if ( adjustmentOptions ) {
|
||||
humidityBase = adjustmentOptions.hasOwnProperty( "bh" ) ? adjustmentOptions.bh : humidityBase;
|
||||
tempBase = adjustmentOptions.hasOwnProperty( "bt" ) ? adjustmentOptions.bt : tempBase;
|
||||
precipBase = adjustmentOptions.hasOwnProperty( "br" ) ? adjustmentOptions.br : precipBase;
|
||||
}
|
||||
|
||||
let humidityFactor = ( humidityBase - wateringData.humidity ),
|
||||
tempFactor = ( ( wateringData.temp - tempBase ) * 4 ),
|
||||
precipFactor = ( ( precipBase - wateringData.precip ) * 200 );
|
||||
|
||||
// Apply adjustment options, if provided, by multiplying the percentage against the factor
|
||||
if ( adjustmentOptions ) {
|
||||
if ( adjustmentOptions.hasOwnProperty( "h" ) ) {
|
||||
humidityFactor = humidityFactor * ( adjustmentOptions.h / 100 );
|
||||
}
|
||||
@@ -63,7 +60,6 @@ async function calculateZimmermanWateringScale( adjustmentOptions: ZimmermanAdju
|
||||
if ( adjustmentOptions.hasOwnProperty( "r" ) ) {
|
||||
precipFactor = precipFactor * ( adjustmentOptions.r / 100 );
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
// Apply all of the weather modifying factors and clamp the result between 0 and 200%.
|
||||
|
||||
Reference in New Issue
Block a user