From 5adc84931704c61d76b19f0dc596e2a8fbb527db Mon Sep 17 00:00:00 2001 From: Matthias Kollmann Date: Mon, 9 Dec 2024 15:38:13 +0100 Subject: [PATCH] fixed parser errors (#34) Co-authored-by: Jeremy Greenwood --- .../Internal/Extensions/APICurrentWeather+Map.swift | 1 + .../Internal/Extensions/APIForecastHourly+Map.swift | 2 ++ .../Internal/Extensions/UnitSpeed.swift | 12 ++++++++++++ .../Internal/Models/APICurrentWeather.swift | 2 +- .../Internal/Models/APIForecastHourly.swift | 4 +++- .../Internal/Models/APIWeatherAlerts.swift | 2 +- .../Public/Characteristics/AlertSummary.swift | 4 ++-- .../OpenWeatherKit/Public/Forecast/HourWeather.swift | 6 ++++++ .../Public/Requests/CurrentWeather.swift | 5 +++++ 9 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 Sources/OpenWeatherKit/Internal/Extensions/UnitSpeed.swift diff --git a/Sources/OpenWeatherKit/Internal/Extensions/APICurrentWeather+Map.swift b/Sources/OpenWeatherKit/Internal/Extensions/APICurrentWeather+Map.swift index 996d37b..6cf9584 100644 --- a/Sources/OpenWeatherKit/Internal/Extensions/APICurrentWeather+Map.swift +++ b/Sources/OpenWeatherKit/Internal/Extensions/APICurrentWeather+Map.swift @@ -16,6 +16,7 @@ extension APICurrentWeather { symbolName: (WeatherCondition(rawValue: conditionCode) ?? .undefined).sfSymbol, dewPoint: Measurement(value: temperatureDewPoint, unit: .celsius), humidity: humidity, + percipationIntensity: Measurement(value: precipitationIntensity, unit: .millimetersPerHour), pressure: Measurement(value: pressure, unit: .millibars), pressureTrend: PressureTrend(rawValue: pressureTrend) ?? .undefined, isDaylight: daylight, diff --git a/Sources/OpenWeatherKit/Internal/Extensions/APIForecastHourly+Map.swift b/Sources/OpenWeatherKit/Internal/Extensions/APIForecastHourly+Map.swift index b74b4a9..358b871 100644 --- a/Sources/OpenWeatherKit/Internal/Extensions/APIForecastHourly+Map.swift +++ b/Sources/OpenWeatherKit/Internal/Extensions/APIForecastHourly+Map.swift @@ -31,6 +31,8 @@ extension APIHour { precipitationAmount: Measurement(value: precipitationAmount, unit: .millimeters), pressure: Measurement(value: pressure, unit: .millibars), pressureTrend: PressureTrend(rawValue: pressureTrend) ?? .undefined, + snowfallIntensity: Measurement(value: snowfallIntensity ?? 0.0, unit: .millimetersPerHour), + snowfallAmount: Measurement(value: snowfallAmount ?? 0.0, unit: .millimeters), temperature: Measurement(value: temperature, unit: .celsius), apparentTemperature: Measurement(value: temperatureApparent, unit: .celsius), uvIndex: UVIndex(value: uvIndex, category: .init(value: uvIndex)), diff --git a/Sources/OpenWeatherKit/Internal/Extensions/UnitSpeed.swift b/Sources/OpenWeatherKit/Internal/Extensions/UnitSpeed.swift new file mode 100644 index 0000000..d0e76f0 --- /dev/null +++ b/Sources/OpenWeatherKit/Internal/Extensions/UnitSpeed.swift @@ -0,0 +1,12 @@ +// +// UnitSpeed.swift +// open-weather-kit +// +// Created by Matthias Kollmann on 20.11.24. +// + +import Foundation + +extension UnitSpeed { + static let millimetersPerHour: UnitSpeed = UnitSpeed(symbol: "mm/h", converter: UnitConverterLinear(coefficient: 1.0/3.6)) +} diff --git a/Sources/OpenWeatherKit/Internal/Models/APICurrentWeather.swift b/Sources/OpenWeatherKit/Internal/Models/APICurrentWeather.swift index 46203e3..b47d088 100644 --- a/Sources/OpenWeatherKit/Internal/Models/APICurrentWeather.swift +++ b/Sources/OpenWeatherKit/Internal/Models/APICurrentWeather.swift @@ -16,7 +16,7 @@ struct APICurrentWeather: Codable, Equatable { let conditionCode: String let daylight: Bool let humidity: Double - let precipitationIntensity: Int + let precipitationIntensity: Double let pressure: Double let pressureTrend: String let temperature: Double diff --git a/Sources/OpenWeatherKit/Internal/Models/APIForecastHourly.swift b/Sources/OpenWeatherKit/Internal/Models/APIForecastHourly.swift index 4fe227a..e7f743f 100644 --- a/Sources/OpenWeatherKit/Internal/Models/APIForecastHourly.swift +++ b/Sources/OpenWeatherKit/Internal/Models/APIForecastHourly.swift @@ -33,7 +33,8 @@ struct APIHour: Codable, Equatable { let precipitationType: String let pressure: Double let pressureTrend: String - let snowfallIntensity: Int + let snowfallIntensity: Double? + let snowfallAmount: Double? let temperature: Double let temperatureApparent: Double let temperatureDewPoint: Double @@ -56,6 +57,7 @@ struct APIHour: Codable, Equatable { case pressure = "pressure" case pressureTrend = "pressureTrend" case snowfallIntensity = "snowfallIntensity" + case snowfallAmount = "snowfallAmount" case temperature = "temperature" case temperatureApparent = "temperatureApparent" case temperatureDewPoint = "temperatureDewPoint" diff --git a/Sources/OpenWeatherKit/Internal/Models/APIWeatherAlerts.swift b/Sources/OpenWeatherKit/Internal/Models/APIWeatherAlerts.swift index e26211c..358b484 100644 --- a/Sources/OpenWeatherKit/Internal/Models/APIWeatherAlerts.swift +++ b/Sources/OpenWeatherKit/Internal/Models/APIWeatherAlerts.swift @@ -26,7 +26,7 @@ struct APIAlertSummary: Codable, Equatable { let name: String let id: String let areaID: String - let areaName: String + let areaName: String? let attributionURL: String let countryCode: String let alertDescription: String diff --git a/Sources/OpenWeatherKit/Public/Characteristics/AlertSummary.swift b/Sources/OpenWeatherKit/Public/Characteristics/AlertSummary.swift index abb8479..76116b2 100644 --- a/Sources/OpenWeatherKit/Public/Characteristics/AlertSummary.swift +++ b/Sources/OpenWeatherKit/Public/Characteristics/AlertSummary.swift @@ -13,7 +13,7 @@ public struct AlertSummary: Codable, Equatable, Sendable { public var name: String public var id: String public var areaID: String - public var areaName: String + public var areaName: String? public var attributionURL: String public var countryCode: String public var alertDescription: String @@ -34,7 +34,7 @@ public struct AlertSummary: Codable, Equatable, Sendable { name: String, id: String, areaID: String, - areaName: String, + areaName: String?, attributionURL: String, countryCode: String, alertDescription: String, diff --git a/Sources/OpenWeatherKit/Public/Forecast/HourWeather.swift b/Sources/OpenWeatherKit/Public/Forecast/HourWeather.swift index bc87b0f..de59043 100644 --- a/Sources/OpenWeatherKit/Public/Forecast/HourWeather.swift +++ b/Sources/OpenWeatherKit/Public/Forecast/HourWeather.swift @@ -54,6 +54,12 @@ public struct HourWeather: Sendable { /// The pressure trend, or barometric tendency, is the kind and amount of atmospheric pressure /// change over time. public var pressureTrend: PressureTrend + + /// The rate at which snow crystals are falling, in millimeters per hour. + public var snowfallIntensity: Measurement + + /// The amount of snowfall for the hour. + public var snowfallAmount: Measurement /// The temperature during the hour. public var temperature: Measurement diff --git a/Sources/OpenWeatherKit/Public/Requests/CurrentWeather.swift b/Sources/OpenWeatherKit/Public/Requests/CurrentWeather.swift index 0a6d0ca..21bb3f7 100644 --- a/Sources/OpenWeatherKit/Public/Requests/CurrentWeather.swift +++ b/Sources/OpenWeatherKit/Public/Requests/CurrentWeather.swift @@ -17,6 +17,7 @@ public struct CurrentWeather: Sendable { symbolName: String, dewPoint: Measurement, humidity: Double, + percipationIntensity: Measurement, pressure: Measurement, pressureTrend: PressureTrend, isDaylight: Bool, @@ -33,6 +34,7 @@ public struct CurrentWeather: Sendable { self.symbolName = symbolName self.dewPoint = dewPoint self.humidity = humidity + self.percipationIntensity = percipationIntensity self.pressure = pressure self.pressureTrend = pressureTrend self.isDaylight = isDaylight @@ -69,6 +71,9 @@ public struct CurrentWeather: Sendable { /// /// The range of this property is from 0 to 1, inclusive. public var humidity: Double + + /// The precipitation intensity, in millimeters per hour. + public var percipationIntensity: Measurement /// The atmospheric pressure at sea level at a given location. ///