diff --git a/homeassistant/components/discovery/__init__.py b/homeassistant/components/discovery/__init__.py index 466d9d40d07..54f7e1bf3de 100644 --- a/homeassistant/components/discovery/__init__.py +++ b/homeassistant/components/discovery/__init__.py @@ -31,7 +31,6 @@ SERVICE_ENIGMA2 = 'enigma2' SERVICE_FREEBOX = 'freebox' SERVICE_HASS_IOS_APP = 'hass_ios' SERVICE_HASSIO = 'hassio' -SERVICE_HOMEKIT = 'homekit' SERVICE_HEOS = 'heos' SERVICE_IGD = 'igd' SERVICE_KONNECTED = 'konnected' @@ -55,7 +54,6 @@ CONFIG_ENTRY_HANDLERS = { SERVICE_TELLDUSLIVE: 'tellduslive', 'sonos': 'sonos', SERVICE_IGD: 'upnp', - SERVICE_HOMEKIT: 'homekit_controller', } SERVICE_HANDLERS = { diff --git a/homeassistant/components/homekit_controller/config_flow.py b/homeassistant/components/homekit_controller/config_flow.py index deefb596310..48d427b8321 100644 --- a/homeassistant/components/homekit_controller/config_flow.py +++ b/homeassistant/components/homekit_controller/config_flow.py @@ -109,7 +109,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow): }) ) - async def async_step_discovery(self, discovery_info): + async def async_step_zeroconf(self, discovery_info): """Handle a discovered HomeKit accessory. This flow is triggered by the discovery component. @@ -132,7 +132,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow): # pylint: disable=unsupported-assignment-operation self.context['title_placeholders'] = { - 'name': discovery_info['name'], + 'name': discovery_info['name'].replace('._hap._tcp.local.', ''), } # The configuration number increases every time the characteristic map diff --git a/homeassistant/components/homekit_controller/manifest.json b/homeassistant/components/homekit_controller/manifest.json index 8b0dfd199bb..62dbf3740a3 100644 --- a/homeassistant/components/homekit_controller/manifest.json +++ b/homeassistant/components/homekit_controller/manifest.json @@ -7,6 +7,7 @@ "homekit[IP]==0.14.0" ], "dependencies": [], + "zeroconf": ["_hap._tcp.local."], "codeowners": [ "@Jc2k" ] diff --git a/homeassistant/generated/zeroconf.py b/homeassistant/generated/zeroconf.py index 434a463dc17..acd912fe28a 100644 --- a/homeassistant/generated/zeroconf.py +++ b/homeassistant/generated/zeroconf.py @@ -13,5 +13,8 @@ SERVICE_TYPES = { ], "_esphomelib._tcp.local.": [ "esphome" + ], + "_hap._tcp.local.": [ + "homekit_controller" ] } diff --git a/tests/components/homekit_controller/common.py b/tests/components/homekit_controller/common.py index 87482f8e92c..34b6474c6e9 100644 --- a/tests/components/homekit_controller/common.py +++ b/tests/components/homekit_controller/common.py @@ -277,7 +277,7 @@ async def device_config_changed(hass, accessories): flow = config_flow.HomekitControllerFlowHandler() flow.hass = hass flow.context = {} - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'abort' assert result['reason'] == 'already_configured' diff --git a/tests/components/homekit_controller/test_config_flow.py b/tests/components/homekit_controller/test_config_flow.py index 9c869809544..07e2dd4afb1 100644 --- a/tests/components/homekit_controller/test_config_flow.py +++ b/tests/components/homekit_controller/test_config_flow.py @@ -64,7 +64,7 @@ async def test_discovery_works(hass): flow = _setup_flow_handler(hass) # Device is discovered - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'form' assert result['step_id'] == 'pair' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -119,7 +119,7 @@ async def test_discovery_works_upper_case(hass): flow = _setup_flow_handler(hass) # Device is discovered - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'form' assert result['step_id'] == 'pair' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -172,7 +172,7 @@ async def test_discovery_works_missing_csharp(hass): flow = _setup_flow_handler(hass) # Device is discovered - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'form' assert result['step_id'] == 'pair' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -226,7 +226,7 @@ async def test_pair_already_paired_1(hass): flow = _setup_flow_handler(hass) - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'abort' assert result['reason'] == 'already_paired' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -248,7 +248,7 @@ async def test_discovery_ignored_model(hass): flow = _setup_flow_handler(hass) - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'abort' assert result['reason'] == 'ignored_model' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -277,7 +277,7 @@ async def test_discovery_invalid_config_entry(hass): flow = _setup_flow_handler(hass) - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'form' assert result['step_id'] == 'pair' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -311,7 +311,7 @@ async def test_discovery_already_configured(hass): flow = _setup_flow_handler(hass) - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'abort' assert result['reason'] == 'already_configured' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -341,7 +341,7 @@ async def test_discovery_already_configured_config_change(hass): flow = _setup_flow_handler(hass) - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'abort' assert result['reason'] == 'already_configured' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -366,7 +366,7 @@ async def test_pair_unable_to_pair(hass): flow = _setup_flow_handler(hass) # Device is discovered - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'form' assert result['step_id'] == 'pair' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -403,7 +403,7 @@ async def test_pair_abort_errors_on_start(hass, exception, expected): flow = _setup_flow_handler(hass) # Device is discovered - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'form' assert result['step_id'] == 'pair' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -436,7 +436,7 @@ async def test_pair_form_errors_on_start(hass, exception, expected): flow = _setup_flow_handler(hass) # Device is discovered - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'form' assert result['step_id'] == 'pair' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -469,7 +469,7 @@ async def test_pair_abort_errors_on_finish(hass, exception, expected): flow = _setup_flow_handler(hass) # Device is discovered - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'form' assert result['step_id'] == 'pair' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -508,7 +508,7 @@ async def test_pair_form_errors_on_finish(hass, exception, expected): flow = _setup_flow_handler(hass) # Device is discovered - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'form' assert result['step_id'] == 'pair' assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} @@ -738,7 +738,7 @@ async def test_parse_new_homekit_json(hass): pairing_cls.return_value = pairing with mock.patch('builtins.open', mock_open): with mock.patch('os.path', mock_path): - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'create_entry' assert result['title'] == 'TestDevice' @@ -796,7 +796,7 @@ async def test_parse_old_homekit_json(hass): with mock.patch('builtins.open', mock_open): with mock.patch('os.path', mock_path): with mock.patch('os.listdir', mock_listdir): - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) assert result['type'] == 'create_entry' assert result['title'] == 'TestDevice' @@ -865,7 +865,7 @@ async def test_parse_overlapping_homekit_json(hass): with mock.patch('builtins.open', side_effect=side_effects): with mock.patch('os.path', mock_path): with mock.patch('os.listdir', mock_listdir): - result = await flow.async_step_discovery(discovery_info) + result = await flow.async_step_zeroconf(discovery_info) await hass.async_block_till_done()