Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#786] Fix crash when wind direction is undefined #791

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading