Skip to content

Conversation

@flixlix
Copy link

@flixlix flixlix commented Nov 25, 2025

Proposed change

I noticed there's no ease way to round the temperature in the weather forecast card to the nearest integers, so I added the round_temperature functionality to it. This is a boolean and when enabled is used to round all temperature numbers to their nearest integer.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

type: weather-forecast
show_current: true
show_forecast: true
entity: weather.forecast_home
forecast_type: daily
round_temperature: true

Additional information

I used some checks to make sure that only temperatures are being rounded. From my testing this works for all values, including secondary_info's. For example, pressure is not being rounded, even with this turned on.

Before (or with `round_temperature: false)

Screenshot 2025-11-25 at 15 13 29

After (only with `round_temperature: true)

Screenshot 2025-11-25 at 15 13 14

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @flixlix

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

},
"weather": {
"attributes": {
"dew_point": "Dew point",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed that this was missing before in the translation file, leading to an error in my change at https://github.com/home-assistant/frontend/pull/28103/files#diff-4f7195942cc7cdfbd5ad6149411b2d6fb641035063b8711026e641d7f1a2a606R276

@flixlix flixlix marked this pull request as ready for review November 25, 2025 15:29
@MindFreeze
Copy link
Member

If the option is a number instead of a boolean, it would make it more flexible but I wonder if setting to 2+ digits (15.23 C) would be useful at all 🤔

@flixlix
Copy link
Author

flixlix commented Nov 27, 2025

@MindFreeze yeah, at first I had implemented that option but came to the same conclusion as you. it was specially confusing inside the editor, because there was a slider / number input for this option. nonetheless, I kept this logic inside the card, in case this should be changed in the future. Whatever the temperatureFractionDigits variable is, will be the precision set. https://github.com/home-assistant/frontend/pull/28103/files#diff-4f7195942cc7cdfbd5ad6149411b2d6fb641035063b8711026e641d7f1a2a606R270-R272

@home-assistant home-assistant bot marked this pull request as draft December 1, 2025 06:45
@flixlix
Copy link
Author

flixlix commented Dec 1, 2025

@MindFreeze thank you for the review, I've tried to correct all issues

@flixlix flixlix marked this pull request as ready for review December 1, 2025 14:50
@home-assistant home-assistant bot requested a review from MindFreeze December 1, 2025 14:50
Comment on lines 322 to 330
if (!tempHigh || fc.temperature > tempHigh) {
tempHigh = fc.temperature;
tempHigh = round(fc.temperature, temperatureFractionDigits);
}
if (!tempLow || (fc.templow && fc.templow < tempLow)) {
tempLow = fc.templow;
if (fc.templow !== undefined && (!tempLow || fc.templow < tempLow)) {
tempLow = round(fc.templow, temperatureFractionDigits);
}
if (!fc.templow && (!tempLow || fc.temperature < tempLow)) {
tempLow = fc.temperature;
tempLow = round(fc.temperature, temperatureFractionDigits);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When round_temperature is false (the default), temperatureFractionDigits is undefined. The round() function has a default precision of 2. if temperatureFractionDigits is undefined we shouldn't use round to preserve the original precision

Comment on lines +274 to +278
const TEMPERATURE_ATTRIBUTES = [
"temperature",
"apparent_temperature",
"dew_point",
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better put this constant outside of the class so it's global

@home-assistant home-assistant bot marked this pull request as draft December 2, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants