Move Homekit controller component to user zeroconf discovery (#24042)

This commit is contained in:
Robert Svensson 2019-05-29 20:20:04 +02:00 committed by Paulus Schoutsen
parent 3fef9a93cf
commit 42ee8eef50
6 changed files with 23 additions and 21 deletions

View file

@ -31,7 +31,6 @@ SERVICE_ENIGMA2 = 'enigma2'
SERVICE_FREEBOX = 'freebox' SERVICE_FREEBOX = 'freebox'
SERVICE_HASS_IOS_APP = 'hass_ios' SERVICE_HASS_IOS_APP = 'hass_ios'
SERVICE_HASSIO = 'hassio' SERVICE_HASSIO = 'hassio'
SERVICE_HOMEKIT = 'homekit'
SERVICE_HEOS = 'heos' SERVICE_HEOS = 'heos'
SERVICE_IGD = 'igd' SERVICE_IGD = 'igd'
SERVICE_KONNECTED = 'konnected' SERVICE_KONNECTED = 'konnected'
@ -55,7 +54,6 @@ CONFIG_ENTRY_HANDLERS = {
SERVICE_TELLDUSLIVE: 'tellduslive', SERVICE_TELLDUSLIVE: 'tellduslive',
'sonos': 'sonos', 'sonos': 'sonos',
SERVICE_IGD: 'upnp', SERVICE_IGD: 'upnp',
SERVICE_HOMEKIT: 'homekit_controller',
} }
SERVICE_HANDLERS = { SERVICE_HANDLERS = {

View file

@ -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. """Handle a discovered HomeKit accessory.
This flow is triggered by the discovery component. This flow is triggered by the discovery component.
@ -132,7 +132,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow):
# pylint: disable=unsupported-assignment-operation # pylint: disable=unsupported-assignment-operation
self.context['title_placeholders'] = { 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 # The configuration number increases every time the characteristic map

View file

@ -7,6 +7,7 @@
"homekit[IP]==0.14.0" "homekit[IP]==0.14.0"
], ],
"dependencies": [], "dependencies": [],
"zeroconf": ["_hap._tcp.local."],
"codeowners": [ "codeowners": [
"@Jc2k" "@Jc2k"
] ]

View file

@ -13,5 +13,8 @@ SERVICE_TYPES = {
], ],
"_esphomelib._tcp.local.": [ "_esphomelib._tcp.local.": [
"esphome" "esphome"
],
"_hap._tcp.local.": [
"homekit_controller"
] ]
} }

View file

@ -277,7 +277,7 @@ async def device_config_changed(hass, accessories):
flow = config_flow.HomekitControllerFlowHandler() flow = config_flow.HomekitControllerFlowHandler()
flow.hass = hass flow.hass = hass
flow.context = {} flow.context = {}
result = await flow.async_step_discovery(discovery_info) result = await flow.async_step_zeroconf(discovery_info)
assert result['type'] == 'abort' assert result['type'] == 'abort'
assert result['reason'] == 'already_configured' assert result['reason'] == 'already_configured'

View file

@ -64,7 +64,7 @@ async def test_discovery_works(hass):
flow = _setup_flow_handler(hass) flow = _setup_flow_handler(hass)
# Device is discovered # 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['type'] == 'form'
assert result['step_id'] == 'pair' assert result['step_id'] == 'pair'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} assert flow.context == {'title_placeholders': {'name': 'TestDevice'}}
@ -119,7 +119,7 @@ async def test_discovery_works_upper_case(hass):
flow = _setup_flow_handler(hass) flow = _setup_flow_handler(hass)
# Device is discovered # 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['type'] == 'form'
assert result['step_id'] == 'pair' assert result['step_id'] == 'pair'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} assert flow.context == {'title_placeholders': {'name': 'TestDevice'}}
@ -172,7 +172,7 @@ async def test_discovery_works_missing_csharp(hass):
flow = _setup_flow_handler(hass) flow = _setup_flow_handler(hass)
# Device is discovered # 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['type'] == 'form'
assert result['step_id'] == 'pair' assert result['step_id'] == 'pair'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} assert flow.context == {'title_placeholders': {'name': 'TestDevice'}}
@ -226,7 +226,7 @@ async def test_pair_already_paired_1(hass):
flow = _setup_flow_handler(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['type'] == 'abort'
assert result['reason'] == 'already_paired' assert result['reason'] == 'already_paired'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} assert flow.context == {'title_placeholders': {'name': 'TestDevice'}}
@ -248,7 +248,7 @@ async def test_discovery_ignored_model(hass):
flow = _setup_flow_handler(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['type'] == 'abort'
assert result['reason'] == 'ignored_model' assert result['reason'] == 'ignored_model'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} assert flow.context == {'title_placeholders': {'name': 'TestDevice'}}
@ -277,7 +277,7 @@ async def test_discovery_invalid_config_entry(hass):
flow = _setup_flow_handler(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['type'] == 'form'
assert result['step_id'] == 'pair' assert result['step_id'] == 'pair'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} assert flow.context == {'title_placeholders': {'name': 'TestDevice'}}
@ -311,7 +311,7 @@ async def test_discovery_already_configured(hass):
flow = _setup_flow_handler(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['type'] == 'abort'
assert result['reason'] == 'already_configured' assert result['reason'] == 'already_configured'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} 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) 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['type'] == 'abort'
assert result['reason'] == 'already_configured' assert result['reason'] == 'already_configured'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} assert flow.context == {'title_placeholders': {'name': 'TestDevice'}}
@ -366,7 +366,7 @@ async def test_pair_unable_to_pair(hass):
flow = _setup_flow_handler(hass) flow = _setup_flow_handler(hass)
# Device is discovered # 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['type'] == 'form'
assert result['step_id'] == 'pair' assert result['step_id'] == 'pair'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} 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) flow = _setup_flow_handler(hass)
# Device is discovered # 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['type'] == 'form'
assert result['step_id'] == 'pair' assert result['step_id'] == 'pair'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} 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) flow = _setup_flow_handler(hass)
# Device is discovered # 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['type'] == 'form'
assert result['step_id'] == 'pair' assert result['step_id'] == 'pair'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} 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) flow = _setup_flow_handler(hass)
# Device is discovered # 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['type'] == 'form'
assert result['step_id'] == 'pair' assert result['step_id'] == 'pair'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} 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) flow = _setup_flow_handler(hass)
# Device is discovered # 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['type'] == 'form'
assert result['step_id'] == 'pair' assert result['step_id'] == 'pair'
assert flow.context == {'title_placeholders': {'name': 'TestDevice'}} assert flow.context == {'title_placeholders': {'name': 'TestDevice'}}
@ -738,7 +738,7 @@ async def test_parse_new_homekit_json(hass):
pairing_cls.return_value = pairing pairing_cls.return_value = pairing
with mock.patch('builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
with mock.patch('os.path', mock_path): 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['type'] == 'create_entry'
assert result['title'] == 'TestDevice' 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('builtins.open', mock_open):
with mock.patch('os.path', mock_path): with mock.patch('os.path', mock_path):
with mock.patch('os.listdir', mock_listdir): 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['type'] == 'create_entry'
assert result['title'] == 'TestDevice' 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('builtins.open', side_effect=side_effects):
with mock.patch('os.path', mock_path): with mock.patch('os.path', mock_path):
with mock.patch('os.listdir', mock_listdir): 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() await hass.async_block_till_done()