mirror of
https://github.com/home-assistant/core.git
synced 2026-10-07 06:50:41 -04:00
Remove user-configurable polling interval from hive (#184251)
This commit is contained in:
@@ -10,7 +10,6 @@ from apyhiveapi import Auth, Hive
|
||||
from apyhiveapi.helper.hive_exceptions import HiveReauthRequired
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_SCAN_INTERVAL
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client, device_registry as dr
|
||||
@@ -30,10 +29,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: HiveConfigEntry) -> bool
|
||||
hive_config = dict(entry.data)
|
||||
hive = Hive(web_session)
|
||||
|
||||
hive_config["options"] = {}
|
||||
hive_config["options"].update(
|
||||
{CONF_SCAN_INTERVAL: dict(entry.options).get(CONF_SCAN_INTERVAL, 120)}
|
||||
)
|
||||
entry.runtime_data = hive
|
||||
|
||||
try:
|
||||
|
||||
@@ -13,16 +13,9 @@ from apyhiveapi.helper.hive_exceptions import (
|
||||
)
|
||||
import probatio
|
||||
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_REAUTH,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
OptionsFlow,
|
||||
)
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
|
||||
from . import HiveConfigEntry
|
||||
from .const import CONF_CODE, CONF_DEVICE_NAME, CONFIG_ENTRY_VERSION, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -201,55 +194,6 @@ class HiveFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
_LOGGER.debug("Reauthenticating user")
|
||||
return await self.async_step_user(data)
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
@override
|
||||
def async_get_options_flow(
|
||||
config_entry: HiveConfigEntry,
|
||||
) -> HiveOptionsFlowHandler:
|
||||
"""Hive options callback."""
|
||||
return HiveOptionsFlowHandler(config_entry)
|
||||
|
||||
|
||||
class HiveOptionsFlowHandler(OptionsFlow):
|
||||
"""Config flow options for Hive."""
|
||||
|
||||
config_entry: HiveConfigEntry
|
||||
|
||||
def __init__(self, config_entry: HiveConfigEntry) -> None:
|
||||
"""Initialize Hive options flow."""
|
||||
self.hive = None
|
||||
self.interval = config_entry.options.get(CONF_SCAN_INTERVAL, 120)
|
||||
|
||||
async def async_step_init(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Manage the options."""
|
||||
return await self.async_step_user()
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle a flow initialized by the user."""
|
||||
self.hive = self.config_entry.runtime_data
|
||||
errors: dict[str, str] = {}
|
||||
if user_input is not None:
|
||||
new_interval = user_input.get(CONF_SCAN_INTERVAL)
|
||||
assert self.hive
|
||||
await self.hive.updateInterval(new_interval)
|
||||
return self.async_create_entry(title="", data=user_input)
|
||||
|
||||
schema = probatio.Schema(
|
||||
{
|
||||
# Polling interval is user-configurable, which is no longer allowed
|
||||
# pylint: disable-next=home-assistant-config-flow-polling-field
|
||||
probatio.Optional(
|
||||
CONF_SCAN_INTERVAL, default=self.interval
|
||||
): probatio.All(probatio.Coerce(int), probatio.Range(min=30))
|
||||
}
|
||||
)
|
||||
return self.async_show_form(step_id="user", data_schema=schema, errors=errors)
|
||||
|
||||
|
||||
class UnknownHiveError(Exception):
|
||||
"""Catch unknown hive error."""
|
||||
|
||||
@@ -64,17 +64,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"step": {
|
||||
"user": {
|
||||
"data": {
|
||||
"scan_interval": "Scan interval (seconds)"
|
||||
},
|
||||
"description": "Update the scan interval to poll for data more often.",
|
||||
"title": "Options for Hive"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"boost_heating_off": {
|
||||
"description": "Sets the boost mode OFF.",
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.hive.const import CONF_CODE, CONF_DEVICE_NAME, DOMAIN
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
@@ -18,8 +18,6 @@ UPDATED_USERNAME = "updated_username@home-assistant.com"
|
||||
PASSWORD = "test-password"
|
||||
UPDATED_PASSWORD = "updated-password"
|
||||
INCORRECT_PASSWORD = "incorrect-password"
|
||||
SCAN_INTERVAL = 120
|
||||
UPDATED_SCAN_INTERVAL = 60
|
||||
DEVICE_NAME = "Test Home Assistant"
|
||||
MFA_CODE = "1234"
|
||||
MFA_RESEND_CODE = "0000"
|
||||
@@ -582,43 +580,6 @@ async def test_reauth_2fa_flow_device_registration_check_fails(
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
|
||||
|
||||
async def test_option_flow(hass: HomeAssistant) -> None:
|
||||
"""Test config flow options."""
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title=USERNAME,
|
||||
data={
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
"device_data": [
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await hass.config_entries.options.async_init(
|
||||
entry.entry_id,
|
||||
data=None,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={CONF_SCAN_INTERVAL: UPDATED_SCAN_INTERVAL}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"][CONF_SCAN_INTERVAL] == UPDATED_SCAN_INTERVAL
|
||||
|
||||
|
||||
async def test_user_flow_2fa_send_new_code(hass: HomeAssistant) -> None:
|
||||
"""Resend a 2FA code if it didn't arrive."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@@ -733,7 +694,6 @@ async def test_abort_if_existing_entry(hass: HomeAssistant) -> None:
|
||||
domain=DOMAIN,
|
||||
unique_id=USERNAME,
|
||||
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
options={CONF_SCAN_INTERVAL: SCAN_INTERVAL},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user