Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused option flow from blink #106735

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions homeassistant/components/blink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN][entry.entry_id] = coordinator

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(update_listener))

return True

Expand All @@ -129,9 +128,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok


async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update."""
blink: Blink = hass.data[DOMAIN][entry.entry_id].api
blink.refresh_rate = entry.options[CONF_SCAN_INTERVAL]
43 changes: 3 additions & 40 deletions homeassistant/components/blink/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,17 @@
from blinkpy.blinkpy import Blink, BlinkSetupError
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import (
CONF_PASSWORD,
CONF_PIN,
CONF_SCAN_INTERVAL,
CONF_USERNAME,
)
from homeassistant.config_entries import ConfigFlow
from homeassistant.const import CONF_PASSWORD, CONF_PIN, CONF_USERNAME
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import selector
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.schema_config_entry_flow import (
SchemaFlowFormStep,
SchemaOptionsFlowHandler,
)

from .const import DEFAULT_SCAN_INTERVAL, DEVICE_ID, DOMAIN
from .const import DEVICE_ID, DOMAIN

_LOGGER = logging.getLogger(__name__)

SIMPLE_OPTIONS_SCHEMA = vol.Schema(
{
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
mkmer marked this conversation as resolved.
Show resolved Hide resolved
): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
unit_of_measurement="seconds",
),
),
}
)


OPTIONS_FLOW = {
"init": SchemaFlowFormStep(next_step="simple_options"),
"simple_options": SchemaFlowFormStep(SIMPLE_OPTIONS_SCHEMA),
}


async def validate_input(auth: Auth) -> None:
"""Validate the user input allows us to connect."""
Expand Down Expand Up @@ -78,14 +49,6 @@ def __init__(self) -> None:
"""Initialize the blink flow."""
self.auth: Auth | None = None

@staticmethod
@callback
def async_get_options_flow(
config_entry: ConfigEntry,
) -> SchemaOptionsFlowHandler:
"""Get options flow for this handler."""
return SchemaOptionsFlowHandler(config_entry, OPTIONS_FLOW)

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
Expand Down
47 changes: 1 addition & 46 deletions tests/components/blink/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Test the Blink config flow."""
from unittest.mock import AsyncMock, Mock, patch
from unittest.mock import patch

from blinkpy.auth import LoginError
from blinkpy.blinkpy import BlinkSetupError
Expand All @@ -8,8 +8,6 @@
from homeassistant.components.blink import DOMAIN
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry


async def test_form(hass: HomeAssistant) -> None:
"""Test we get the form."""
Expand Down Expand Up @@ -258,46 +256,3 @@ async def test_reauth_shows_user_step(hass: HomeAssistant) -> None:
)
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["step_id"] == "user"


async def test_options_flow(hass: HomeAssistant) -> None:
"""Test config flow options."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data={"username": "blink@example.com", "password": "example"},
options={},
entry_id=1,
version=3,
)
config_entry.add_to_hass(hass)

mock_auth = AsyncMock(
startup=Mock(return_value=True), check_key_required=Mock(return_value=False)
)
mock_blink = AsyncMock(cameras=Mock(), sync=Mock())

with patch("homeassistant.components.blink.Auth", return_value=mock_auth), patch(
"homeassistant.components.blink.Blink", return_value=mock_blink
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

result = await hass.config_entries.options.async_init(
config_entry.entry_id, context={"show_advanced_options": False}
)

assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["step_id"] == "simple_options"

with patch("homeassistant.components.blink.Auth", return_value=mock_auth), patch(
"homeassistant.components.blink.Blink", return_value=mock_blink
):
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={"scan_interval": 5},
)
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["data"] == {"scan_interval": 5}
await hass.async_block_till_done()

assert mock_blink.refresh_rate == 5
Loading