Trådfri component to use new zeroconf discovery (#24041)

* Move tradfri component to use new zeroconf discovery

* Will this work?

* Remove prints

* Correct order in generated zeroconf

* Update test_init.py

* Update test_init.py

* Update test_init.py

* Update test_init.py
This commit is contained in:
Robert Svensson 2019-05-29 20:19:50 +02:00 committed by Paulus Schoutsen
parent 4b256f3466
commit 3fef9a93cf
7 changed files with 13 additions and 9 deletions

View file

@ -34,7 +34,6 @@ SERVICE_HASSIO = 'hassio'
SERVICE_HOMEKIT = 'homekit'
SERVICE_HEOS = 'heos'
SERVICE_IGD = 'igd'
SERVICE_IKEA_TRADFRI = 'ikea_tradfri'
SERVICE_KONNECTED = 'konnected'
SERVICE_MOBILE_APP = 'hass_mobile_app'
SERVICE_NETGEAR = 'netgear_router'
@ -54,7 +53,6 @@ CONFIG_ENTRY_HANDLERS = {
'google_cast': 'cast',
SERVICE_HEOS: 'heos',
SERVICE_TELLDUSLIVE: 'tellduslive',
SERVICE_IKEA_TRADFRI: 'tradfri',
'sonos': 'sonos',
SERVICE_IGD: 'upnp',
SERVICE_HOMEKIT: 'homekit_controller',

View file

@ -76,8 +76,8 @@ class FlowHandler(config_entries.ConfigFlow):
errors=errors,
)
async def async_step_discovery(self, user_input):
"""Handle discovery."""
async def async_step_zeroconf(self, user_input):
"""Handle zeroconf discovery."""
for entry in self._async_current_entries():
if entry.data[CONF_HOST] == user_input['host']:
return self.async_abort(

View file

@ -7,6 +7,7 @@
"pytradfri[async]==6.0.1"
],
"dependencies": [],
"zeroconf": ["_coap._udp.local."],
"codeowners": [
"@ggravlingen"
]

View file

@ -8,6 +8,9 @@ SERVICE_TYPES = {
"_axis-video._tcp.local.": [
"axis"
],
"_coap._udp.local.": [
"tradfri"
],
"_esphomelib._tcp.local.": [
"esphome"
]

View file

@ -63,7 +63,8 @@ def validate(integrations: Dict[str, Integration], config: Config):
config.cache['zeroconf'] = content = generate_and_validate(integrations)
with open(str(zeroconf_path), 'r') as fp:
if fp.read().strip() != content:
current = fp.read().strip()
if current != content:
config.add_error(
"zeroconf",
"File zeroconf.py is not up to date. "

View file

@ -99,7 +99,7 @@ async def test_discovery_connection(hass, mock_auth, mock_entry_setup):
})
flow = await hass.config_entries.flow.async_init(
'tradfri', context={'source': 'discovery'}, data={
'tradfri', context={'source': 'zeroconf'}, data={
'host': '123.123.123.123'
})
@ -249,7 +249,7 @@ async def test_discovery_duplicate_aborted(hass):
).add_to_hass(hass)
flow = await hass.config_entries.flow.async_init(
'tradfri', context={'source': 'discovery'}, data={
'tradfri', context={'source': 'zeroconf'}, data={
'host': 'some-host'
})

View file

@ -3,6 +3,7 @@ from unittest.mock import patch
from aiozeroconf import ServiceInfo, ServiceStateChange
from homeassistant.generated import zeroconf as zc_gen
from homeassistant.setup import async_setup_component
from homeassistant.components import zeroconf
@ -36,5 +37,5 @@ async def test_setup(hass):
hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
await hass.async_block_till_done()
assert len(MockServiceBrowser.mock_calls) == 2
assert len(mock_config_flow.mock_calls) == 2
assert len(MockServiceBrowser.mock_calls) == len(zc_gen.SERVICE_TYPES)
assert len(mock_config_flow.mock_calls) == len(zc_gen.SERVICE_TYPES)