Handle zeroconf updated events (#47683)

pull/47739/head
Paulus Schoutsen 2021-03-09 12:14:00 -08:00 committed by GitHub
parent ed679b263b
commit 46e593485e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -242,7 +242,7 @@ async def _async_start_zeroconf_browser(hass, zeroconf):
nonlocal zeroconf_types
nonlocal homekit_models
if state_change != ServiceStateChange.Added:
if state_change == ServiceStateChange.Removed:
return
try:

View File

@ -3,6 +3,7 @@ from unittest.mock import patch
from zeroconf import (
BadTypeInNameException,
Error as ZeroconfError,
InterfaceChoice,
IPVersion,
ServiceInfo,
@ -495,3 +496,35 @@ async def test_get_instance(hass, mock_zeroconf):
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
await hass.async_block_till_done()
assert len(mock_zeroconf.ha_close.mock_calls) == 1
async def test_removed_ignored(hass, mock_zeroconf):
"""Test we remove it when a zeroconf entry is removed."""
mock_zeroconf.get_service_info.side_effect = ZeroconfError
def service_update_mock(zeroconf, services, handlers):
"""Call service update handler."""
handlers[0](
zeroconf, "_service.added", "name._service.added", ServiceStateChange.Added
)
handlers[0](
zeroconf,
"_service.updated",
"name._service.updated",
ServiceStateChange.Updated,
)
handlers[0](
zeroconf,
"_service.removed",
"name._service.removed",
ServiceStateChange.Removed,
)
with patch.object(zeroconf, "HaServiceBrowser", side_effect=service_update_mock):
assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
assert len(mock_zeroconf.get_service_info.mock_calls) == 2
assert mock_zeroconf.get_service_info.mock_calls[0][1][0] == "_service.added"
assert mock_zeroconf.get_service_info.mock_calls[1][1][0] == "_service.updated"