Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up discovery integration #47022

Merged
merged 3 commits into from Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions homeassistant/components/daikin/config_flow.py
Expand Up @@ -12,7 +12,7 @@
from homeassistant import config_entries
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD

from .const import CONF_UUID, KEY_IP, KEY_MAC, TIMEOUT
from .const import CONF_UUID, KEY_MAC, TIMEOUT

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -124,14 +124,6 @@ async def async_step_import(self, user_input):
return await self.async_step_user()
return await self._create_device(host)

async def async_step_discovery(self, discovery_info):
"""Initialize step from discovery."""
_LOGGER.debug("Discovered device: %s", discovery_info)
await self.async_set_unique_id(discovery_info[KEY_MAC])
self._abort_if_unique_id_configured()
self.host = discovery_info[KEY_IP]
return await self.async_step_user()

async def async_step_zeroconf(self, discovery_info):
"""Prepare configuration for a discovered Daikin device."""
_LOGGER.debug("Zeroconf user_input: %s", discovery_info)
Expand Down
22 changes: 12 additions & 10 deletions homeassistant/components/discovery/__init__.py
Expand Up @@ -38,25 +38,17 @@
SERVICE_WINK = "wink"
SERVICE_XIAOMI_GW = "xiaomi_gw"

# These have custom protocols
CONFIG_ENTRY_HANDLERS = {
SERVICE_DAIKIN: "daikin",
SERVICE_TELLDUSLIVE: "tellduslive",
"logitech_mediaserver": "squeezebox",
}

# These have no config flows
SERVICE_HANDLERS = {
SERVICE_MOBILE_APP: ("mobile_app", None),
SERVICE_HASS_IOS_APP: ("ios", None),
SERVICE_NETGEAR: ("device_tracker", None),
SERVICE_HASSIO: ("hassio", None),
SERVICE_APPLE_TV: ("apple_tv", None),
SERVICE_ENIGMA2: ("media_player", "enigma2"),
SERVICE_WINK: ("wink", None),
SERVICE_SABNZBD: ("sabnzbd", None),
SERVICE_SAMSUNG_PRINTER: ("sensor", None),
SERVICE_KONNECTED: ("konnected", None),
SERVICE_OCTOPRINT: ("octoprint", None),
SERVICE_FREEBOX: ("freebox", None),
"yamaha": ("media_player", "yamaha"),
"frontier_silicon": ("media_player", "frontier_silicon"),
"openhome": ("media_player", "openhome"),
Expand All @@ -69,20 +61,30 @@
OPTIONAL_SERVICE_HANDLERS = {SERVICE_DLNA_DMR: ("media_player", "dlna_dmr")}

MIGRATED_SERVICE_HANDLERS = [
SERVICE_APPLE_TV,
"axis",
"deconz",
SERVICE_DAIKIN,
"denonavr",
"esphome",
SERVICE_FREEBOX,
"google_cast",
SERVICE_HASS_IOS_APP,
SERVICE_HASSIO,
SERVICE_HEOS,
"harmony",
"homekit",
"ikea_tradfri",
"kodi",
SERVICE_KONNECTED,
SERVICE_MOBILE_APP,
SERVICE_OCTOPRINT,
"philips_hue",
SERVICE_SAMSUNG_PRINTER,
"sonos",
"songpal",
SERVICE_WEMO,
SERVICE_WINK,
SERVICE_XIAOMI_GW,
"volumio",
SERVICE_YEELIGHT,
Expand Down
20 changes: 2 additions & 18 deletions homeassistant/components/freebox/__init__.py
Expand Up @@ -4,10 +4,9 @@

import voluptuous as vol

from homeassistant.components.discovery import SERVICE_FREEBOX
from homeassistant.config_entries import SOURCE_DISCOVERY, SOURCE_IMPORT, ConfigEntry
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP
from homeassistant.helpers import config_validation as cv, discovery
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import HomeAssistantType

from .const import DOMAIN, PLATFORMS
Expand All @@ -29,21 +28,6 @@ async def async_setup(hass, config):
"""Set up the Freebox component."""
conf = config.get(DOMAIN)

async def discovery_dispatch(service, discovery_info):
if conf is None:
host = discovery_info.get("properties", {}).get("api_domain")
port = discovery_info.get("properties", {}).get("https_port")
_LOGGER.info("Discovered Freebox server: %s:%s", host, port)
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_DISCOVERY},
balloob marked this conversation as resolved.
Show resolved Hide resolved
data={CONF_HOST: host, CONF_PORT: port},
)
)

discovery.async_listen(hass, SERVICE_FREEBOX, discovery_dispatch)

if conf is None:
return True

Expand Down
4 changes: 0 additions & 4 deletions homeassistant/components/freebox/config_flow.py
Expand Up @@ -105,7 +105,3 @@ async def async_step_link(self, user_input=None):
async def async_step_import(self, user_input=None):
"""Import a config entry."""
return await self.async_step_user(user_input)

async def async_step_discovery(self, discovery_info):
"""Initialize step from discovery."""
return await self.async_step_user(discovery_info)
2 changes: 1 addition & 1 deletion homeassistant/components/freebox/manifest.json
Expand Up @@ -4,6 +4,6 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/freebox",
"requirements": ["freebox-api==0.0.9"],
"after_dependencies": ["discovery"],
"zeroconf": ["_fbx-api._tcp.local."],
"codeowners": ["@hacf-fr", "@Quentame"]
}
5 changes: 5 additions & 0 deletions homeassistant/generated/zeroconf.py
Expand Up @@ -59,6 +59,11 @@
"domain": "esphome"
}
],
"_fbx-api._tcp.local.": [
{
"domain": "freebox"
}
],
"_googlecast._tcp.local.": [
{
"domain": "cast"
Expand Down
10 changes: 2 additions & 8 deletions tests/components/daikin/test_config_flow.py
Expand Up @@ -7,13 +7,8 @@
from aiohttp.web_exceptions import HTTPForbidden
import pytest

from homeassistant.components.daikin.const import KEY_IP, KEY_MAC
from homeassistant.config_entries import (
SOURCE_DISCOVERY,
SOURCE_IMPORT,
SOURCE_USER,
SOURCE_ZEROCONF,
)
from homeassistant.components.daikin.const import KEY_MAC
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.const import CONF_HOST
from homeassistant.data_entry_flow import (
RESULT_TYPE_ABORT,
Expand Down Expand Up @@ -132,7 +127,6 @@ async def test_device_abort(hass, mock_daikin, s_effect, reason):
@pytest.mark.parametrize(
"source, data, unique_id",
[
(SOURCE_DISCOVERY, {KEY_IP: HOST, KEY_MAC: MAC}, MAC),
(SOURCE_ZEROCONF, {CONF_HOST: HOST}, MAC),
],
)
Expand Down
6 changes: 3 additions & 3 deletions tests/components/discovery/test_init.py
Expand Up @@ -16,8 +16,8 @@
SERVICE = "yamaha"
SERVICE_COMPONENT = "media_player"

SERVICE_NO_PLATFORM = "hass_ios"
SERVICE_NO_PLATFORM_COMPONENT = "ios"
SERVICE_NO_PLATFORM = "netgear_router"
SERVICE_NO_PLATFORM_COMPONENT = "device_tracker"
SERVICE_INFO = {"key": "value"} # Can be anything

UNKNOWN_SERVICE = "this_service_will_never_be_supported"
Expand All @@ -39,7 +39,7 @@ async def mock_discovery(hass, discoveries, config=BASE_CONFIG):
with patch("homeassistant.components.zeroconf.async_get_instance"), patch(
"homeassistant.components.zeroconf.async_setup", return_value=True
), patch.object(discovery, "_discover", discoveries), patch(
"homeassistant.components.discovery.async_discover", return_value=mock_coro()
"homeassistant.components.discovery.async_discover"
) as mock_discover, patch(
"homeassistant.components.discovery.async_load_platform",
return_value=mock_coro(),
Expand Down
13 changes: 1 addition & 12 deletions tests/components/freebox/test_config_flow.py
Expand Up @@ -10,7 +10,7 @@

from homeassistant import data_entry_flow
from homeassistant.components.freebox.const import DOMAIN
from homeassistant.config_entries import SOURCE_DISCOVERY, SOURCE_IMPORT, SOURCE_USER
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.const import CONF_HOST, CONF_PORT

from tests.common import MockConfigEntry
Expand Down Expand Up @@ -66,17 +66,6 @@ async def test_import(hass):
assert result["step_id"] == "link"


async def test_discovery(hass):
"""Test discovery step."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_DISCOVERY},
data={CONF_HOST: HOST, CONF_PORT: PORT},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "link"


async def test_link(hass, connect):
"""Test linking."""
result = await hass.config_entries.flow.async_init(
Expand Down