@@ -155,7 +155,39 @@ class EnvCanadaProvider {
155155 #generateCurrentWeather ( xml ) {
156156 const current = { date : new Date ( ) } ;
157157
158- // Since <currentConditions/> is often empty, extract from first forecast period
158+ // Try to get temperature from currentConditions first
159+ const currentTempStr = 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) ;
160+
161+ if ( currentTempStr && currentTempStr !== "" ) {
162+ current . temperature = parseFloat ( currentTempStr ) ;
163+ this . cacheCurrentTemp = current . temperature ;
164+ } else {
165+ // Fallback: extract from first forecast period if currentConditions is empty
166+ const firstForecast = xml . match ( / < f o r e c a s t > ( .* ?) < \/ f o r e c a s t > / s) ;
167+ if ( firstForecast ) {
168+ const forecastXml = firstForecast [ 1 ] ;
169+ 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 > / ) ;
170+ if ( temp && temp !== "" ) {
171+ current . temperature = parseFloat ( temp ) ;
172+ this . cacheCurrentTemp = current . temperature ;
173+ } else if ( this . cacheCurrentTemp !== null ) {
174+ current . temperature = this . cacheCurrentTemp ;
175+ } else {
176+ current . temperature = null ;
177+ }
178+ }
179+ }
180+
181+ // Wind chill / humidex for feels like temperature
182+ const windChill = this . #extract( xml , / < w i n d C h i l l [ ^ > ] * > ( .* ?) < \/ w i n d C h i l l > / ) ;
183+ const humidex = this . #extract( xml , / < h u m i d e x [ ^ > ] * > ( .* ?) < \/ h u m i d e x > / ) ;
184+ if ( windChill ) {
185+ current . feelsLikeTemp = parseFloat ( windChill ) ;
186+ } else if ( humidex ) {
187+ current . feelsLikeTemp = parseFloat ( humidex ) ;
188+ }
189+
190+ // Get wind and icon from currentConditions or first forecast
159191 const firstForecast = xml . match ( / < f o r e c a s t > ( .* ?) < \/ f o r e c a s t > / s) ;
160192 if ( ! firstForecast ) {
161193 Log . warn ( "[envcanada] No forecast data available" ) ;
@@ -164,31 +196,34 @@ class EnvCanadaProvider {
164196
165197 const forecastXml = firstForecast [ 1 ] ;
166198
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 > / ) ;
169- if ( temp && temp !== "" ) {
170- current . temperature = parseFloat ( temp ) ;
171- this . cacheCurrentTemp = current . temperature ;
172- } else if ( this . cacheCurrentTemp !== null ) {
173- current . temperature = this . cacheCurrentTemp ;
174- } else {
175- current . temperature = null ;
199+ // Wind speed - try currentConditions first, fallback to forecast
200+ let windSpeed = this . #extract( xml , / < c u r r e n t C o n d i t i o n s > .* ?< w i n d > .* ?< s p e e d [ ^ > ] * > ( .* ?) < \/ s p e e d > / s) ;
201+ if ( ! windSpeed ) {
202+ windSpeed = this . #extract( forecastXml , / < s p e e d [ ^ > ] * > ( .* ?) < \/ s p e e d > / ) ;
176203 }
177-
178- // Wind speed
179- const windSpeed = this . #extract( forecastXml , / < s p e e d [ ^ > ] * > ( .* ?) < \/ s p e e d > / ) ;
180204 if ( windSpeed ) {
181205 current . windSpeed = ( windSpeed === "calm" ) ? 0 : convertKmhToMs ( parseFloat ( windSpeed ) ) ;
182206 }
183207
184- const windBearing = this . #extract( forecastXml , / < b e a r i n g [ ^ > ] * > ( .* ?) < \/ b e a r i n g > / ) ;
208+ // Wind bearing - try currentConditions first, fallback to forecast
209+ let windBearing = this . #extract( xml , / < c u r r e n t C o n d i t i o n s > .* ?< w i n d > .* ?< b e a r i n g [ ^ > ] * > ( .* ?) < \/ b e a r i n g > / s) ;
210+ if ( ! windBearing ) {
211+ windBearing = this . #extract( forecastXml , / < b e a r i n g [ ^ > ] * > ( .* ?) < \/ b e a r i n g > / ) ;
212+ }
185213 if ( windBearing ) current . windFromDirection = parseFloat ( windBearing ) ;
186214
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 > / ) ;
215+ // Try icon from currentConditions first, fallback to forecast
216+ let 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) ;
217+ if ( ! iconCode ) {
218+ iconCode = this . #extract( forecastXml , / < i c o n C o d e [ ^ > ] * > ( .* ?) < \/ i c o n C o d e > / ) ;
219+ }
189220 if ( iconCode ) current . weatherType = this . #convertWeatherType( iconCode ) ;
190221
191- // Precipitation probability
222+ // Humidity from currentConditions
223+ const humidity = this . #extract( xml , / < c u r r e n t C o n d i t i o n s > .* ?< 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 > / s) ;
224+ if ( humidity ) current . humidity = parseFloat ( humidity ) ;
225+
226+ // Precipitation probability from forecast
192227 const pop = this . #extract( forecastXml , / < p o p [ ^ > ] * > ( .* ?) < \/ p o p > / ) ;
193228 if ( pop && pop !== "" ) {
194229 current . precipitationProbability = parseFloat ( pop ) ;
0 commit comments