Skip to content

Commit e85d8b0

Browse files
authored
Merge pull request #942 from matrixx567/popup_weather_forecast_fix
Fix number of forecast entities.
2 parents f34ac86 + e1cc4dd commit e85d8b0

File tree

7 files changed

+122
-34
lines changed

7 files changed

+122
-34
lines changed

custom_components/ui_lovelace_minimalist/lovelace/ulm_templates/actions/actions_card.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ ulm_actions_card:
104104
return popup_config.popup_variables;
105105
}
106106
}
107+
return {};
107108
]]]
108109
hold_action:
109110
action: >
@@ -134,7 +135,7 @@ ulm_actions_card:
134135
action = 'more-info'
135136
}
136137
137-
return action
138+
return action;
138139
]]]
139140
navigation_path: "[[[ return variables.ulm_card_hold_action == 'navigate' ? variables.ulm_card_hold_navigate_path : '/0' ]]]"
140141
haptic: "[[[ return variables.ulm_card_hold_haptic != null ? variables.ulm_card_hold_haptic : 'none' ]]]"
@@ -208,6 +209,7 @@ ulm_actions_card:
208209
return popup_config.popup_variables;
209210
}
210211
}
212+
return {};
211213
]]]
212214
double_tap_action:
213215
action: >
@@ -238,7 +240,7 @@ ulm_actions_card:
238240
action = 'more-info'
239241
}
240242
241-
return action
243+
return action;
242244
]]]
243245
navigation_path: "[[[ return variables.ulm_card_double_tap_action == 'navigate' ? variables.ulm_card_double_tap_navigate_path : '/0' ]]]"
244246
haptic: "[[[ return variables.ulm_card_double_tap_haptic != null ? variables.ulm_card_double_tap_haptic : 'none' ]]]"
@@ -312,4 +314,5 @@ ulm_actions_card:
312314
return popup_config.popup_variables;
313315
}
314316
}
317+
return {};
315318
]]]

custom_components/ui_lovelace_minimalist/lovelace/ulm_templates/actions/actions_icon.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ ulm_actions_icon:
121121
return popup_config.popup_variables;
122122
}
123123
}
124+
return {};
124125
]]]
125126
hold_action:
126127
action: >
@@ -242,6 +243,7 @@ ulm_actions_icon:
242243
return popup_config.popup_variables;
243244
}
244245
}
246+
return {};
245247
]]]
246248
double_tap_action:
247249
action: >
@@ -357,4 +359,5 @@ ulm_actions_icon:
357359
return popup_config.popup_variables;
358360
}
359361
}
362+
return {};
360363
]]]

custom_components/ui_lovelace_minimalist/lovelace/ulm_templates/actions/actions_name.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ ulm_actions_name:
111111
return popup_config.popup_variables;
112112
}
113113
}
114+
return {};
114115
]]]
115116
hold_action:
116117
action: >
@@ -222,6 +223,7 @@ ulm_actions_name:
222223
return popup_config.popup_variables;
223224
}
224225
}
226+
return {};
225227
]]]
226228
double_tap_action:
227229
action: >
@@ -333,4 +335,5 @@ ulm_actions_name:
333335
return popup_config.popup_variables;
334336
}
335337
}
338+
return {};
336339
]]]

custom_components/ui_lovelace_minimalist/lovelace/ulm_templates/popup_templates/popups/popup_weather_forecast.yaml

+68-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
popup_weather_forecast:
3+
variables:
4+
ulm_weather_popup_surpress_first_forecast: false
35
show_icon: false
46
show_name: false
57
show_label: false
@@ -97,37 +99,72 @@ popup_weather_forecast:
9799
temp: "[[[ return entity.attributes.temperature + '°' ]]]"
98100
tempminmax: "[[[ return 'Max. ' + entity.attributes.forecast[0].temperature + '° Min. ' + entity.attributes.forecast[0].templow + '°' ]]]"
99101
- type: "vertical-stack"
100-
cards:
101-
- type: "custom:button-card"
102-
template: "popup_weather_row"
103-
entity: "[[[ return entity.entity_id ]]]"
104-
variables:
105-
ulm_popup_weather_entity_idx: 0
106-
- type: "custom:button-card"
107-
template: "popup_weather_row"
108-
entity: "[[[ return entity.entity_id ]]]"
109-
variables:
110-
ulm_popup_weather_entity_idx: 1
111-
- type: "custom:button-card"
112-
template: "popup_weather_row"
113-
entity: "[[[ return entity.entity_id ]]]"
114-
variables:
115-
ulm_popup_weather_entity_idx: 2
116-
- type: "custom:button-card"
117-
template: "popup_weather_row"
118-
entity: "[[[ return entity.entity_id ]]]"
119-
variables:
120-
ulm_popup_weather_entity_idx: 3
121-
- type: "custom:button-card"
122-
template: "popup_weather_row"
123-
entity: "[[[ return entity.entity_id ]]]"
124-
variables:
125-
ulm_popup_weather_entity_idx: 4
126-
- type: "custom:button-card"
127-
template: "popup_weather_row"
128-
entity: "[[[ return entity.entity_id ]]]"
129-
variables:
130-
ulm_popup_weather_entity_idx: 5
102+
cards: >
103+
[[[
104+
let rows = [];
105+
106+
function generate_weather_row(index) {
107+
var row = {
108+
'type': 'custom:button-card',
109+
'template': 'popup_weather_row',
110+
'entity': entity.entity_id,
111+
'variables': {
112+
'ulm_popup_weather_entity_idx': index
113+
}
114+
};
115+
return row;
116+
}
117+
118+
let surpress_first_forecast = ('ulm_weather_popup_surpress_first_forecast' in variables) ? variables.ulm_weather_popup_surpress_first_forecast : false;
119+
120+
let index = 0;
121+
for (let forecast in entity.attributes.forecast) {
122+
123+
if ((index == 0) && surpress_first_forecast) {
124+
index++;
125+
continue;
126+
}
127+
128+
rows.push(generate_weather_row(index));
129+
index++;
130+
if (rows.length >= 6) {
131+
break;
132+
}
133+
}
134+
return rows;
135+
]]]
136+
# Code above create following cards
137+
# cards:
138+
# - type: "custom:button-card"
139+
# template: "popup_weather_row"
140+
# entity: "[[[ return entity.entity_id ]]]"
141+
# variables:
142+
# ulm_popup_weather_entity_idx: 0
143+
# - type: "custom:button-card"
144+
# template: "popup_weather_row"
145+
# entity: "[[[ return entity.entity_id ]]]"
146+
# variables:
147+
# ulm_popup_weather_entity_idx: 1
148+
# - type: "custom:button-card"
149+
# template: "popup_weather_row"
150+
# entity: "[[[ return entity.entity_id ]]]"
151+
# variables:
152+
# ulm_popup_weather_entity_idx: 2
153+
# - type: "custom:button-card"
154+
# template: "popup_weather_row"
155+
# entity: "[[[ return entity.entity_id ]]]"
156+
# variables:
157+
# ulm_popup_weather_entity_idx: 3
158+
# - type: "custom:button-card"
159+
# template: "popup_weather_row"
160+
# entity: "[[[ return entity.entity_id ]]]"
161+
# variables:
162+
# ulm_popup_weather_entity_idx: 4
163+
# - type: "custom:button-card"
164+
# template: "popup_weather_row"
165+
# entity: "[[[ return entity.entity_id ]]]"
166+
# variables:
167+
# ulm_popup_weather_entity_idx: 5
131168
buttons:
132169
card:
133170
type: "custom:button-card"

custom_components/ui_lovelace_minimalist/lovelace/ulm_templates/popup_templates/popups/popup_weather_radar.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
popup_weather_radar:
33
template: "popup_weather_forecast"
4+
variables:
5+
ulm_weather_popup_surpress_first_forecast: false
46
styles:
57
grid:
68
- grid-template-areas: "'header' 'content2' 'buttons' 'footer'"

docs/setup/custom_actions.md

+32
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,35 @@ show_name: false
345345
show_label: false
346346
show_units: false
347347
```
348+
349+
The usage of variables within the popup have some restrictions. Default variables of the popup don't work in the same
350+
way as for other custom button cards. The default variables -- defined in the variables section -- will always be overwritten by
351+
the custom actions caller.
352+
353+
The following code won't work on custom popup cards:
354+
355+
```yaml
356+
popup_weather_forecast:
357+
...
358+
variables:
359+
ulm_weather_popup_surpress_first_forecast: false
360+
...
361+
```
362+
363+
Instead of using the variables section of the card the variables must be checked within a JavaScript template. The following
364+
code shows an example how to check and define a default value of custom popup variable:
365+
366+
```yaml
367+
element: >
368+
[[[
369+
let surpress_first_forecast = ('ulm_weather_popup_surpress_first_forecast' in variables) ? variables.ulm_weather_popup_surpress_first_forecast : false;
370+
371+
if (surpress_first_forecast) {
372+
...
373+
}
374+
375+
return surpress_first_forecast;
376+
]]]
377+
```
378+
379+
The code checks if the variable is available before reading from the variabl and if the variable isn't available it will set a default value.

docs/usage/popups/popup_weather.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ To enable this popup, add the following code to your card:
2121
```yaml
2222
ulm_custom_popup:
2323
template: "popup_weather_forecast"
24+
entity: weather.xxx
2425
popup_variables:
25-
ulm_popup_weather_entity: weather.xxx
26+
ulm_weather_popup_surpress_first_forecast: false
2627
```
2728
29+
## Variables
30+
31+
| Variable | Default | Required | Notes |
32+
|-------------------------------------------|---------|------------------|-------------------------------|
33+
| entity | | :material-check: | |
34+
| ulm_weather_popup_surpress_first_forecast | false | :material-close: | Suppress first forecast entry |
35+
2836
## Credits
2937
3038
- Designed by schumijo

0 commit comments

Comments
 (0)