forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Fastdotcom config flow (home-assistant#98686)
* Adding config flow and tests * Removing update and adding to integrations.json * Updating hassfest * Removing comments * Removing unique ID * Putting the setup_platform out of order * Adding feedback on issues and importing * Removing uniqueID (again) * Adjusting unload and typo * Updating manifest properly * Minor patching * Removing hass.data.setdefault(DOMAIN, {}) * Moving load_platform to __init__.py * Update homeassistant/components/fastdotcom/config_flow.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Update homeassistant/components/fastdotcom/strings.json Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Update homeassistant/components/fastdotcom/__init__.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Update homeassistant/components/fastdotcom/config_flow.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Adding an unload function for the timer * Adding issue on setup platform in sensor * Update homeassistant/components/fastdotcom/config_flow.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Removing platform * Fixing strings.json * Fine-tuning * Putting back last_state --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se>
- Loading branch information
1 parent
5805601
commit eb5c7a3
Showing
13 changed files
with
206 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Config flow for Fast.com integration.""" | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from homeassistant.config_entries import ConfigFlow | ||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN | ||
from homeassistant.data_entry_flow import FlowResult | ||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue | ||
|
||
from .const import DEFAULT_NAME, DOMAIN | ||
|
||
|
||
class FastdotcomConfigFlow(ConfigFlow, domain=DOMAIN): | ||
"""Handle a config flow for Fast.com.""" | ||
|
||
VERSION = 1 | ||
|
||
async def async_step_user( | ||
self, user_input: dict[str, Any] | None = None | ||
) -> FlowResult: | ||
"""Handle the initial step.""" | ||
if self._async_current_entries(): | ||
return self.async_abort(reason="single_instance_allowed") | ||
|
||
if user_input is not None: | ||
return self.async_create_entry(title=DEFAULT_NAME, data={}) | ||
|
||
return self.async_show_form(step_id="user") | ||
|
||
async def async_step_import( | ||
self, user_input: dict[str, Any] | None = None | ||
) -> FlowResult: | ||
"""Handle a flow initiated by configuration file.""" | ||
async_create_issue( | ||
self.hass, | ||
HOMEASSISTANT_DOMAIN, | ||
f"deprecated_yaml_{DOMAIN}", | ||
breaks_in_ha_version="2024.6.0", | ||
is_fixable=False, | ||
issue_domain=DOMAIN, | ||
severity=IssueSeverity.WARNING, | ||
translation_key="deprecated_yaml", | ||
translation_placeholders={ | ||
"domain": DOMAIN, | ||
"integration_title": "Fast.com", | ||
}, | ||
) | ||
|
||
return await self.async_step_user(user_input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Constants for the Fast.com integration.""" | ||
import logging | ||
|
||
from homeassistant.const import Platform | ||
|
||
LOGGER = logging.getLogger(__package__) | ||
|
||
DOMAIN = "fastdotcom" | ||
DATA_UPDATED = f"{DOMAIN}_data_updated" | ||
|
||
CONF_MANUAL = "manual" | ||
|
||
DEFAULT_NAME = "Fast.com" | ||
DEFAULT_INTERVAL = 1 | ||
PLATFORMS: list[Platform] = [Platform.SENSOR] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,7 @@ | |
"evil_genius_labs", | ||
"ezviz", | ||
"faa_delays", | ||
"fastdotcom", | ||
"fibaro", | ||
"filesize", | ||
"fireservicerota", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Fast.com integration tests.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"""Test for the Fast.com config flow.""" | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from homeassistant import config_entries | ||
from homeassistant.components.fastdotcom.const import DOMAIN | ||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.data_entry_flow import FlowResultType | ||
|
||
from tests.common import MockConfigEntry | ||
|
||
|
||
async def test_user_form(hass: HomeAssistant) -> None: | ||
"""Test the full user configuration flow.""" | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": SOURCE_USER} | ||
) | ||
|
||
assert result["type"] == FlowResultType.FORM | ||
assert result["step_id"] == "user" | ||
|
||
with patch( | ||
"homeassistant.components.fastdotcom.async_setup_entry", | ||
return_value=True, | ||
) as mock_setup_entry: | ||
result = await hass.config_entries.flow.async_configure( | ||
result["flow_id"], | ||
user_input={}, | ||
) | ||
|
||
assert result["type"] == FlowResultType.CREATE_ENTRY | ||
assert result["title"] == "Fast.com" | ||
assert result["data"] == {} | ||
assert result["options"] == {} | ||
assert len(mock_setup_entry.mock_calls) == 1 | ||
|
||
|
||
@pytest.mark.parametrize("source", [SOURCE_USER, SOURCE_IMPORT]) | ||
async def test_single_instance_allowed( | ||
hass: HomeAssistant, | ||
source: str, | ||
) -> None: | ||
"""Test we abort if already setup.""" | ||
mock_config_entry = MockConfigEntry(domain=DOMAIN) | ||
|
||
mock_config_entry.add_to_hass(hass) | ||
|
||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": source} | ||
) | ||
|
||
assert result["type"] == FlowResultType.ABORT | ||
assert result["reason"] == "single_instance_allowed" | ||
|
||
|
||
async def test_import_flow_success(hass: HomeAssistant) -> None: | ||
"""Test import flow.""" | ||
with patch( | ||
"homeassistant.components.fastdotcom.__init__.SpeedtestData", | ||
return_value={"download": "50"}, | ||
), patch("homeassistant.components.fastdotcom.sensor.SpeedtestSensor"): | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, | ||
context={"source": config_entries.SOURCE_IMPORT}, | ||
data={}, | ||
) | ||
await hass.async_block_till_done() | ||
|
||
assert result["type"] == FlowResultType.CREATE_ENTRY | ||
assert result["title"] == "Fast.com" | ||
assert result["data"] == {} | ||
assert result["options"] == {} |