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

Add Option to Configure Scan Interval to vesync #127152

Closed
wants to merge 1 commit into from
Closed
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
45 changes: 42 additions & 3 deletions homeassistant/components/vesync/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
from pyvesync import VeSync
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
OptionsFlow,
)
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv

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

DATA_SCHEMA = vol.Schema(
{
Expand All @@ -20,11 +25,45 @@
)


class VesyncOptionFlowHandler(OptionsFlow):
"""Handle an option flow for Vesync."""

def __init__(self, config_entry: ConfigEntry) -> None:
"""Initialize option flow instance."""
self.config_entry = config_entry

Check warning on line 33 in homeassistant/components/vesync/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/vesync/config_flow.py#L33

Added line #L33 was not covered by tests

async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Manage the vesync options."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)

Check warning on line 40 in homeassistant/components/vesync/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/vesync/config_flow.py#L39-L40

Added lines #L39 - L40 were not covered by tests

options = {

Check warning on line 42 in homeassistant/components/vesync/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/vesync/config_flow.py#L42

Added line #L42 was not covered by tests
vol.Optional(
CONF_SCAN_INTERVAL,
default=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
),
): int,
Comment on lines +43 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not allow configuration of the scan interval.

We should provide a sane default out of the box. In case the default isn't correct, we should adjust that.

If an user wants to use a different schedule or a conditional scan interval, they can use the homeassistant.update_entity service instead.

}

return self.async_show_form(step_id="init", data_schema=vol.Schema(options))

Check warning on line 51 in homeassistant/components/vesync/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/vesync/config_flow.py#L51

Added line #L51 was not covered by tests


class VeSyncFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle a config flow."""

VERSION = 1

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

Check warning on line 65 in homeassistant/components/vesync/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/vesync/config_flow.py#L65

Added line #L65 was not covered by tests

@callback
def _show_form(self, errors: dict[str, str] | None = None) -> ConfigFlowResult:
"""Show form to the user."""
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/vesync/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@
"LAP-EL551S-WEU": "EverestAir", # Alt ID Model EverestAir
"LAP-EL551S-WUS": "EverestAir", # Alt ID Model EverestAir
}

DEFAULT_SCAN_INTERVAL: int = 15
9 changes: 9 additions & 0 deletions homeassistant/components/vesync/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
}
},
"options": {
"step": {
"init": {
"data": {
"scan_interval": "Update interval"
}
}
}
},
"entity": {
"sensor": {
"filter_life": {
Expand Down