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

Changes to the valueText should also rescale ha-gauge text #23536

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

Hypfer
Copy link
Contributor

@Hypfer Hypfer commented Jan 1, 2025

Proposed change

When clicking through my energy dashboard, I sometimes noticed that the grid neutrality gauge didn't render correctly:

image

This happens, because ha-gauge::_rescale_svg() is only being called on a value or label update:

protected updated(changedProperties: PropertyValues) {
super.updated(changedProperties);
if (
!this._updated ||
(!changedProperties.has("value") &&
!changedProperties.has("label") &&
!changedProperties.has("_segment_label"))
) {
return;
}
this._angle = getAngle(this.value, this.min, this.max);
this._segment_label = this.getSegmentLabel();
this._rescale_svg();
}

This works for almost all cases, however with the hui-energy-grid-neutrality-gauge-card, it breaks, because value and valueText are independent from each other.

This bug only occurs, when there are multiple days with the same grid neutrality ratio but kWh usage differing by digit count.
Otherwise, the change of the ratio also triggers the _rescale_svg()

According to the github code search, the grid neutrality gauge card is currently the only gauge where that can happen:
https://github.com/search?q=repo%3Ahome-assistant%2Ffrontend%20.valueText&type=code

These two factors are probably why it hasn't been discovered so far.

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

Default energy dashboard

Additional information

  • This PR fixes or closes issue: N/A
  • This PR is related to issue or discussion: N/A
  • Link to documentation pull request: N/A

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:

@karwosts
Copy link
Contributor

karwosts commented Jan 2, 2025

Nice find. I believe this was reported before #19114, but never solved.

@bramkragten bramkragten added this to the 2025.1 milestone Jan 2, 2025
@bramkragten bramkragten merged commit c7df147 into home-assistant:dev Jan 2, 2025
16 checks passed
bramkragten pushed a commit that referenced this pull request Jan 2, 2025
Changes to the valueText should also recenter ha-gauge text
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.

3 participants