mirror of
https://github.com/home-assistant/core.git
synced 2025-07-07 21:37:07 +00:00
Add dhcp discovery for fyta (#132185)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
b9e4855e05
commit
09d7fed6cd
@ -3,6 +3,7 @@
|
||||
"name": "FYTA",
|
||||
"codeowners": ["@dontinelli"],
|
||||
"config_flow": true,
|
||||
"dhcp": [{ "hostname": "fyta*" }],
|
||||
"documentation": "https://www.home-assistant.io/integrations/fyta",
|
||||
"integration_type": "hub",
|
||||
"iot_class": "cloud_polling",
|
||||
|
@ -26,7 +26,8 @@
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
|
||||
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]",
|
||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
||||
},
|
||||
"error": {
|
||||
|
@ -209,6 +209,10 @@ DHCP: Final[list[dict[str, str | bool]]] = [
|
||||
"domain": "fully_kiosk",
|
||||
"registered_devices": True,
|
||||
},
|
||||
{
|
||||
"domain": "fyta",
|
||||
"hostname": "fyta*",
|
||||
},
|
||||
{
|
||||
"domain": "goalzero",
|
||||
"registered_devices": True,
|
||||
|
@ -10,6 +10,7 @@ from fyta_cli.fyta_exceptions import (
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.dhcp import DhcpServiceInfo
|
||||
from homeassistant.components.fyta.const import CONF_EXPIRATION, DOMAIN
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -20,6 +21,26 @@ from .const import ACCESS_TOKEN, EXPIRATION, PASSWORD, USERNAME
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def user_step(
|
||||
hass: HomeAssistant, flow_id: str, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
"""Test user step (helper function)."""
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
flow_id, {CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == USERNAME
|
||||
assert result["data"] == {
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
CONF_ACCESS_TOKEN: ACCESS_TOKEN,
|
||||
CONF_EXPIRATION: EXPIRATION,
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_user_flow(
|
||||
hass: HomeAssistant, mock_fyta_connector: AsyncMock, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
@ -31,20 +52,7 @@ async def test_user_flow(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {}
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["title"] == USERNAME
|
||||
assert result2["data"] == {
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
CONF_ACCESS_TOKEN: ACCESS_TOKEN,
|
||||
CONF_EXPIRATION: EXPIRATION,
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
await user_step(hass, result["flow_id"], mock_setup_entry)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -190,3 +198,27 @@ async def test_reauth(
|
||||
assert entry.data[CONF_PASSWORD] == "other_password"
|
||||
assert entry.data[CONF_ACCESS_TOKEN] == ACCESS_TOKEN
|
||||
assert entry.data[CONF_EXPIRATION] == EXPIRATION
|
||||
|
||||
|
||||
async def test_dhcp_discovery(
|
||||
hass: HomeAssistant, mock_fyta_connector: AsyncMock, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
"""Test DHCP discovery flow."""
|
||||
|
||||
service_info = DhcpServiceInfo(
|
||||
hostname="FYTA HUB",
|
||||
ip="1.2.3.4",
|
||||
macaddress="aabbccddeeff",
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data=service_info,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
await user_step(hass, result["flow_id"], mock_setup_entry)
|
||||
|
Loading…
x
Reference in New Issue
Block a user