mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Add zeroconf discovery to Freebox (#47045)
* Add zeroconf discovery to Freebox - remove deprecated discovery - tried with SSDP too but the presentation URL is not the same (*.fbxos.fr for zeroconf, http://mafreebox.freebox.fr/ for SSDP) - so config entry unique_id should be the MAC (included into SSDP, but not zeroconf, can be retrieve from `fbx.system.get_config()`) - DHCP discovery might be added in the future too * host and port are required on zeroconf * cleanup in other PR
This commit is contained in:
parent
5bba532dd4
commit
125206adbf
@ -22,7 +22,6 @@ SERVICE_APPLE_TV = "apple_tv"
|
|||||||
SERVICE_DAIKIN = "daikin"
|
SERVICE_DAIKIN = "daikin"
|
||||||
SERVICE_DLNA_DMR = "dlna_dmr"
|
SERVICE_DLNA_DMR = "dlna_dmr"
|
||||||
SERVICE_ENIGMA2 = "enigma2"
|
SERVICE_ENIGMA2 = "enigma2"
|
||||||
SERVICE_FREEBOX = "freebox"
|
|
||||||
SERVICE_HASS_IOS_APP = "hass_ios"
|
SERVICE_HASS_IOS_APP = "hass_ios"
|
||||||
SERVICE_HASSIO = "hassio"
|
SERVICE_HASSIO = "hassio"
|
||||||
SERVICE_HEOS = "heos"
|
SERVICE_HEOS = "heos"
|
||||||
@ -67,7 +66,6 @@ MIGRATED_SERVICE_HANDLERS = [
|
|||||||
SERVICE_DAIKIN,
|
SERVICE_DAIKIN,
|
||||||
"denonavr",
|
"denonavr",
|
||||||
"esphome",
|
"esphome",
|
||||||
SERVICE_FREEBOX,
|
|
||||||
"google_cast",
|
"google_cast",
|
||||||
SERVICE_HASS_IOS_APP,
|
SERVICE_HASS_IOS_APP,
|
||||||
SERVICE_HASSIO,
|
SERVICE_HASSIO,
|
||||||
|
@ -25,18 +25,12 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the Freebox component."""
|
"""Set up the Freebox integration."""
|
||||||
conf = config.get(DOMAIN)
|
if DOMAIN in config:
|
||||||
|
for entry_config in config[DOMAIN]:
|
||||||
if conf is None:
|
|
||||||
return True
|
|
||||||
|
|
||||||
for freebox_conf in conf:
|
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.flow.async_init(
|
hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN, context={"source": SOURCE_IMPORT}, data=entry_config
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=freebox_conf,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,7 +38,7 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
||||||
"""Set up Freebox component."""
|
"""Set up Freebox entry."""
|
||||||
router = FreeboxRouter(hass, entry)
|
router = FreeboxRouter(hass, entry)
|
||||||
await router.setup()
|
await router.setup()
|
||||||
|
|
||||||
|
@ -105,3 +105,9 @@ class FreeboxFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
async def async_step_import(self, user_input=None):
|
async def async_step_import(self, user_input=None):
|
||||||
"""Import a config entry."""
|
"""Import a config entry."""
|
||||||
return await self.async_step_user(user_input)
|
return await self.async_step_user(user_input)
|
||||||
|
|
||||||
|
async def async_step_zeroconf(self, discovery_info: dict):
|
||||||
|
"""Initialize flow from zeroconf."""
|
||||||
|
host = discovery_info["properties"]["api_domain"]
|
||||||
|
port = discovery_info["properties"]["https_port"]
|
||||||
|
return await self.async_step_user({CONF_HOST: host, CONF_PORT: port})
|
||||||
|
@ -10,7 +10,7 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.freebox.const import DOMAIN
|
from homeassistant.components.freebox.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER, SOURCE_ZEROCONF
|
||||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
@ -18,6 +18,25 @@ from tests.common import MockConfigEntry
|
|||||||
HOST = "myrouter.freeboxos.fr"
|
HOST = "myrouter.freeboxos.fr"
|
||||||
PORT = 1234
|
PORT = 1234
|
||||||
|
|
||||||
|
MOCK_ZEROCONF_DATA = {
|
||||||
|
"host": "192.168.0.254",
|
||||||
|
"port": 80,
|
||||||
|
"hostname": "Freebox-Server.local.",
|
||||||
|
"type": "_fbx-api._tcp.local.",
|
||||||
|
"name": "Freebox Server._fbx-api._tcp.local.",
|
||||||
|
"properties": {
|
||||||
|
"api_version": "8.0",
|
||||||
|
"device_type": "FreeboxServer1,2",
|
||||||
|
"api_base_url": "/api/",
|
||||||
|
"uid": "b15ab20debb399f95001a9ca207d2777",
|
||||||
|
"https_available": "1",
|
||||||
|
"https_port": f"{PORT}",
|
||||||
|
"box_model": "fbxgw-r2/full",
|
||||||
|
"box_model_name": "Freebox Server (r2)",
|
||||||
|
"api_domain": HOST,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="connect")
|
@pytest.fixture(name="connect")
|
||||||
def mock_controller_connect():
|
def mock_controller_connect():
|
||||||
@ -66,6 +85,17 @@ async def test_import(hass):
|
|||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_zeroconf(hass):
|
||||||
|
"""Test zeroconf step."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": SOURCE_ZEROCONF},
|
||||||
|
data=MOCK_ZEROCONF_DATA,
|
||||||
|
)
|
||||||
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
|
|
||||||
async def test_link(hass, connect):
|
async def test_link(hass, connect):
|
||||||
"""Test linking."""
|
"""Test linking."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user