Add support for glob matching to entity filters (#36913)

* Added GLOB capability to entityfilter and every place that uses it. All existing tests are passing

* added tests for components affected by glob change

* fixed flake8 error

* mocking the correct listener

* mocking correct bus method in azure test

* tests passing in 3.7 and 3.8

* fixed formatting issue from rebase/conflict

* Checking against glob patterns in more performant way

* perf improvments and reverted unnecessarily adjusted tests

* added new benchmark test around filters

* no longer using get with default in entityfilter

* changed filter name and removed logbook from filter benchmark

* simplified benchmark tests from feedback

* fixed apache tests and returned include exclude schemas to normal

* fixed azure event hub tests to properly go through component logic

* fixed azure test and clean up for other tests

* renaming test files to match standard

* merged mqtt statestream test changes with base

* removed dependency on recorder filter schema from history

* fixed recorder tests after merge and a bunch of lint errors
This commit is contained in:
mdegat01 2020-06-23 21:02:29 -04:00 committed by GitHub
parent a1ac1fb091
commit 6c7355785a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1832 additions and 278 deletions

View file

@ -66,20 +66,20 @@ from tests.components.homekit.common import patch_debounce
IP_ADDRESS = "127.0.0.1"
@pytest.fixture
def device_reg(hass):
@pytest.fixture(name="device_reg")
def device_reg_fixture(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
@pytest.fixture(name="entity_reg")
def entity_reg_fixture(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture(scope="module")
def debounce_patcher():
@pytest.fixture(name="debounce_patcher", scope="module")
def debounce_patcher_fixture():
"""Patch debounce method."""
patcher = patch_debounce()
yield patcher.start()
@ -88,7 +88,6 @@ def debounce_patcher():
async def test_setup_min(hass):
"""Test async_setup with min config options."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_NAME: BRIDGE_NAME, CONF_PORT: DEFAULT_PORT},
@ -413,6 +412,47 @@ async def test_homekit_entity_filter(hass):
assert mock_get_acc.called is False
async def test_homekit_entity_glob_filter(hass):
"""Test the entity filter."""
entry = await async_init_integration(hass)
entity_filter = generate_filter(
["cover"], ["demo.test"], [], [], ["*.included_*"], ["*.excluded_*"]
)
homekit = HomeKit(
hass,
None,
None,
None,
entity_filter,
{},
DEFAULT_SAFE_MODE,
advertise_ip=None,
entry_id=entry.entry_id,
)
homekit.bridge = Mock()
homekit.bridge.accessories = {}
with patch(f"{PATH_HOMEKIT}.get_accessory") as mock_get_acc:
mock_get_acc.return_value = None
homekit.add_bridge_accessory(State("cover.test", "open"))
assert mock_get_acc.called is True
mock_get_acc.reset_mock()
homekit.add_bridge_accessory(State("demo.test", "on"))
assert mock_get_acc.called is True
mock_get_acc.reset_mock()
homekit.add_bridge_accessory(State("cover.excluded_test", "open"))
assert mock_get_acc.called is False
mock_get_acc.reset_mock()
homekit.add_bridge_accessory(State("light.included_test", "light"))
assert mock_get_acc.called is True
mock_get_acc.reset_mock()
async def test_homekit_start(hass, hk_driver, device_reg, debounce_patcher):
"""Test HomeKit start method."""
entry = await async_init_integration(hass)
@ -432,6 +472,7 @@ async def test_homekit_start(hass, hk_driver, device_reg, debounce_patcher):
homekit.bridge = Mock()
homekit.bridge.accessories = []
homekit.driver = hk_driver
# pylint: disable=protected-access
homekit._filter = Mock(return_value=True)
connection = (device_registry.CONNECTION_NETWORK_MAC, "AA:BB:CC:DD:EE:FF")
@ -587,7 +628,6 @@ async def test_homekit_stop(hass):
async def test_homekit_reset_accessories(hass):
"""Test adding too many accessories to HomeKit."""
entry = MockConfigEntry(
domain=DOMAIN, data={CONF_NAME: "mock_name", CONF_PORT: 12345}
)
@ -629,7 +669,7 @@ async def test_homekit_reset_accessories(hass):
)
await hass.async_block_till_done()
assert 2 == hk_driver_config_changed.call_count
assert hk_driver_config_changed.call_count == 2
assert mock_add_accessory.called
homekit.status = STATUS_READY
@ -686,6 +726,7 @@ async def test_homekit_finds_linked_batteries(
entry_id=entry.entry_id,
)
homekit.driver = hk_driver
# pylint: disable=protected-access
homekit._filter = Mock(return_value=True)
homekit.bridge = HomeBridge(hass, hk_driver, "mock_bridge")
@ -818,7 +859,6 @@ async def test_setup_imported(hass):
async def test_yaml_updates_update_config_entry_for_name(hass):
"""Test async_setup with imported config."""
entry = MockConfigEntry(
domain=DOMAIN,
source=SOURCE_IMPORT,
@ -858,7 +898,6 @@ async def test_yaml_updates_update_config_entry_for_name(hass):
async def test_raise_config_entry_not_ready(hass):
"""Test async_setup when the port is not available."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_NAME: BRIDGE_NAME, CONF_PORT: DEFAULT_PORT},
@ -918,6 +957,7 @@ async def test_homekit_ignored_missing_devices(
entry_id=entry.entry_id,
)
homekit.driver = hk_driver
# pylint: disable=protected-access
homekit._filter = Mock(return_value=True)
homekit.bridge = HomeBridge(hass, hk_driver, "mock_bridge")
@ -997,6 +1037,7 @@ async def test_homekit_finds_linked_motion_sensors(
entry_id=entry.entry_id,
)
homekit.driver = hk_driver
# pylint: disable=protected-access
homekit._filter = Mock(return_value=True)
homekit.bridge = HomeBridge(hass, hk_driver, "mock_bridge")