From 26ecc3e5fdb6e5241f0511889029006aa1159c08 Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Thu, 8 Jan 2026 18:36:38 +0100 Subject: [PATCH] fix: convert wind direction degrees to cardinal string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- CHANGELOG.md | 9 +++++++++ pyproject.toml | 2 +- src/domains/tools/environment/service.py | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a68ae6..90f1f82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.10.11] - 2026-01-08 + +### Fixed + +- **Weather wind direction** - Convert integer degrees to cardinal direction string + - Scheduler stores wind_direction as degrees (e.g., 135) + - Schema expects string (e.g., "SE") + - Added `_degrees_to_cardinal()` conversion + ## [1.10.10] - 2026-01-08 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index e9501f4..1a7cd3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "core-api" -version = "1.10.10" +version = "1.10.11" description = "Core Code API - Infrastructure management and tools API" readme = "README.md" requires-python = ">=3.12" diff --git a/src/domains/tools/environment/service.py b/src/domains/tools/environment/service.py index 9aab2b8..ef75e82 100644 --- a/src/domains/tools/environment/service.py +++ b/src/domains/tools/environment/service.py @@ -43,13 +43,18 @@ class EnvironmentService: return None try: + # Handle wind direction - convert degrees to cardinal if integer + wind_dir = raw_data.get("wind_direction") or raw_data.get("wind_dir") + if isinstance(wind_dir, (int, float)): + wind_dir = self._degrees_to_cardinal(wind_dir) + return WeatherData( temperature=raw_data.get("temperature") or raw_data.get("temp"), feels_like=raw_data.get("feels_like") or raw_data.get("feelslike"), conditions=raw_data.get("conditions") or raw_data.get("weather") or raw_data.get("description"), humidity=raw_data.get("humidity"), wind_speed=raw_data.get("wind_speed") or raw_data.get("windspeed") or raw_data.get("wind"), - wind_direction=raw_data.get("wind_direction") or raw_data.get("wind_dir"), + wind_direction=wind_dir, pressure=raw_data.get("pressure"), visibility=raw_data.get("visibility"), uv_index=raw_data.get("uv_index") or raw_data.get("uv"), @@ -60,6 +65,13 @@ class EnvironmentService: logger.warning(f"Failed to parse weather data: {e}") return None + def _degrees_to_cardinal(self, degrees: float) -> str: + """Convert wind direction degrees to cardinal direction.""" + directions = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", + "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"] + index = round(degrees / 22.5) % 16 + return directions[index] + def _parse_forecast(self, raw_data: Any) -> Optional[List[ForecastDay]]: """ Parse raw forecast data into list of ForecastDay schemas.