Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/predbat/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def get_coordinates(self):
if longitude is None:
longitude = self.get_state_wrapper("zone.home", attribute="longitude")

try:
latitude = float(latitude)
longitude = float(longitude)
except (TypeError, ValueError):
Comment on lines +79 to +82
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because latitude/longitude are always either successfully converted to floats or the function returns in the except block, the later if latitude is not None and longitude is not None: check becomes redundant and the else branch is effectively unreachable. Consider handling the "missing" case before conversion (for clearer logging) or simplifying the control flow after the conversion.

Copilot uses AI. Check for mistakes.
self.log("Warn: TemperatureAPI: Invalid latitude or longitude values: latitude {}, longitude {}".format(latitude, longitude))
Comment on lines +79 to +83
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After coercing to float, values like NaN/Inf (e.g., float('nan')) or out-of-range coordinates (lat not in [-90, 90], lon not in [-180, 180]) will still pass and be used to build the API URL. Consider validating finiteness and bounds after float conversion and treating invalid values the same as the exception case (warn + return None, None) to avoid bad API requests.

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +83
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new invalid-coordinate handling isn’t covered by tests: there are no cases for non-numeric values (e.g., 'unknown'), NaN/Inf, or out-of-range lat/lon. Please extend the existing Temperature API test suite to assert get_coordinates() / fetch_temperature_data() returns None and logs a warning for these inputs.

Copilot generated this review using guidance from repository custom instructions.
return None, None

if latitude is not None and longitude is not None:
self.log("TemperatureAPI: Using coordinates latitude {}, longitude {}".format(dp1(latitude), dp1(longitude)))
return latitude, longitude
Expand Down
Loading