Add manifest support for homekit discovery (#24225)
* Add manifest support for homekit discovery * Add a space after model check * Update comment
This commit is contained in:
1 parent
18286dbf4b
commit
3c1cdecb88
7 files changed
+169
-32
No files matched your search
@@ -1,6 +1,7 @@
|
||||
"""Test Zeroconf component setup process."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from zeroconf import ServiceInfo, ServiceStateChange
|
||||
|
||||
from homeassistant.generated import zeroconf as zc_gen
|
||||
@@ -8,6 +9,13 @@ from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import zeroconf
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_zeroconf():
|
||||
"""Mock zeroconf."""
|
||||
with patch('homeassistant.components.zeroconf.Zeroconf') as mock_zc:
|
||||
yield mock_zc.return_value
|
||||
|
||||
|
||||
def service_update_mock(zeroconf, service, handlers):
|
||||
"""Call service update handler."""
|
||||
handlers[0](
|
||||
@@ -23,18 +31,44 @@ def get_service_info_mock(service_type, name):
|
||||
properties={b'macaddress': b'ABCDEF012345'})
|
||||
|
||||
|
||||
async def test_setup(hass):
|
||||
def get_homekit_info_mock(service_type, name):
|
||||
"""Return homekit info for get_service_info."""
|
||||
return ServiceInfo(
|
||||
service_type, name, address=b'\n\x00\x00\x14', port=80, weight=0,
|
||||
priority=0, server='name.local.',
|
||||
properties={b'md': b'LIFX Bulb'})
|
||||
|
||||
|
||||
async def test_setup(hass, mock_zeroconf):
|
||||
"""Test configured options for a device are loaded via config entry."""
|
||||
with patch.object(hass.config_entries, 'flow') as mock_config_flow, \
|
||||
patch.object(zeroconf, 'ServiceBrowser') as MockServiceBrowser, \
|
||||
patch.object(zeroconf.Zeroconf, 'get_service_info') as \
|
||||
mock_get_service_info:
|
||||
|
||||
MockServiceBrowser.side_effect = service_update_mock
|
||||
mock_get_service_info.side_effect = get_service_info_mock
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, 'flow'
|
||||
) as mock_config_flow, patch.object(
|
||||
zeroconf, 'ServiceBrowser', side_effect=service_update_mock
|
||||
) as mock_service_browser:
|
||||
mock_zeroconf.get_service_info.side_effect = get_service_info_mock
|
||||
assert await async_setup_component(
|
||||
hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
||||
|
||||
assert len(MockServiceBrowser.mock_calls) == len(zc_gen.ZEROCONF)
|
||||
assert len(mock_service_browser.mock_calls) == len(zc_gen.ZEROCONF)
|
||||
assert len(mock_config_flow.mock_calls) == len(zc_gen.ZEROCONF) * 2
|
||||
|
||||
|
||||
async def test_homekit(hass, mock_zeroconf):
|
||||
"""Test configured options for a device are loaded via config entry."""
|
||||
with patch.dict(
|
||||
zc_gen.ZEROCONF, {
|
||||
zeroconf.HOMEKIT_TYPE: ["homekit_controller"]
|
||||
}, clear=True
|
||||
), patch.object(
|
||||
hass.config_entries, 'flow'
|
||||
) as mock_config_flow, patch.object(
|
||||
zeroconf, 'ServiceBrowser', side_effect=service_update_mock
|
||||
) as mock_service_browser:
|
||||
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock
|
||||
assert await async_setup_component(
|
||||
hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
||||
|
||||
assert len(mock_service_browser.mock_calls) == 1
|
||||
assert len(mock_config_flow.mock_calls) == 2
|
||||
assert mock_config_flow.mock_calls[0][1][0] == 'lifx'
|
||||
Reference in new issue
Block a user