Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several issues fixed #4 #1593

Merged
merged 5 commits into from
Jan 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update action cards, fix helpers.relativeTime
wilbiev committed Jan 4, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit c244e9cf1bfea30b4e12a664b7df924aa0bfbc7d
Original file line number Diff line number Diff line change
@@ -33,10 +33,31 @@ ulm_translation_engine:
let domain = entity.entity_id.substr(0, entity.entity_id.indexOf("."));
let mode = hass.resources[lang]["state_attributes." + domain + ".hvac_action." + action];
if(variables.ulm_show_last_changed){
return helpers.relativeTime(entity.last_changed, true)
let dt = new Intl.RelativeTimeFormat(lang, { style: "long" });
let delta = (Date.parse(entity.last_changed) - Date.now()) / 1000
let days = 0
if (delta > 1000)
days = parseInt(delta / (60 * 60 * 24));
let hours = parseInt(Math.round(delta / (60 * 60)) % 24);
let hours_unrounded = parseInt((delta / (60 * 60)) % 24);
let minutes = parseInt(Math.round(delta / 60) % 60);
let minutes_unrounded = parseInt((delta / 60) % 60);
let seconds = parseInt(Math.round(delta) % 60);
if (days != 0)
return dt.format(days,"days");
else if (hours_unrounded != 0)
return dt.format(hours,"hours");
else if (minutes_unrounded != 0)
return dt.format(minutes,"minutes");
return dt.format(seconds,"seconds");
}
if(device_class == 'timestamp'){
return helpers.relativeTime(entity.state, true)
if(device_class == ('timestamp' || 'date')){
let dt = new Intl.DateTimeFormat(lang, {
dateStyle: "long",
timeStyle: "short"
});
let formatted_date = dt.format(Date.parse(entity.state))
return formatted_date;
}
if(entity.entity_id.startsWith("climate.")){
return helpers.localize(entity, entity.attributes.current_temperature) + ' • ' +
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@ ulm_actions_card:
action = 'popup'
}
if (action == 'adaptive'){
action = 'call-service'
action = 'perform-action'
}
if (domain == "media_player" && action == 'toggle'){
action = 'call-service';
action = 'perform-action';
}
if (action == 'popup' && (variables.ulm_custom_popup != null )){
let popup_config = variables.ulm_custom_popup;
@@ -36,34 +36,34 @@ ulm_actions_card:
]]]
navigation_path: "[[[ return variables.ulm_card_tap_action == 'navigate' ? variables.ulm_card_tap_navigate_path : '/0' ]]]"
haptic: "[[[ return variables.ulm_card_tap_haptic != null ? variables.ulm_card_tap_haptic : 'none' ]]]"
service: >
perform_action: >
[[[
var action = variables.ulm_card_tap_action;

if (action == 'adaptive'){
if (variables.ulm_card_tap_action == 'adaptive')
return 'input_select.select_option';
}
if((entity != null) && entity.entity_id.startsWith("media_player.")){
else if (variables.ulm_card_tap_service !== undefined)
return variables.ulm_card_tap_service;
else if ((entity != null) && entity.entity_id.startsWith("media_player."))
return 'media_player.media_play_pause';
}
return variables.ulm_card_tap_service;
return "";
]]]
service_data: >
target:
entity_id: >
[[[
if (variables.ulm_card_tap_action == 'adaptive')
return variables.ulm_input_select;
else if (variables.ulm_card_tap_target !== undefined)
return variables.ulm_card_tap_target;
else if ((entity != null) && entity.entity_id.startsWith("media_player."))
return entity.entity_id;
return "";
]]]
data: >
[[[
var action = variables.ulm_card_tap_action;

if (action == 'adaptive'){
return {
'option': variables.ulm_input_select_option,
'entity_id': variables.ulm_input_select
};
}
if((entity != null) && entity.entity_id.startsWith("media_player.")){
return {
'entity_id': entity.entity_id
};
}
return variables.ulm_card_tap_service_data;
if (variables.ulm_card_tap_action == 'adaptive'){
return {'option': variables.ulm_input_select_option };
else if (variables.ulm_card_tap_service_data !== undefined)
return variables.ulm_card_tap_service_data;
return "";
]]]
browser_mod:
service: "browser_mod.popup"
@@ -129,10 +129,10 @@ ulm_actions_card:
action = 'popup'
}
if (action == 'adaptive'){
action = 'call-service'
action = 'perform-action'
}
if (domain == "media_player" && action == 'toggle'){
action = 'call-service';
action = 'perform-action';
}
if (action == 'popup' && (variables.ulm_custom_popup != null )){
let popup_config = variables.ulm_custom_popup;
@@ -149,34 +149,34 @@ ulm_actions_card:
]]]
navigation_path: "[[[ return variables.ulm_card_hold_action == 'navigate' ? variables.ulm_card_hold_navigate_path : '/0' ]]]"
haptic: "[[[ return variables.ulm_card_hold_haptic != null ? variables.ulm_card_hold_haptic : 'none' ]]]"
service: >
perform_action: >
[[[
var action = variables.ulm_card_hold_action;

if (action == 'adaptive'){
if (variables.ulm_card_hold_action == 'adaptive')
return 'input_select.select_option';
}
if((entity != null) && entity.entity_id.startsWith("media_player.")){
else if (variables.ulm_card_hold_service !== undefined)
return variables.ulm_card_hold_service;
else if ((entity != null) && entity.entity_id.startsWith("media_player."))
return 'media_player.media_play_pause';
}
return variables.ulm_card_hold_service;
return "";
]]]
service_data: >
target:
entity_id: >
[[[
if (variables.ulm_card_hold_action == 'adaptive')
return variables.ulm_input_select;
else if (variables.ulm_card_hold_target !== undefined)
return variables.ulm_card_hold_target;
else if ((entity != null) && entity.entity_id.startsWith("media_player."))
return entity.entity_id;
return "";
]]]
data: >
[[[
var action = variables.ulm_card_hold_action;

if (action == 'adaptive'){
return {
'option': variables.ulm_input_select_option,
'entity_id': variables.ulm_input_select
};
}
if((entity != null) && entity.entity_id.startsWith("media_player.")){
return {
'entity_id': entity.entity_id
};
}
return variables.ulm_card_hold_service_data;
if (variables.ulm_card_hold_action == 'adaptive')
return { 'option': variables.ulm_input_select_option };
else if (variables.ulm_card_hold_service_data !== undefined)
return variables.ulm_card_hold_service_data;
return "";
]]]
browser_mod:
service: "browser_mod.popup"
@@ -242,10 +242,10 @@ ulm_actions_card:
action = 'popup'
}
if (action == 'adaptive'){
action = 'call-service'
action = 'perform-action'
}
if (domain == "media_player" && action == 'toggle'){
action = 'call-service';
action = 'perform-action';
}
if (action == 'popup' && (variables.ulm_custom_popup != null )){
let popup_config = variables.ulm_custom_popup;
@@ -262,34 +262,34 @@ ulm_actions_card:
]]]
navigation_path: "[[[ return variables.ulm_card_double_tap_action == 'navigate' ? variables.ulm_card_double_tap_navigate_path : '/0' ]]]"
haptic: "[[[ return variables.ulm_card_double_tap_haptic != null ? variables.ulm_card_double_tap_haptic : 'none' ]]]"
service: >
perform_action: >
[[[
var action = variables.ulm_card_double_tap_action;

if (action == 'adaptive'){
if (variables.ulm_card_double_tap_action == 'adaptive')
return 'input_select.select_option';
}
if((entity != null) && entity.entity_id.startsWith("media_player.")){
else if (variables.ulm_card_double_tap_service !== undefined)
return variables.ulm_card_double_tap_service;
else if ((entity != null) && entity.entity_id.startsWith("media_player."))
return 'media_player.media_play_pause';
}
return variables.ulm_card_double_tap_service;
return "";
]]]
service_data: >
target:
entity_id: >
[[[
if (variables.ulm_card_double_tap_action == 'adaptive')
return variables.ulm_input_select;
else if (variables.ulm_card_double_tap_target !== undefined)
return variables.ulm_card_double_tap_target;
else if ((entity != null) && entity.entity_id.startsWith("media_player."))
return entity.entity_id;
return "";
]]]
data: >
[[[
var action = variables.ulm_card_double_tap_action;

if (action == 'adaptive'){
return {
'option': variables.ulm_input_select_option,
'entity_id': variables.ulm_input_select
};
}
if((entity != null) && entity.entity_id.startsWith("media_player.")){
return {
'entity_id': entity.entity_id
};
}
return variables.ulm_card_double_tap_service_data;
if (variables.ulm_card_double_tap_action == 'adaptive')
return { 'option': variables.ulm_input_select_option };
else if (variables.ulm_card_double_tap_service_data !== undefined)
return variables.ulm_card_double_tap_service_data;
return "";
]]]
browser_mod:
service: "browser_mod.popup"
Loading