mirror of
https://github.com/GeorgeSG/sarah.git
synced 2026-06-15 17:12:59 +00:00
Be safer with entities in templates
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
v3_badge_humidity:
|
||||
template: v3_badge
|
||||
state_display: "[[[ return Number.parseFloat(entity.state.split(' ')[0]).toFixed(1) + '%' ]]]"
|
||||
state_display: "[[[ return Number.parseFloat(entity?.state.split(' ')[0]).toFixed(1) + '%' ]]]"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
v3_badge_temp:
|
||||
template: v3_badge
|
||||
state_display: "[[[ return Number.parseFloat(entity.state.split(' ')[0]).toFixed(1) + '°' ]]]"
|
||||
state_display: "[[[ return Number.parseFloat(entity?.state.split(' ')[0]).toFixed(1) + '°' ]]]"
|
||||
|
||||
@@ -10,9 +10,9 @@ v3_button_ac:
|
||||
if (entity.state === "off") {
|
||||
return "Off";
|
||||
}
|
||||
return entity.attributes.hvac_action.charAt(0).toUpperCase() +
|
||||
entity.attributes.hvac_action.slice(1) + ' to ' +
|
||||
entity.attributes.temperature + '°';
|
||||
return entity.attributes?.hvac_action?.charAt(0).toUpperCase() +
|
||||
entity.attributes?.hvac_action?.slice(1) + ' to ' +
|
||||
entity.attributes?.temperature + '°';
|
||||
]]]
|
||||
state:
|
||||
- value: 'off'
|
||||
|
||||
@@ -2,6 +2,6 @@ v3_button_cover:
|
||||
template: [v3_button, cover]
|
||||
state_display: |
|
||||
[[[
|
||||
if (entity.state === 'closed') { return 'Closed' }
|
||||
return entity.attributes.current_position + '% Open';
|
||||
if (entity?.state === 'closed') { return 'Closed' }
|
||||
return entity?.attributes?.current_position + '% Open';
|
||||
]]]
|
||||
|
||||
@@ -2,6 +2,6 @@ v3_button_light:
|
||||
template: v3_button
|
||||
state_display: |
|
||||
[[[
|
||||
if (entity.state === 'off') { return 'Off'; }
|
||||
return Math.round(entity.attributes.brightness * 100 / 255) + "%";
|
||||
if (entity?.state === 'off') { return 'Off'; }
|
||||
return Math.round(entity?.attributes?.brightness * 100 / 255) + "%";
|
||||
]]]
|
||||
|
||||
@@ -4,7 +4,7 @@ v3_button_power:
|
||||
power_sensor:
|
||||
state_display: |
|
||||
[[[
|
||||
if (entity.state === 'off') return 'Off';
|
||||
if (entity?.state === 'off') return 'Off';
|
||||
return states[variables.power_sensor].state + " W";
|
||||
]]]
|
||||
icon: mdi:power-socket
|
||||
|
||||
@@ -2,9 +2,9 @@ v3_button_purifier:
|
||||
template: v3_button
|
||||
state_display: |
|
||||
[[[
|
||||
if (entity.state === 'off') { return 'Off'; }
|
||||
if (!entity.attributes.preset_mode) { return 'Unknown preset'; }
|
||||
return entity.attributes.preset_mode.charAt(0).toUpperCase() + entity.attributes.preset_mode.slice(1);
|
||||
if (entity?.state === 'off') { return 'Off'; }
|
||||
if (!entity?.attributes.preset_mode) { return 'Unknown preset'; }
|
||||
return entity?.attributes?.preset_mode.charAt(0).toUpperCase() + entity?.attributes?.preset_mode.slice(1);
|
||||
]]]
|
||||
variables:
|
||||
value_has_error: |
|
||||
|
||||
@@ -3,10 +3,10 @@ v3_button_radiator:
|
||||
icon: mdi:radiator
|
||||
state_display: |
|
||||
[[[
|
||||
if (entity.state === 'off') { return 'Off'};
|
||||
return entity.state.charAt(0).toUpperCase() +
|
||||
entity.state.slice(1) + " to " +
|
||||
entity.attributes.temperature + '°';
|
||||
if (entity?.state === 'off') { return 'Off'};
|
||||
return entity?.state.charAt(0).toUpperCase() +
|
||||
entity?.state.slice(1) + " to " +
|
||||
entity?.attributes?.temperature + '°';
|
||||
]]]
|
||||
tap_action:
|
||||
action: call-service
|
||||
|
||||
Reference in New Issue
Block a user