Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def service_update(zeroconf, service_type, name, state_change):
nonlocal zeroconf_types
nonlocal homekit_models

if state_change != ServiceStateChange.Added:
if state_change == ServiceStateChange.Removed:
return

try:
Expand Down
33 changes: 33 additions & 0 deletions tests/components/zeroconf/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from zeroconf import (
BadTypeInNameException,
Error as ZeroconfError,
InterfaceChoice,
IPVersion,
ServiceInfo,
Expand Down Expand Up @@ -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"