Skip to content

Fix gas energy graph units if stats added by external source#11892

Merged
balloob merged 3 commits intohome-assistant:devfrom
pszafer:dev
Mar 22, 2022
Merged

Fix gas energy graph units if stats added by external source#11892
balloob merged 3 commits intohome-assistant:devfrom
pszafer:dev

Conversation

@pszafer
Copy link
Copy Markdown
Contributor

@pszafer pszafer commented Mar 1, 2022

Proposed change

By default Energy dashboard get units from entity.
If stats for gas are added by async_add_external_statistics then entity don't exists, so energy dashboard is falling back to m³ units.
This PR fixes this issue and get unit from statistic_meta if entity doesn't exists.

Depends on core PR home-assistant/core#68471

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

Additional information

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

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:

@emontnemery
Copy link
Copy Markdown
Collaborator

I think it's correct to only check the statistic meta data, instead of checking the state first and falling back to statistic meta data: while the unit is allowed to change in the state, the unit in the statistics meta data is locked.

Also, getEnergyGasUnitCategory should probably be updated in the same way as getEnergyGasUnit?

@pszafer
Copy link
Copy Markdown
Contributor Author

pszafer commented Mar 1, 2022

getEnergyGasUnitCategory filters out entities to show in Add source dialog.
For external stats it filters out one level lower between , ft³, kWh`, so I think it's ok.

About correct way for filter out entities I can remove this if there is no reason to fetch units from entity itself.

Copy link
Copy Markdown
Collaborator

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

Looks good to me.
This should be followed up with another PR replacing existing calls to history/list_statistic_ids with recorder/get_statistics_metadata.

@balloob balloob merged commit ccf1fb5 into home-assistant:dev Mar 22, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants