Skip to content

Commit

Permalink
[#786] Fix crash when wind direction is undefined (#791)
Browse files Browse the repository at this point in the history
* [#786] Fix crash when wind direction is undefined

* [Auto] Adding updated localization files

Files changed:
M	src/localize/languages/nn-NO.json
M	src/localize/languages/pt-BR.json
  • Loading branch information
decompil3d authored Jan 14, 2025
1 parent e679c5d commit 84fcf4a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 9 deletions.
107 changes: 107 additions & 0 deletions cypress/e2e/weather-bar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,113 @@ describe('Weather bar', () => {
})
});

it('handles undefined wind bearing', () => {
cy.addEntity({
'weather.undefined_wind_bearing': {
attributes: {
forecast: [
{
"datetime": "2022-07-21T17:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 0,
"pressure": 1007,
"wind_speed": 4.67,
// @ts-expect-error testing undefined wind_bearing
"wind_bearing": undefined,
"condition": "cloudy",
"clouds": 60,
"temperature": 84
},
{
"datetime": "2022-07-21T18:00:00+00:00",
"precipitation": 0.35,
"precipitation_probability": 0,
"pressure": 1007,
"wind_speed": 6.07,
// @ts-expect-error testing undefined wind_bearing
"wind_bearing": undefined,
"condition": "cloudy",
"clouds": 75,
"temperature": 85
},
{
"datetime": "2022-07-21T19:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 0,
"pressure": 1007,
"wind_speed": 6.16,
// @ts-expect-error testing undefined wind_bearing
"wind_bearing": undefined,
"condition": "cloudy",
"clouds": 60,
"temperature": 85
},
{
"datetime": "2022-07-21T20:00:00+00:00",
"precipitation": 1.3,
"precipitation_probability": 1,
"pressure": 1007,
"wind_speed": 5.9,
// @ts-expect-error testing undefined wind_bearing
"wind_bearing": undefined,
"condition": "partlycloudy",
"clouds": 49,
"temperature": 84
},
{
"datetime": "2022-07-21T21:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 1,
"pressure": 1007,
"wind_speed": 5.78,
// @ts-expect-error testing undefined wind_bearing
"wind_bearing": undefined,
"condition": "partlycloudy",
"clouds": 34,
"temperature": 84
},
{
"datetime": "2022-07-21T22:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 1,
"pressure": 1008,
"wind_speed": 5.06,
// @ts-expect-error testing undefined wind_bearing
"wind_bearing": undefined,
"condition": "partlycloudy",
"clouds": 19,
"temperature": 83
},
{
"datetime": "2022-07-21T23:00:00+00:00",
"precipitation": 0,
"precipitation_probability": 1,
"pressure": 1008,
"wind_speed": 6.39,
// @ts-expect-error testing undefined wind_bearing
"wind_bearing": undefined,
"condition": "sunny",
"clouds": 4,
"temperature": 79
}
]
}
}
});
cy.configure({
entity: 'weather.undefined_wind_bearing',
num_segments: '4',
show_wind: 'direction'
});
cy.get('weather-bar')
.shadow()
.find('div.axes > div.bar-block div.wind')
.should('have.length', 4)
.each((el) => {
cy.wrap(el).should('be.empty');
});
});

it('localizes wind bearing when entity provides as a string', () => {
cy.addEntity({
'weather.wind_bearing_string': {
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/localize/languages/nn-NO.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@
"card": {
"chance_of_precipitation": "{0}% sjanse for nedbør"
}
}
}
2 changes: 1 addition & 1 deletion src/localize/languages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@
"card": {
"chance_of_precipitation": "{0}% chance de precipitação"
}
}
}
4 changes: 2 additions & 2 deletions src/weather-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ export class WeatherBar extends LitElement {
const { windSpeed, windSpeedRawMS, windDirection, windDirectionRaw } = this.wind[i];

const wind: TemplateResult[] = [];
const bearing: number = typeof windDirectionRaw === 'number'
const bearing: number | undefined = typeof windDirectionRaw === 'number'
? windDirectionRaw
: DIRECTIONS_BEARINGS[windDirectionRaw.toLowerCase()];
: DIRECTIONS_BEARINGS[windDirectionRaw?.toLowerCase()];
if (showWindBarb && bearing !== undefined) {
wind.push(html`<span title=${`${windSpeed} ${windDirection}`}>
${this.getWindBarb(windSpeedRawMS, bearing)}
Expand Down

0 comments on commit 84fcf4a

Please sign in to comment.