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
cd2045b6
Unverified
Commit
cd2045b6
authored
2 years ago
by
Erik Montnemery
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Clean up user overridden device class in entity registry (#77662)
parent
8afcde4e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/helpers/entity_registry.py
+12
-2
12 additions, 2 deletions
homeassistant/helpers/entity_registry.py
tests/helpers/test_entity_registry.py
+72
-0
72 additions, 0 deletions
tests/helpers/test_entity_registry.py
with
84 additions
and
2 deletions
homeassistant/helpers/entity_registry.py
+
12
−
2
View file @
cd2045b6
...
...
@@ -30,6 +30,7 @@ from homeassistant.const import (
MAX_LENGTH_STATE_ENTITY_ID
,
STATE_UNAVAILABLE
,
STATE_UNKNOWN
,
Platform
,
)
from
homeassistant.core
import
(
Event
,
...
...
@@ -62,7 +63,7 @@ SAVE_DELAY = 10
_LOGGER
=
logging
.
getLogger
(
__name__
)
STORAGE_VERSION_MAJOR
=
1
STORAGE_VERSION_MINOR
=
7
STORAGE_VERSION_MINOR
=
8
STORAGE_KEY
=
"
core.entity_registry
"
# Attributes relevant to describing entity
...
...
@@ -970,10 +971,19 @@ async def _async_migrate(
entity
[
"
hidden_by
"
]
=
None
if
old_major_version
==
1
and
old_minor_version
<
7
:
# Version 1.
6
adds has_entity_name
# Version 1.
7
adds has_entity_name
for
entity
in
data
[
"
entities
"
]:
entity
[
"
has_entity_name
"
]
=
False
if
old_major_version
==
1
and
old_minor_version
<
8
:
# Cleanup after frontend bug which incorrectly updated device_class
# Fixed by frontend PR #13551
for
entity
in
data
[
"
entities
"
]:
domain
=
split_entity_id
(
entity
[
"
entity_id
"
])[
0
]
if
domain
in
[
Platform
.
BINARY_SENSOR
,
Platform
.
COVER
]:
continue
entity
[
"
device_class
"
]
=
None
if
old_major_version
>
1
:
raise
NotImplementedError
return
data
...
...
This diff is collapsed.
Click to expand it.
tests/helpers/test_entity_registry.py
+
72
−
0
View file @
cd2045b6
...
...
@@ -528,6 +528,78 @@ async def test_migration_1_1(hass, hass_storage):
assert
entry
.
original_device_class
==
"
best_class
"
@pytest.mark.parametrize
(
"
load_registries
"
,
[
False
])
async
def
test_migration_1_7
(
hass
,
hass_storage
):
"""
Test migration from version 1.7.
This tests cleanup after frontend bug which incorrectly updated device_class
"""
entity_dict
=
{
"
area_id
"
:
None
,
"
capabilities
"
:
{},
"
config_entry_id
"
:
None
,
"
device_id
"
:
None
,
"
disabled_by
"
:
None
,
"
entity_category
"
:
None
,
"
has_entity_name
"
:
False
,
"
hidden_by
"
:
None
,
"
icon
"
:
None
,
"
id
"
:
"
12345
"
,
"
name
"
:
None
,
"
options
"
:
None
,
"
original_icon
"
:
None
,
"
original_name
"
:
None
,
"
platform
"
:
"
super_platform
"
,
"
supported_features
"
:
0
,
"
unique_id
"
:
"
very_unique
"
,
"
unit_of_measurement
"
:
None
,
}
hass_storage
[
er
.
STORAGE_KEY
]
=
{
"
version
"
:
1
,
"
minor_version
"
:
7
,
"
data
"
:
{
"
entities
"
:
[
{
**
entity_dict
,
"
device_class
"
:
"
original_class_by_integration
"
,
"
entity_id
"
:
"
test.entity
"
,
"
original_device_class
"
:
"
new_class_by_integration
"
,
},
{
**
entity_dict
,
"
device_class
"
:
"
class_by_user
"
,
"
entity_id
"
:
"
binary_sensor.entity
"
,
"
original_device_class
"
:
"
class_by_integration
"
,
},
{
**
entity_dict
,
"
device_class
"
:
"
class_by_user
"
,
"
entity_id
"
:
"
cover.entity
"
,
"
original_device_class
"
:
"
class_by_integration
"
,
},
]
},
}
await
er
.
async_load
(
hass
)
registry
=
er
.
async_get
(
hass
)
entry
=
registry
.
async_get_or_create
(
"
test
"
,
"
super_platform
"
,
"
very_unique
"
)
assert
entry
.
device_class
is
None
assert
entry
.
original_device_class
==
"
new_class_by_integration
"
entry
=
registry
.
async_get_or_create
(
"
binary_sensor
"
,
"
super_platform
"
,
"
very_unique
"
)
assert
entry
.
device_class
==
"
class_by_user
"
assert
entry
.
original_device_class
==
"
class_by_integration
"
entry
=
registry
.
async_get_or_create
(
"
cover
"
,
"
super_platform
"
,
"
very_unique
"
)
assert
entry
.
device_class
==
"
class_by_user
"
assert
entry
.
original_device_class
==
"
class_by_integration
"
@pytest.mark.parametrize
(
"
load_registries
"
,
[
False
])
async
def
test_loading_invalid_entity_id
(
hass
,
hass_storage
):
"""
Test we skip entities with invalid entity IDs.
"""
...
...
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