Entity registry api update disable (#26015)

* Clean up entity registry WS commands

* Allow updating disabled_by in entity registry

* Allow changing disabled_by via API

* Update tests/components/config/test_entity_registry.py

Co-Authored-By: Robert Svensson <Kane610@users.noreply.github.com>
This commit is contained in:
Paulus SchoutsenandRobert Svensson authored and GitHub committed 2019-08-16 16:22:45 -07:00
1 parent d4046cb6e4
commit eba6caf8a1
4 files changed
+97 -53

No files matched your search

@@ -105,9 +105,9 @@ async def test_get_entity(hass, client):
}
async def test_update_entity_name(hass, client):
"""Test updating entity name."""
mock_registry(
async def test_update_entity(hass, client):
"""Test updating entity."""
registry = mock_registry(
hass,
{
"test_domain.world": RegistryEntry(
@@ -133,6 +133,32 @@ async def test_update_entity_name(hass, client):
"type": "config/entity_registry/update",
"entity_id": "test_domain.world",
"name": "after update",
"disabled_by": "user",
}
)
msg = await client.receive_json()
assert msg["result"] == {
"config_entry_id": None,
"device_id": None,
"disabled_by": "user",
"platform": "test_platform",
"entity_id": "test_domain.world",
"name": "after update",
}
state = hass.states.get("test_domain.world")
assert state.name == "after update"
assert registry.entities["test_domain.world"].disabled_by == "user"
await client.send_json(
{
"id": 7,
"type": "config/entity_registry/update",
"entity_id": "test_domain.world",
"disabled_by": None,
}
)
@@ -147,9 +173,6 @@ async def test_update_entity_name(hass, client):
"name": "after update",
}
state = hass.states.get("test_domain.world")
assert state.name == "after update"
async def test_update_entity_no_changes(hass, client):
"""Test update entity with no changes."""
+20
View File
@@ -354,6 +354,26 @@ async def test_update_entity_unique_id_conflict(registry):
assert mock_schedule_save.call_count == 0
async def test_update_entity(registry):
"""Test updating entity."""
entry = registry.async_get_or_create(
"light", "hue", "5678", config_entry_id="mock-id-1"
)
for attr_name, new_value in (
("name", "new name"),
("disabled_by", entity_registry.DISABLED_USER),
):
changes = {attr_name: new_value}
updated_entry = registry.async_update_entity(entry.entity_id, **changes)
assert updated_entry != entry
assert getattr(updated_entry, attr_name) == new_value
assert getattr(updated_entry, attr_name) != getattr(entry, attr_name)
entry = updated_entry
async def test_disabled_by(registry):
"""Test that we can disable an entry when we create it."""
entry = registry.async_get_or_create("light", "hue", "5678", disabled_by="hass")