@@ -22,84 +22,27 @@ ulm_translation_engine:
22
22
return (!not_active.includes(entity.state) && !containsNumbers(entity.state))
23
23
}
24
24
]]]
25
- ulm_translation_hour : >
26
- [[[
27
- var number = hass.resources[hass['language']]["ui.duration.hour"];
28
- var matches = number.match(/[^{\}]+(?=})/g);
29
- var hour = "Hour";
30
- if (matches) {
31
- var hour = matches[1];
32
- }
33
- return(hour);
34
- ]]]
35
- ulm_translation_hours : >
36
- [[[
37
- var number = hass.resources[hass['language']]["ui.duration.hour"];
38
- var matches = number.match(/[^{\}]+(?=})/g);
39
- var hour = "Hours";
40
- if (matches) {
41
- var hour = matches[2];
42
- }
43
- return(hour);
44
- ]]]
45
- ulm_translation_hvac : >
46
- [[[
47
- if (typeof(entity) !== 'undefined' && entity !== undefined){
48
- let state = entity.state;
49
- let d_class = entity.attributes.device_class;
50
- let def = ["unknown", "unavailable"];
51
- let lang = hass["language"];
52
- let action = entity.attributes.hvac_action;
53
- let domain = entity.entity_id.substr(0, entity.entity_id.indexOf("."));
54
- var mode = hass.resources[lang]["state_attributes." + domain + ".hvac_action." + action];
55
- if (def.includes(state)) {
56
- var mode = hass.resources[lang]["state.default." + state ];
57
- }
58
- var label = hass.resources[lang]["component." + domain + ".state._." + state];
59
- var translation = label ? label : state;
60
- return (entity.attributes.current_temperature ) + '°' + ' • ' + translation + ((entity.state !='off' && mode !== undefined) ? ' (' + mode + ')' : '');
61
- }
62
- ]]]
63
25
ulm_translation_off : " [[[ return hass.resources[hass['language']]['state.default.off']; ]]]"
64
26
ulm_translation_on : " [[[ return hass.resources[hass['language']]['state.default.on']; ]]]"
65
27
ulm_translation_state : >
66
28
[[[
67
29
if (typeof(entity) !== 'undefined' && entity !== undefined){
68
- let state = entity.state;
69
- let d_class = entity.attributes.device_class;
70
- let def = ["unknown", "unavailable"];
30
+ let device_class = entity.attributes.device_class;
71
31
let lang = hass["language"];
32
+ let action = entity.attributes.hvac_action;
72
33
let domain = entity.entity_id.substr(0, entity.entity_id.indexOf("."));
73
- var translation = hass.resources[lang]["component." + domain + ".entity_component._.state." + state]
74
- let display_precision = hass.entities[entity.entity_id]?.display_precision
75
- const now = new Date();
76
- const timestamp = (new Date(state)).getTime();
77
- const nowTimeStamp = now.getTime();
78
- const microSecondsDiff = Math.round(timestamp - nowTimeStamp);
79
- const daysDiff = Math.round(microSecondsDiff / (1000 * 60 * 60 * 24));
80
- const hoursDiff = Math.round(microSecondsDiff / (1000 * 60 * 60));
81
- const minutesDiff = Math.round(microSecondsDiff / (1000 * 60));
82
- const secondsDiff = Math.round(microSecondsDiff / (1000));
83
- const formatter = new Intl.RelativeTimeFormat(lang, { numeric: 'auto' });
84
- var scale = 'day'
85
- var diff = daysDiff
86
- if (Math.abs(secondsDiff) < 60){ scale = 'second'; diff = secondsDiff }
87
- else if (Math.abs(minutesDiff) < 60){ scale = 'minute'; diff = minutesDiff }
88
- else if (Math.abs(hoursDiff) < 24){ scale = 'hour'; diff = hoursDiff }
89
-
90
- if (def.includes(state)) {
91
- var translation = hass.resources[lang]["state.default." + state ];
92
- }
93
- else if (domain == "binary_sensor" && d_class != ''){
94
- var translation = hass.resources[lang]["component." + domain + ".entity_component." + d_class + ".state." + state]
34
+ let mode = hass.resources[lang]["state_attributes." + domain + ".hvac_action." + action];
35
+ if(variables.ulm_show_last_changed){
36
+ return helpers.relativeTime(entity.last_changed, true)
95
37
}
96
- else if (d_class == 'timestamp'){
97
- var translation = formatter.format(diff, scale )
38
+ if(device_class == 'timestamp'){
39
+ return helpers.relativeTime(entity.state, true )
98
40
}
99
- else if (parseFloat(display_precision) >=0){
100
- var translation = parseFloat(entity.state).toFixed(display_precision?.toString())
41
+ if(entity.entity_id.startsWith("climate.")){
42
+ return helpers.localize(entity, entity.attributes.current_temperature) + ' • ' +
43
+ helpers.localize(entity) + ((entity.state !='off' && mode !== undefined) ? ' (' + mode + ')' : '');
101
44
}
102
- return translation ? translation.charAt(0).toUpperCase() + translation.slice(1) : state;
45
+ return helpers.localize(entity)
103
46
}
104
47
]]]
105
48
ulm_translation_state_reverse : >
@@ -119,59 +62,6 @@ ulm_translation_engine:
119
62
return translation ? translation : state;
120
63
}
121
64
]]]
122
- ulm_translation_state_unit : >
123
- [[[
124
- if (typeof(entity) !== 'undefined' && entity !== undefined){
125
- let state = entity.state;
126
- let d_class = entity.attributes.device_class;
127
- let def = ["unknown", "unavailable"];
128
- let lang = hass["language"];
129
- let domain = entity.entity_id.substr(0, entity.entity_id.indexOf("."));
130
- let unit = entity.attributes.unit_of_measurement != null ? " " + entity.attributes.unit_of_measurement : "";
131
- let display_precision = hass.entities[entity.entity_id]?.display_precision
132
- const now = new Date();
133
- const timestamp = (new Date(state)).getTime();
134
- const nowTimeStamp = now.getTime();
135
- const microSecondsDiff = Math.round(timestamp - nowTimeStamp);
136
- const daysDiff = Math.round(microSecondsDiff / (1000 * 60 * 60 * 24));
137
- const hoursDiff = Math.round(microSecondsDiff / (1000 * 60 * 60));
138
- const minutesDiff = Math.round(microSecondsDiff / (1000 * 60));
139
- const secondsDiff = Math.round(microSecondsDiff / (1000));
140
- const formatter = new Intl.RelativeTimeFormat(lang, { numeric: 'auto' });
141
-
142
- var scale = 'day'
143
- var diff = daysDiff
144
- if (Math.abs(secondsDiff) < 60){ scale = 'second'; diff = secondsDiff }
145
- else if (Math.abs(minutesDiff) < 60){ scale = 'minute'; diff = minutesDiff }
146
- else if (Math.abs(hoursDiff) < 24){ scale = 'hour'; diff = hoursDiff }
147
-
148
- if(hass.resources[lang]["component." + domain + ".entity_component._.state." + state]){
149
- var translation = hass.resources[lang]["component." + domain + ".entity_component._.state." + state] + unit
150
- } else {
151
- var translation = state + unit;
152
- }
153
- if (def.includes(state)) {
154
- var translation = hass.resources[lang]["state.default." + state ];
155
- }
156
- else if (domain == "binary_sensor" && d_class != ''){
157
- var translation = hass.resources[lang]["component." + domain + ".entity_component." + d_class + ".state." + state]
158
- }
159
- else if (domain == "media_player" && d_class != ''){
160
- if (state == 'idle' || state == 'paused')
161
- var translation = hass.resources[lang]["component." + domain + ".entity_component._.state." + state];
162
- else {
163
- var translation = (entity.attributes.source) + ' • ' + ( Math.round(entity.attributes.volume_level / 0.01)) + '%' ;
164
- }
165
- }
166
- else if (d_class == 'timestamp'){
167
- var translation = formatter.format(diff, scale);
168
- }
169
- else if (parseFloat(display_precision) >=0){
170
- var translation = parseFloat(entity.state).toFixed(display_precision?.toString()) + unit
171
- }
172
- return translation ? translation.charAt(0).toUpperCase() + translation.slice(1) : state;
173
- }
174
- ]]]
175
65
ulm_translation_statistics : " [[[ return hass.resources[hass['language']]['ui.components.statistic-picker.statistic']; ]]]"
176
66
ulm_translation_unavailable : " [[[ return hass.resources[hass['language']]['state.default.unavailable']; ]]]"
177
67
ulm_translation_currency : >
0 commit comments