Skip to content

Temperature, catch bad latitude/longitude#3339

Merged
springfall2008 merged 1 commit intomainfrom
fixes8
Feb 9, 2026
Merged

Temperature, catch bad latitude/longitude#3339
springfall2008 merged 1 commit intomainfrom
fixes8

Conversation

@springfall2008
Copy link
Owner

No description provided.

@springfall2008 springfall2008 changed the title Catch bad latitude/longitude Temperature, catch bad latitude/longitude Feb 9, 2026
@springfall2008 springfall2008 marked this pull request as ready for review February 9, 2026 09:12
Copilot AI review requested due to automatic review settings February 9, 2026 09:12
@springfall2008 springfall2008 merged commit 92e33bb into main Feb 9, 2026
5 checks passed
@springfall2008 springfall2008 deleted the fixes8 branch February 9, 2026 09:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves robustness of the TemperatureAPI coordinate resolution by handling non-numeric latitude/longitude values before attempting to use them for Open-Meteo requests.

Changes:

  • Coerces temperature_latitude / temperature_longitude (or zone.home fallbacks) to floats.
  • Logs and returns (None, None) when coordinate values cannot be converted to floats.

Comment on lines +79 to +83
try:
latitude = float(latitude)
longitude = float(longitude)
except (TypeError, ValueError):
self.log("Warn: TemperatureAPI: Invalid latitude or longitude values: latitude {}, longitude {}".format(latitude, longitude))
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 +82
try:
latitude = float(latitude)
longitude = float(longitude)
except (TypeError, ValueError):
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.
Comment on lines +79 to +83
try:
latitude = float(latitude)
longitude = float(longitude)
except (TypeError, ValueError):
self.log("Warn: TemperatureAPI: Invalid latitude or longitude values: latitude {}, longitude {}".format(latitude, longitude))
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant