Skip to content

Commit

Permalink
make find_weather_sensor_by_location more strict about failing to fin…
Browse files Browse the repository at this point in the history
…d a sensor close enough

Signed-off-by: Nicolas Höning <[email protected]>
  • Loading branch information
nhoening committed Oct 8, 2024
1 parent a039ba4 commit a5a35e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
27 changes: 14 additions & 13 deletions flexmeasures_openweathermap/utils/locating.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def find_weather_sensor_by_location(
) -> Sensor | None:
"""
Try to find a weather sensor of fitting type close by.
Complain if the nearest weather sensor is further away than some minimum degrees.
Return None if the nearest weather sensor is further away than some minimum degrees or if no sensor was found at all.
"""
weather_sensor: Optional[Sensor] = Sensor.find_closest(
generic_asset_type_name=WEATHER_STATION_TYPE_NAME,
Expand All @@ -92,22 +92,23 @@ def find_weather_sensor_by_location(
lng=location[1],
n=1,
)
if weather_sensor is not None:
weather_station: GenericAsset = weather_sensor.generic_asset
if abs(
location[0] - weather_station.location[0]
) > max_degree_difference_for_nearest_weather_sensor or abs(
location[1] - weather_station.location[1]
> max_degree_difference_for_nearest_weather_sensor
):
current_app.logger.warning(
f"[FLEXMEASURES-OWM] We found a weather station, but no sufficiently close weather sensor found (within {max_degree_difference_for_nearest_weather_sensor} {flexmeasures_inflection.pluralize('degree', max_degree_difference_for_nearest_weather_sensor)} distance) for measuring {sensor_name}! We're looking for: {location}, closest available: ({weather_station.location})"
)
else:
if weather_sensor is None:
current_app.logger.warning(
"[FLEXMEASURES-OWM] No weather sensor set up yet for measuring %s. Try the register-weather-sensor CLI task."
% sensor_name
)
return None
weather_station: GenericAsset = weather_sensor.generic_asset
if abs(
location[0] - weather_station.location[0]
) > max_degree_difference_for_nearest_weather_sensor or abs(
location[1] - weather_station.location[1]
> max_degree_difference_for_nearest_weather_sensor
):
current_app.logger.warning(
f"[FLEXMEASURES-OWM] We found a weather station, but no sufficiently close weather sensor found (within {max_degree_difference_for_nearest_weather_sensor} {flexmeasures_inflection.pluralize('degree', max_degree_difference_for_nearest_weather_sensor)} distance) for measuring {sensor_name}! We're looking for: {location}, closest available: ({weather_station.location})"
)
return None
return weather_sensor


Expand Down
2 changes: 1 addition & 1 deletion flexmeasures_openweathermap/utils/owm.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def call_openweatherapi(
) -> Tuple[datetime, List[Dict]]:
"""
Make a single "one-call" to the Open Weather API and return the API timestamp as well as the 48 hourly forecasts.
See https://openweathermap.org/api/one-call-api for docs.
See https://openweathermap.org/api/one-call-3 for docs.
Note that the first forecast is about the current hour.
"""
check_openweathermap_version(API_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion run_mypy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
set -e
pip install --upgrade mypy > 1.4
pip install types-pytz types-requests types-Flask types-click types-redis types-tzlocal types-python-dateutil types-setuptools
files=$(find . -name \*.py -not -path "./venv/*" -not -path ".eggs/*" -not -path "./build/*" -not -path "./dist/*" -not -path "./scripts/*")
files=$(find flexmeasures_openweathermap -name \*.py)
mypy --follow-imports skip --ignore-missing-imports $files

0 comments on commit a5a35e0

Please sign in to comment.