UI icon indicating copy to clipboard operation
UI copied to clipboard

Weather has bug if forecast isn't available

Open matrixx567 opened this issue 2 years ago • 1 comments

Describe the bug

Weather throws an error

Expected behavior Show the popup

Screenshots Iimage

Additional context @schumijo My weather sensor has only 5 items. The popup_weather_forecasts expects 6 elements.

(5) [{…}, {…}, {…}, {…}, {…}]
0: {condition: 'partlycloudy', datetime: '2022-08-11T10:00:00+00:00', wind_bearing: 57.5, temperature: 25.2, templow: 11.2, …}
1: {condition: 'rainy', datetime: '2022-08-12T10:00:00+00:00', wind_bearing: 104.1, temperature: 20.4, templow: 12.3, …}
2: {condition: 'partlycloudy', datetime: '2022-08-13T10:00:00+00:00', wind_bearing: 30.2, temperature: 23.7, templow: 11.4, …}
3: {condition: 'partlycloudy', datetime: '2022-08-14T10:00:00+00:00', wind_bearing: 37.9, temperature: 25.5, templow: 14.2, …}
4: {condition: 'cloudy', datetime: '2022-08-15T10:00:00+00:00', wind_bearing: 95.9, temperature: 27.8, templow: 15.8, …}
length: 5

matrixx567 avatar Aug 10 '22 17:08 matrixx567

@schumijo

Quick solution to generate the rows dynamically

            cards: >
              [[[
                let rows = [];

                function generate_weather_row(index) {
                    var row = {
                      'type': 'custom:button-card',
                      'template': 'popup_weather_row',
                      'entity': entity.entity_id,
                      'variables': {
                        'ulm_popup_weather_entity_idx': index
                      }
                    };
                    return row;
                }
                
                let index = 0;
                for (let forecast in entity.attributes.forecast) {
                    rows.push(generate_weather_row(index));
                    index++;
                }
                return rows;
              ]]]

matrixx567 avatar Aug 10 '22 21:08 matrixx567