From e83f8890b0db19ab4407196daea9110572ecf23d Mon Sep 17 00:00:00 2001 From: Jonathan Keslin Date: Tue, 14 Jan 2025 09:31:13 -0800 Subject: [PATCH 1/2] [#786] Fix crash when wind direction is undefined --- cypress/e2e/weather-bar.cy.ts | 107 ++++++++++++++++++++++++++++++++++ package-lock.json | 10 ++-- src/weather-bar.ts | 4 +- 3 files changed, 114 insertions(+), 7 deletions(-) diff --git a/cypress/e2e/weather-bar.cy.ts b/cypress/e2e/weather-bar.cy.ts index b959a2e7..41c6df97 100644 --- a/cypress/e2e/weather-bar.cy.ts +++ b/cypress/e2e/weather-bar.cy.ts @@ -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': { diff --git a/package-lock.json b/package-lock.json index 44ded600..22d775ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lovelace-hourly-weather", - "version": "6.5.0", + "version": "6.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "lovelace-hourly-weather", - "version": "6.5.0", + "version": "6.6.0", "license": "MIT", "dependencies": { "@lit-labs/scoped-registry-mixin": "^1.0.3", @@ -2896,9 +2896,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "dependencies": { "path-key": "^3.1.0", diff --git a/src/weather-bar.ts b/src/weather-bar.ts index f4c2fee6..037b0a7e 100644 --- a/src/weather-bar.ts +++ b/src/weather-bar.ts @@ -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` ${this.getWindBarb(windSpeedRawMS, bearing)} From ebfe4e89342ca65076a4895ef75f1688304727ec Mon Sep 17 00:00:00 2001 From: decompil3d Date: Tue, 14 Jan 2025 17:31:53 +0000 Subject: [PATCH 2/2] [Auto] Adding updated localization files Files changed: M src/localize/languages/nn-NO.json M src/localize/languages/pt-BR.json --- src/localize/languages/nn-NO.json | 2 +- src/localize/languages/pt-BR.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/localize/languages/nn-NO.json b/src/localize/languages/nn-NO.json index a1a735b6..9cf614a4 100644 --- a/src/localize/languages/nn-NO.json +++ b/src/localize/languages/nn-NO.json @@ -76,4 +76,4 @@ "card": { "chance_of_precipitation": "{0}% sjanse for nedbør" } -} +} \ No newline at end of file diff --git a/src/localize/languages/pt-BR.json b/src/localize/languages/pt-BR.json index 845914e1..e328fa7d 100644 --- a/src/localize/languages/pt-BR.json +++ b/src/localize/languages/pt-BR.json @@ -76,4 +76,4 @@ "card": { "chance_of_precipitation": "{0}% chance de precipitação" } -} +} \ No newline at end of file