Clean up discovery integration (#47022)
* Clean up discovery integration * Fix tests * Remove discovery step from freeboxpull/47045/head
parent
7a691f9d26
commit
1989b8c07d
|
@ -12,7 +12,7 @@ import voluptuous as vol
|
|||
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__)
|
||||
|
||||
|
@ -124,14 +124,6 @@ class FlowHandler(config_entries.ConfigFlow):
|
|||
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)
|
||||
|
|
|
@ -38,25 +38,17 @@ SERVICE_WEMO = "belkin_wemo"
|
|||
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"),
|
||||
|
@ -69,20 +61,30 @@ SERVICE_HANDLERS = {
|
|||
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,
|
||||
|
|
|
@ -4,10 +4,9 @@ import logging
|
|||
|
||||
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
|
||||
|
@ -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},
|
||||
data={CONF_HOST: host, CONF_PORT: port},
|
||||
)
|
||||
)
|
||||
|
||||
discovery.async_listen(hass, SERVICE_FREEBOX, discovery_dispatch)
|
||||
|
||||
if conf is None:
|
||||
return True
|
||||
|
||||
|
|
|
@ -105,7 +105,3 @@ class FreeboxFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
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)
|
||||
|
|
|
@ -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"]
|
||||
}
|
||||
|
|
|
@ -59,6 +59,11 @@ ZEROCONF = {
|
|||
"domain": "esphome"
|
||||
}
|
||||
],
|
||||
"_fbx-api._tcp.local.": [
|
||||
{
|
||||
"domain": "freebox"
|
||||
}
|
||||
],
|
||||
"_googlecast._tcp.local.": [
|
||||
{
|
||||
"domain": "cast"
|
||||
|
|
|
@ -7,13 +7,8 @@ from aiohttp import ClientError
|
|||
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,
|
||||
|
@ -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),
|
||||
],
|
||||
)
|
||||
|
|
|
@ -16,8 +16,8 @@ from tests.common import async_fire_time_changed, mock_coro
|
|||
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"
|
||||
|
@ -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(),
|
||||
|
|
|
@ -10,7 +10,7 @@ import pytest
|
|||
|
||||
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
|
||||
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue