Entity Registry to store and restore name/icon (#31714)
* Entity Registry to store and restore name/icon * Update test_entity_registry.py * Add original name/icon to JSON result
This commit is contained in:
1 parent
ecd7ec385d
commit
51c35ab9a8
6 files changed
+84
-7
No files matched your search
@@ -41,6 +41,9 @@ async def test_list_entities(hass, client):
|
||||
"disabled_by": None,
|
||||
"entity_id": "test_domain.name",
|
||||
"name": "Hello World",
|
||||
"icon": None,
|
||||
"original_name": None,
|
||||
"original_icon": None,
|
||||
"platform": "test_platform",
|
||||
},
|
||||
{
|
||||
@@ -49,6 +52,9 @@ async def test_list_entities(hass, client):
|
||||
"disabled_by": None,
|
||||
"entity_id": "test_domain.no_name",
|
||||
"name": None,
|
||||
"icon": None,
|
||||
"original_name": None,
|
||||
"original_icon": None,
|
||||
"platform": "test_platform",
|
||||
},
|
||||
]
|
||||
@@ -85,6 +91,9 @@ async def test_get_entity(hass, client):
|
||||
"platform": "test_platform",
|
||||
"entity_id": "test_domain.name",
|
||||
"name": "Hello World",
|
||||
"icon": None,
|
||||
"original_name": None,
|
||||
"original_icon": None,
|
||||
}
|
||||
|
||||
await client.send_json(
|
||||
@@ -103,6 +112,9 @@ async def test_get_entity(hass, client):
|
||||
"platform": "test_platform",
|
||||
"entity_id": "test_domain.no_name",
|
||||
"name": None,
|
||||
"icon": None,
|
||||
"original_name": None,
|
||||
"original_icon": None,
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +129,7 @@ async def test_update_entity(hass, client):
|
||||
# Using component.async_add_entities is equal to platform "domain"
|
||||
platform="test_platform",
|
||||
name="before update",
|
||||
icon="icon:before update",
|
||||
)
|
||||
},
|
||||
)
|
||||
@@ -127,14 +140,16 @@ async def test_update_entity(hass, client):
|
||||
state = hass.states.get("test_domain.world")
|
||||
assert state is not None
|
||||
assert state.name == "before update"
|
||||
assert state.attributes["icon"] == "icon:before update"
|
||||
|
||||
# UPDATE NAME
|
||||
# UPDATE NAME & ICON
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 6,
|
||||
"type": "config/entity_registry/update",
|
||||
"entity_id": "test_domain.world",
|
||||
"name": "after update",
|
||||
"icon": "icon:after update",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -147,10 +162,14 @@ async def test_update_entity(hass, client):
|
||||
"platform": "test_platform",
|
||||
"entity_id": "test_domain.world",
|
||||
"name": "after update",
|
||||
"icon": "icon:after update",
|
||||
"original_name": None,
|
||||
"original_icon": None,
|
||||
}
|
||||
|
||||
state = hass.states.get("test_domain.world")
|
||||
assert state.name == "after update"
|
||||
assert state.attributes["icon"] == "icon:after update"
|
||||
|
||||
# UPDATE DISABLED_BY TO USER
|
||||
await client.send_json(
|
||||
@@ -186,6 +205,9 @@ async def test_update_entity(hass, client):
|
||||
"platform": "test_platform",
|
||||
"entity_id": "test_domain.world",
|
||||
"name": "after update",
|
||||
"icon": "icon:after update",
|
||||
"original_name": None,
|
||||
"original_icon": None,
|
||||
}
|
||||
|
||||
|
||||
@@ -229,6 +251,9 @@ async def test_update_entity_no_changes(hass, client):
|
||||
"platform": "test_platform",
|
||||
"entity_id": "test_domain.world",
|
||||
"name": "name of entity",
|
||||
"icon": None,
|
||||
"original_name": None,
|
||||
"original_icon": None,
|
||||
}
|
||||
|
||||
state = hass.states.get("test_domain.world")
|
||||
@@ -301,6 +326,9 @@ async def test_update_entity_id(hass, client):
|
||||
"platform": "test_platform",
|
||||
"entity_id": "test_domain.planet",
|
||||
"name": None,
|
||||
"icon": None,
|
||||
"original_name": None,
|
||||
"original_icon": None,
|
||||
}
|
||||
|
||||
assert hass.states.get("test_domain.world") is None
|
||||
|
||||
@@ -72,6 +72,9 @@ def test_get_or_create_updates_data(registry):
|
||||
supported_features=5,
|
||||
device_class="mock-device-class",
|
||||
disabled_by=entity_registry.DISABLED_HASS,
|
||||
unit_of_measurement="initial-unit_of_measurement",
|
||||
original_name="initial-original_name",
|
||||
original_icon="initial-original_icon",
|
||||
)
|
||||
|
||||
assert orig_entry.config_entry_id == orig_config_entry.entry_id
|
||||
@@ -80,6 +83,9 @@ def test_get_or_create_updates_data(registry):
|
||||
assert orig_entry.supported_features == 5
|
||||
assert orig_entry.device_class == "mock-device-class"
|
||||
assert orig_entry.disabled_by == entity_registry.DISABLED_HASS
|
||||
assert orig_entry.unit_of_measurement == "initial-unit_of_measurement"
|
||||
assert orig_entry.original_name == "initial-original_name"
|
||||
assert orig_entry.original_icon == "initial-original_icon"
|
||||
|
||||
new_config_entry = MockConfigEntry(domain="light")
|
||||
|
||||
@@ -93,6 +99,9 @@ def test_get_or_create_updates_data(registry):
|
||||
supported_features=10,
|
||||
device_class="new-mock-device-class",
|
||||
disabled_by=entity_registry.DISABLED_USER,
|
||||
unit_of_measurement="updated-unit_of_measurement",
|
||||
original_name="updated-original_name",
|
||||
original_icon="updated-original_icon",
|
||||
)
|
||||
|
||||
assert new_entry.config_entry_id == new_config_entry.entry_id
|
||||
@@ -100,6 +109,9 @@ def test_get_or_create_updates_data(registry):
|
||||
assert new_entry.capabilities == {"new-max": 100}
|
||||
assert new_entry.supported_features == 10
|
||||
assert new_entry.device_class == "new-mock-device-class"
|
||||
assert new_entry.unit_of_measurement == "updated-unit_of_measurement"
|
||||
assert new_entry.original_name == "updated-original_name"
|
||||
assert new_entry.original_icon == "updated-original_icon"
|
||||
# Should not be updated
|
||||
assert new_entry.disabled_by == entity_registry.DISABLED_HASS
|
||||
|
||||
@@ -434,6 +446,7 @@ async def test_update_entity(registry):
|
||||
|
||||
for attr_name, new_value in (
|
||||
("name", "new name"),
|
||||
("icon", "new icon"),
|
||||
("disabled_by", entity_registry.DISABLED_USER),
|
||||
):
|
||||
changes = {attr_name: new_value}
|
||||
@@ -503,6 +516,8 @@ async def test_restore_states(hass):
|
||||
capabilities={"max": 100},
|
||||
supported_features=5,
|
||||
device_class="mock-device-class",
|
||||
original_name="Mock Original Name",
|
||||
original_icon="hass:original-icon",
|
||||
)
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START, {})
|
||||
@@ -524,6 +539,8 @@ async def test_restore_states(hass):
|
||||
"supported_features": 5,
|
||||
"device_class": "mock-device-class",
|
||||
"restored": True,
|
||||
"friendly_name": "Mock Original Name",
|
||||
"icon": "hass:original-icon",
|
||||
}
|
||||
|
||||
registry.async_remove("light.disabled")
|
||||
|
||||
Reference in new issue
Block a user