mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Use zeroconf attributes in freebox (#58967)
* Use zeroconf attributes in freebox * Use zeroconf.HaServiceInfo in tests
This commit is contained in:
parent
9eaf8bd21b
commit
cf22bd8807
@ -5,7 +5,10 @@ from freebox_api.exceptions import AuthorizationError, HttpRequestError
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .router import get_api
|
from .router import get_api
|
||||||
@ -105,8 +108,10 @@ class FreeboxFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""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):
|
async def async_step_zeroconf(
|
||||||
|
self, discovery_info: DiscoveryInfoType
|
||||||
|
) -> FlowResult:
|
||||||
"""Initialize flow from zeroconf."""
|
"""Initialize flow from zeroconf."""
|
||||||
host = discovery_info["properties"]["api_domain"]
|
host = discovery_info[zeroconf.ATTR_PROPERTIES]["api_domain"]
|
||||||
port = discovery_info["properties"]["https_port"]
|
port = discovery_info[zeroconf.ATTR_PROPERTIES]["https_port"]
|
||||||
return await self.async_step_user({CONF_HOST: host, CONF_PORT: port})
|
return await self.async_step_user({CONF_HOST: host, CONF_PORT: port})
|
||||||
|
@ -8,6 +8,7 @@ from freebox_api.exceptions import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.freebox.const import DOMAIN
|
from homeassistant.components.freebox.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER, SOURCE_ZEROCONF
|
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
|
||||||
@ -17,13 +18,13 @@ from .const import MOCK_HOST, MOCK_PORT
|
|||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
MOCK_ZEROCONF_DATA = {
|
MOCK_ZEROCONF_DATA = zeroconf.HaServiceInfo(
|
||||||
"host": "192.168.0.254",
|
host="192.168.0.254",
|
||||||
"port": 80,
|
port=80,
|
||||||
"hostname": "Freebox-Server.local.",
|
hostname="Freebox-Server.local.",
|
||||||
"type": "_fbx-api._tcp.local.",
|
type="_fbx-api._tcp.local.",
|
||||||
"name": "Freebox Server._fbx-api._tcp.local.",
|
name="Freebox Server._fbx-api._tcp.local.",
|
||||||
"properties": {
|
properties={
|
||||||
"api_version": "8.0",
|
"api_version": "8.0",
|
||||||
"device_type": "FreeboxServer1,2",
|
"device_type": "FreeboxServer1,2",
|
||||||
"api_base_url": "/api/",
|
"api_base_url": "/api/",
|
||||||
@ -34,7 +35,7 @@ MOCK_ZEROCONF_DATA = {
|
|||||||
"box_model_name": "Freebox Server (r2)",
|
"box_model_name": "Freebox Server (r2)",
|
||||||
"api_domain": MOCK_HOST,
|
"api_domain": MOCK_HOST,
|
||||||
},
|
},
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_user(hass: HomeAssistant):
|
async def test_user(hass: HomeAssistant):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user