1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Improve handling of disabled devices (#43864)

This commit is contained in:
Erik Montnemery
2020-12-02 21:20:14 +01:00
committed by GitHub
parent d518db1c95
commit 30baf333c3
4 changed files with 113 additions and 10 deletions

View File

@@ -7,7 +7,13 @@ from homeassistant.components.config import entity_registry
from homeassistant.const import ATTR_ICON
from homeassistant.helpers.entity_registry import RegistryEntry
from tests.common import MockConfigEntry, MockEntity, MockEntityPlatform, mock_registry
from tests.common import (
MockConfigEntry,
MockEntity,
MockEntityPlatform,
mock_device_registry,
mock_registry,
)
@pytest.fixture
@@ -17,6 +23,12 @@ def client(hass, hass_ws_client):
yield hass.loop.run_until_complete(hass_ws_client(hass))
@pytest.fixture
def device_registry(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
async def test_list_entities(hass, client):
"""Test list entries."""
entities = OrderedDict()
@@ -282,6 +294,55 @@ async def test_update_entity_require_restart(hass, client):
}
async def test_enable_entity_disabled_device(hass, client, device_registry):
"""Test enabling entity of disabled device."""
config_entry = MockConfigEntry(domain="test_platform")
config_entry.add_to_hass(hass)
device = device_registry.async_get_or_create(
config_entry_id="1234",
connections={("ethernet", "12:34:56:78:90:AB:CD:EF")},
identifiers={("bridgeid", "0123")},
manufacturer="manufacturer",
model="model",
disabled_by="user",
)
mock_registry(
hass,
{
"test_domain.world": RegistryEntry(
config_entry_id=config_entry.entry_id,
entity_id="test_domain.world",
unique_id="1234",
# Using component.async_add_entities is equal to platform "domain"
platform="test_platform",
device_id=device.id,
)
},
)
platform = MockEntityPlatform(hass)
entity = MockEntity(unique_id="1234")
await platform.async_add_entities([entity])
state = hass.states.get("test_domain.world")
assert state is not None
# UPDATE DISABLED_BY TO NONE
await client.send_json(
{
"id": 8,
"type": "config/entity_registry/update",
"entity_id": "test_domain.world",
"disabled_by": None,
}
)
msg = await client.receive_json()
assert not msg["success"]
async def test_update_entity_no_changes(hass, client):
"""Test update entity with no changes."""
mock_registry(