@@ -84,8 +84,9 @@ class EnvCanadaProvider {
8484 const cityPageURL = this . #extractCityPageURL( html ) ;
8585
8686 if ( ! cityPageURL ) {
87- // This can happen during hour transitions when old responses arrive
87+ // This can happen during hour transitions when old responses arrive
8888 Log . debug ( "[envcanada] Could not find city page URL (may be stale response from previous hour)" ) ;
89+ return ;
8990 }
9091
9192 if ( cityPageURL === this . lastCityPageURL ) {
@@ -154,8 +155,17 @@ class EnvCanadaProvider {
154155 #generateCurrentWeather ( xml ) {
155156 const current = { date : new Date ( ) } ;
156157
157- // Temperature (with caching for missing values)
158- const temp = this . #extract( xml , / < c u r r e n t C o n d i t i o n s > .* ?< t e m p e r a t u r e [ ^ > ] * > ( .* ?) < \/ t e m p e r a t u r e > / s) ;
158+ // Since <currentConditions/> is often empty, extract from first forecast period
159+ const firstForecast = xml . match ( / < f o r e c a s t > ( .* ?) < \/ f o r e c a s t > / s) ;
160+ if ( ! firstForecast ) {
161+ Log . warn ( "[envcanada] No forecast data available" ) ;
162+ return current ;
163+ }
164+
165+ const forecastXml = firstForecast [ 1 ] ;
166+
167+ // Temperature from first forecast (class can be "high" or "low" depending on time of day)
168+ const temp = this . #extract( forecastXml , / < t e m p e r a t u r e [ ^ > ] * > ( .* ?) < \/ t e m p e r a t u r e > / ) ;
159169 if ( temp && temp !== "" ) {
160170 current . temperature = parseFloat ( temp ) ;
161171 this . cacheCurrentTemp = current . temperature ;
@@ -165,32 +175,26 @@ class EnvCanadaProvider {
165175 current . temperature = null ;
166176 }
167177
168- // Wind
169- const windSpeed = this . #extract( xml , / < w i n d > .* ?< s p e e d [ ^ > ] * > ( .* ?) < \/ s p e e d > / s) ;
170- current . windSpeed = ( windSpeed === "calm" ) ? 0 : convertKmhToMs ( parseFloat ( windSpeed ) ) ;
178+ // Wind speed
179+ const windSpeed = this . #extract( forecastXml , / < s p e e d [ ^ > ] * > ( .* ?) < \/ s p e e d > / ) ;
180+ if ( windSpeed ) {
181+ current . windSpeed = ( windSpeed === "calm" ) ? 0 : convertKmhToMs ( parseFloat ( windSpeed ) ) ;
182+ }
171183
172- const windBearing = this . #extract( xml , / < w i n d > . * ? < b e a r i n g [ ^ > ] * > ( .* ?) < \/ b e a r i n g > / s ) ;
184+ const windBearing = this . #extract( forecastXml , / < b e a r i n g [ ^ > ] * > ( .* ?) < \/ b e a r i n g > / ) ;
173185 if ( windBearing ) current . windFromDirection = parseFloat ( windBearing ) ;
174186
175- // Humidity
176- const humidity = this . #extract( xml , / < r e l a t i v e H u m i d i t y [ ^ > ] * > ( .* ?) < \/ r e l a t i v e H u m i d i t y > / ) ;
177- if ( humidity ) current . humidity = parseFloat ( humidity ) ;
178-
179- // Feels like
180- current . feelsLikeTemp = current . temperature ;
181- const windChill = this . #extract( xml , / < w i n d C h i l l [ ^ > ] * > ( .* ?) < \/ w i n d C h i l l > / ) ;
182- const humidex = this . #extract( xml , / < h u m i d e x [ ^ > ] * > ( .* ?) < \/ h u m i d e x > / ) ;
183- if ( windChill ) {
184- current . feelsLikeTemp = parseFloat ( windChill ) ;
185- } else if ( humidex ) {
186- current . feelsLikeTemp = parseFloat ( humidex ) ;
187- }
188-
189- // Weather type
190- const iconCode = this . #extract( xml , / < c u r r e n t C o n d i t i o n s > .* ?< i c o n C o d e [ ^ > ] * > ( .* ?) < \/ i c o n C o d e > / s) ;
187+ // Weather type from icon code
188+ const iconCode = this . #extract( forecastXml , / < i c o n C o d e [ ^ > ] * > ( .* ?) < \/ i c o n C o d e > / ) ;
191189 if ( iconCode ) current . weatherType = this . #convertWeatherType( iconCode ) ;
192190
193- // Sunrise/sunset
191+ // Precipitation probability
192+ const pop = this . #extract( forecastXml , / < p o p [ ^ > ] * > ( .* ?) < \/ p o p > / ) ;
193+ if ( pop && pop !== "" ) {
194+ current . precipitationProbability = parseFloat ( pop ) ;
195+ }
196+
197+ // Sunrise/sunset (from riseSet, independent of currentConditions)
194198 const sunriseTime = this . #extract( xml , / < d a t e T i m e [ ^ > ] * n a m e = " s u n r i s e " [ ^ > ] * > .* ?< t i m e S t a m p > ( .* ?) < \/ t i m e S t a m p > / s) ;
195199 const sunsetTime = this . #extract( xml , / < d a t e T i m e [ ^ > ] * n a m e = " s u n s e t " [ ^ > ] * > .* ?< t i m e S t a m p > ( .* ?) < \/ t i m e S t a m p > / s) ;
196200 if ( sunriseTime ) current . sunrise = this . #parseECTime( sunriseTime ) ;
0 commit comments