Add update events to registries (#23746)

* Add update events to registries

* Add to websocket
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-05-07 20:04:57 -07:00
1 parent 6e7a7ba4a0
commit 07ee3b2eb9
8 files changed
+187 -14

No files matched your search

+41 -2
View File
@@ -5,6 +5,7 @@ from unittest.mock import patch
import asynctest
import pytest
from homeassistant.core import callback
from homeassistant.helpers import device_registry
from tests.common import mock_device_registry, flush_store
@@ -15,7 +16,22 @@ def registry(hass):
return mock_device_registry(hass)
async def test_get_or_create_returns_same_entry(registry):
@pytest.fixture
def update_events(hass):
"""Capture update events."""
events = []
@callback
def async_capture(event):
events.append(event.data)
hass.bus.async_listen(device_registry.EVENT_DEVICE_REGISTRY_UPDATED,
async_capture)
return events
async def test_get_or_create_returns_same_entry(hass, registry, update_events):
"""Make sure we do not duplicate entries."""
entry = registry.async_get_or_create(
config_entry_id='1234',
@@ -51,6 +67,15 @@ async def test_get_or_create_returns_same_entry(registry):
assert entry3.name == 'name'
assert entry3.sw_version == 'sw-version'
await hass.async_block_till_done()
# Only 2 update events. The third entry did not generate any changes.
assert len(update_events) == 2
assert update_events[0]['action'] == 'create'
assert update_events[0]['device_id'] == entry.id
assert update_events[1]['action'] == 'update'
assert update_events[1]['device_id'] == entry.id
async def test_requirement_for_identifier_or_connection(registry):
"""Make sure we do require some descriptor of device."""
@@ -155,7 +180,7 @@ async def test_loading_from_storage(hass, hass_storage):
assert isinstance(entry.config_entries, set)
async def test_removing_config_entries(registry):
async def test_removing_config_entries(hass, registry, update_events):
"""Make sure we do not get duplicate entries."""
entry = registry.async_get_or_create(
config_entry_id='123',
@@ -191,6 +216,20 @@ async def test_removing_config_entries(registry):
assert entry.config_entries == {'456'}
assert entry3.config_entries == set()
await hass.async_block_till_done()
assert len(update_events) == 5
assert update_events[0]['action'] == 'create'
assert update_events[0]['device_id'] == entry.id
assert update_events[1]['action'] == 'update'
assert update_events[1]['device_id'] == entry2.id
assert update_events[2]['action'] == 'create'
assert update_events[2]['device_id'] == entry3.id
assert update_events[3]['action'] == 'update'
assert update_events[3]['device_id'] == entry.id
assert update_events[4]['action'] == 'update'
assert update_events[4]['device_id'] == entry3.id
async def test_removing_area_id(registry):
"""Make sure we can clear area id."""