Skip to content

Commit

Permalink
fix sensor schema validation and raise Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad-Wahid committed Jul 27, 2023
1 parent 96a7c53 commit 6a93236
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 6 additions & 1 deletion flexmeasures_openweathermap/cli/schemas/weather_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def validate_name_is_supported(self, name: str):

@validates_schema(skip_on_field_errors=False)
def validate_name_is_unique_in_weather_station(self, data, **kwargs):
if "name" not in data:
if (
"name" not in data
or "latitude" not in data
or "longitude" not in data
or "asset_id" not in data
):
return # That's a different validation problem
if data["latitude"] is not None and data["longitude"] is not None:
weather_station = get_or_create_weather_station(
Expand Down
5 changes: 2 additions & 3 deletions flexmeasures_openweathermap/utils/locating.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Tuple, List, Optional

import click
from flask import current_app

from flexmeasures.utils.grid_cells import LatLngGrid, get_cell_nums
from flexmeasures import Sensor
Expand Down Expand Up @@ -100,11 +99,11 @@ def find_weather_sensor_by_location(
location[1] - weather_station.location[1]
> max_degree_difference_for_nearest_weather_sensor
):
current_app.logger.warning(
raise Warning(
f"[FLEXMEASURES-OWM] 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:
current_app.logger.warning(
raise Warning(
"[FLEXMEASURES-OWM] No weather sensor set up yet for measuring %s. Try the register-weather-sensor CLI task."
% sensor_name
)
Expand Down

0 comments on commit 6a93236

Please sign in to comment.