Skip to content

Commit

Permalink
Merge pull request #1314 from basbruss/Display-precision
Browse files Browse the repository at this point in the history
Add display precision based on HA settings
  • Loading branch information
basbruss authored Jun 7, 2023
2 parents 9106b4c + 42d6024 commit 8916e79
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ ulm_translation_engine:
let lang = hass["language"];
let domain = entity.entity_id.substr(0, entity.entity_id.indexOf("."));
var translation = hass.resources[lang]["component." + domain + ".entity_component._.state." + state]
let display_precision = hass.entities[entity.entity_id]?.display_precision
const now = new Date();
const timestamp = (new Date(state)).getTime();
const nowTimeStamp = now.getTime();
Expand All @@ -95,6 +96,9 @@ ulm_translation_engine:
else if (d_class == 'timestamp'){
var translation = formatter.format(diff, scale)
}
else if (parseFloat(display_precision) >=0){
var translation = parseFloat(entity.state).toFixed(display_precision?.toString())
}
return translation ? translation.charAt(0).toUpperCase() + translation.slice(1) : state;
}
]]]
Expand Down Expand Up @@ -124,6 +128,7 @@ ulm_translation_engine:
let lang = hass["language"];
let domain = entity.entity_id.substr(0, entity.entity_id.indexOf("."));
let unit = entity.attributes.unit_of_measurement != null ? " " + entity.attributes.unit_of_measurement : "";
let display_precision = hass.entities[entity.entity_id]?.display_precision
const now = new Date();
const timestamp = (new Date(state)).getTime();
const nowTimeStamp = now.getTime();
Expand Down Expand Up @@ -161,6 +166,9 @@ ulm_translation_engine:
else if (d_class == 'timestamp'){
var translation = formatter.format(diff, scale);
}
else if (parseFloat(display_precision) >=0){
var translation = parseFloat(entity.state).toFixed(display_precision?.toString()) + unit
}
return translation ? translation.charAt(0).toUpperCase() + translation.slice(1) : state;
}
]]]
Expand Down

0 comments on commit 8916e79

Please sign in to comment.