Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
f61edf07
Unverified
Commit
f61edf07
authored
2 years ago
by
Erik Montnemery
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix updating of statistics metadata name (#77207)
* Fix updating of statistics metadata name * Fix test * Test renaming
parent
b1d249c3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/recorder/statistics.py
+2
-0
2 additions, 0 deletions
homeassistant/components/recorder/statistics.py
tests/components/recorder/test_statistics.py
+29
-1
29 additions, 1 deletion
tests/components/recorder/test_statistics.py
with
31 additions
and
1 deletion
homeassistant/components/recorder/statistics.py
+
2
−
0
View file @
f61edf07
...
...
@@ -267,12 +267,14 @@ def _update_or_add_metadata(
if
(
old_metadata
[
"
has_mean
"
]
!=
new_metadata
[
"
has_mean
"
]
or
old_metadata
[
"
has_sum
"
]
!=
new_metadata
[
"
has_sum
"
]
or
old_metadata
[
"
name
"
]
!=
new_metadata
[
"
name
"
]
or
old_metadata
[
"
unit_of_measurement
"
]
!=
new_metadata
[
"
unit_of_measurement
"
]
):
session
.
query
(
StatisticsMeta
).
filter_by
(
statistic_id
=
statistic_id
).
update
(
{
StatisticsMeta
.
has_mean
:
new_metadata
[
"
has_mean
"
],
StatisticsMeta
.
has_sum
:
new_metadata
[
"
has_sum
"
],
StatisticsMeta
.
name
:
new_metadata
[
"
name
"
],
StatisticsMeta
.
unit_of_measurement
:
new_metadata
[
"
unit_of_measurement
"
],
},
synchronize_session
=
False
,
...
...
This diff is collapsed.
Click to expand it.
tests/components/recorder/test_statistics.py
+
29
−
1
View file @
f61edf07
...
...
@@ -161,6 +161,7 @@ def mock_sensor_statistics():
"
unit_of_measurement
"
:
"
dogs
"
,
"
has_mean
"
:
True
,
"
has_sum
"
:
False
,
"
name
"
:
None
,
},
"
stat
"
:
{
"
start
"
:
start
},
}
...
...
@@ -599,7 +600,7 @@ async def test_import_statistics(
]
}
# Update the previously inserted statistics
# Update the previously inserted statistics
+ rename
external_statistics
=
{
"
start
"
:
period1
,
"
max
"
:
1
,
...
...
@@ -609,8 +610,34 @@ async def test_import_statistics(
"
state
"
:
4
,
"
sum
"
:
5
,
}
external_metadata
[
"
name
"
]
=
"
Total imported energy renamed
"
import_fn
(
hass
,
external_metadata
,
(
external_statistics
,))
await
async_wait_recording_done
(
hass
)
statistic_ids
=
list_statistic_ids
(
hass
)
assert
statistic_ids
==
[
{
"
has_mean
"
:
False
,
"
has_sum
"
:
True
,
"
statistic_id
"
:
statistic_id
,
"
name
"
:
"
Total imported energy renamed
"
,
"
source
"
:
source
,
"
unit_of_measurement
"
:
"
kWh
"
,
}
]
metadata
=
get_metadata
(
hass
,
statistic_ids
=
(
statistic_id
,))
assert
metadata
==
{
statistic_id
:
(
1
,
{
"
has_mean
"
:
False
,
"
has_sum
"
:
True
,
"
name
"
:
"
Total imported energy renamed
"
,
"
source
"
:
source
,
"
statistic_id
"
:
statistic_id
,
"
unit_of_measurement
"
:
"
kWh
"
,
},
)
}
stats
=
statistics_during_period
(
hass
,
zero
,
period
=
"
hour
"
)
assert
stats
==
{
statistic_id
:
[
...
...
@@ -639,6 +666,7 @@ async def test_import_statistics(
]
}
# Adjust the statistics
await
client
.
send_json
(
{
"
id
"
:
1
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment