From dec9f31dec60907733f9339b2356bba8d2c3e10a Mon Sep 17 00:00:00 2001 From: Matthew Oslan Date: Thu, 23 May 2019 14:36:34 -0400 Subject: [PATCH] Revert "Add support for fallback WeatherProviders" This reverts commit 0e23e568172ec392b3fa34b131a20af0c3cabf7a. --- routes/weather.ts | 6 +-- .../CompositeWeatherProvider.ts | 45 ------------------- 2 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 routes/weatherProviders/CompositeWeatherProvider.ts diff --git a/routes/weather.ts b/routes/weather.ts index 7fa9497..1d292c0 100644 --- a/routes/weather.ts +++ b/routes/weather.ts @@ -6,11 +6,7 @@ import * as moment from "moment-timezone"; import * as geoTZ from "geo-tz"; import { AdjustmentOptions, GeoCoordinates, TimeData, WateringData, WeatherData, WeatherProvider } from "../types"; -import CompositeWeatherProvider from "./weatherProviders/CompositeWeatherProvider"; - -const weatherProvider: WeatherProvider = new CompositeWeatherProvider( - ( process.env.WEATHER_PROVIDER || "OWM" ).split( "," ).map( ( id ) => require( "./weatherProviders/" + id ).default ) -); +const weatherProvider: WeatherProvider = require("./weatherProviders/" + ( process.env.WEATHER_PROVIDER || "OWM" ) ).default; // Define regex filters to match against location const filters = { diff --git a/routes/weatherProviders/CompositeWeatherProvider.ts b/routes/weatherProviders/CompositeWeatherProvider.ts deleted file mode 100644 index c79e496..0000000 --- a/routes/weatherProviders/CompositeWeatherProvider.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { GeoCoordinates, WateringData, WeatherData, WeatherProvider } from "../../types"; - -/** - * A WeatherProvider calls other WeatherProviders until one successfully returns a value. - * This is a special utility WeatherProvider, and should NOT be selected with the WEATHER_PROVIDER environment variable. - */ -export default class CompositeWeatherProvider implements WeatherProvider { - - private readonly weatherProviders: WeatherProvider[]; - - public constructor( weatherProviders: WeatherProvider[] ) { - this.weatherProviders = weatherProviders; - } - - public async getWateringData( coordinates : GeoCoordinates ): Promise< WateringData > { - return await this.callMethod( "getWateringData", coordinates ) as WateringData; - } - - public async getWeatherData( coordinates : GeoCoordinates ): Promise< WeatherData > { - return await this.callMethod( "getWeatherData", coordinates ) as WeatherData; - } - - /** - * Calls a specified function in each WeatherProvider until one returns a non-undefined value. If the function is - * not defined for a WeatherProvider, it will be skipped. - * @param func The name of the function to call. - * @param args The arguments to pass to the function. - * @return A promise that will be resolved with the first non-undefined value returned by a WeatherProvider, or - * resolved with undefined if none of the WeatherProviders returned a value. - */ - private async callMethod( func: "getWateringData" | "getWeatherData", ...args: any ): Promise< unknown > { - for ( const weatherProvider of this.weatherProviders ) { - if ( !weatherProvider[ func ] ) { - continue; - } - - // @ts-ignore - const result = await weatherProvider[ func ]( ...args ); - if ( result ) { - return result; - } - } - return undefined; - } -}