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:
parent
4b256f3466
commit
3fef9a93cf
7 changed files with 13 additions and 9 deletions
|
@ -34,7 +34,6 @@ SERVICE_HASSIO = 'hassio'
|
||||||
SERVICE_HOMEKIT = 'homekit'
|
SERVICE_HOMEKIT = 'homekit'
|
||||||
SERVICE_HEOS = 'heos'
|
SERVICE_HEOS = 'heos'
|
||||||
SERVICE_IGD = 'igd'
|
SERVICE_IGD = 'igd'
|
||||||
SERVICE_IKEA_TRADFRI = 'ikea_tradfri'
|
|
||||||
SERVICE_KONNECTED = 'konnected'
|
SERVICE_KONNECTED = 'konnected'
|
||||||
SERVICE_MOBILE_APP = 'hass_mobile_app'
|
SERVICE_MOBILE_APP = 'hass_mobile_app'
|
||||||
SERVICE_NETGEAR = 'netgear_router'
|
SERVICE_NETGEAR = 'netgear_router'
|
||||||
|
@ -54,7 +53,6 @@ CONFIG_ENTRY_HANDLERS = {
|
||||||
'google_cast': 'cast',
|
'google_cast': 'cast',
|
||||||
SERVICE_HEOS: 'heos',
|
SERVICE_HEOS: 'heos',
|
||||||
SERVICE_TELLDUSLIVE: 'tellduslive',
|
SERVICE_TELLDUSLIVE: 'tellduslive',
|
||||||
SERVICE_IKEA_TRADFRI: 'tradfri',
|
|
||||||
'sonos': 'sonos',
|
'sonos': 'sonos',
|
||||||
SERVICE_IGD: 'upnp',
|
SERVICE_IGD: 'upnp',
|
||||||
SERVICE_HOMEKIT: 'homekit_controller',
|
SERVICE_HOMEKIT: 'homekit_controller',
|
||||||
|
|
|
@ -76,8 +76,8 @@ class FlowHandler(config_entries.ConfigFlow):
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_discovery(self, user_input):
|
async def async_step_zeroconf(self, user_input):
|
||||||
"""Handle discovery."""
|
"""Handle zeroconf discovery."""
|
||||||
for entry in self._async_current_entries():
|
for entry in self._async_current_entries():
|
||||||
if entry.data[CONF_HOST] == user_input['host']:
|
if entry.data[CONF_HOST] == user_input['host']:
|
||||||
return self.async_abort(
|
return self.async_abort(
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"pytradfri[async]==6.0.1"
|
"pytradfri[async]==6.0.1"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
|
"zeroconf": ["_coap._udp.local."],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
"@ggravlingen"
|
"@ggravlingen"
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,6 +8,9 @@ SERVICE_TYPES = {
|
||||||
"_axis-video._tcp.local.": [
|
"_axis-video._tcp.local.": [
|
||||||
"axis"
|
"axis"
|
||||||
],
|
],
|
||||||
|
"_coap._udp.local.": [
|
||||||
|
"tradfri"
|
||||||
|
],
|
||||||
"_esphomelib._tcp.local.": [
|
"_esphomelib._tcp.local.": [
|
||||||
"esphome"
|
"esphome"
|
||||||
]
|
]
|
||||||
|
|
|
@ -63,7 +63,8 @@ def validate(integrations: Dict[str, Integration], config: Config):
|
||||||
config.cache['zeroconf'] = content = generate_and_validate(integrations)
|
config.cache['zeroconf'] = content = generate_and_validate(integrations)
|
||||||
|
|
||||||
with open(str(zeroconf_path), 'r') as fp:
|
with open(str(zeroconf_path), 'r') as fp:
|
||||||
if fp.read().strip() != content:
|
current = fp.read().strip()
|
||||||
|
if current != content:
|
||||||
config.add_error(
|
config.add_error(
|
||||||
"zeroconf",
|
"zeroconf",
|
||||||
"File zeroconf.py is not up to date. "
|
"File zeroconf.py is not up to date. "
|
||||||
|
|
|
@ -99,7 +99,7 @@ async def test_discovery_connection(hass, mock_auth, mock_entry_setup):
|
||||||
})
|
})
|
||||||
|
|
||||||
flow = await hass.config_entries.flow.async_init(
|
flow = await hass.config_entries.flow.async_init(
|
||||||
'tradfri', context={'source': 'discovery'}, data={
|
'tradfri', context={'source': 'zeroconf'}, data={
|
||||||
'host': '123.123.123.123'
|
'host': '123.123.123.123'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ async def test_discovery_duplicate_aborted(hass):
|
||||||
).add_to_hass(hass)
|
).add_to_hass(hass)
|
||||||
|
|
||||||
flow = await hass.config_entries.flow.async_init(
|
flow = await hass.config_entries.flow.async_init(
|
||||||
'tradfri', context={'source': 'discovery'}, data={
|
'tradfri', context={'source': 'zeroconf'}, data={
|
||||||
'host': 'some-host'
|
'host': 'some-host'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ from unittest.mock import patch
|
||||||
|
|
||||||
from aiozeroconf import ServiceInfo, ServiceStateChange
|
from aiozeroconf import ServiceInfo, ServiceStateChange
|
||||||
|
|
||||||
|
from homeassistant.generated import zeroconf as zc_gen
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
|
|
||||||
|
@ -36,5 +37,5 @@ async def test_setup(hass):
|
||||||
hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(MockServiceBrowser.mock_calls) == 2
|
assert len(MockServiceBrowser.mock_calls) == len(zc_gen.SERVICE_TYPES)
|
||||||
assert len(mock_config_flow.mock_calls) == 2
|
assert len(mock_config_flow.mock_calls) == len(zc_gen.SERVICE_TYPES)
|
||||||
|
|
Loading…
Add table
Reference in a new issue