Remove polling_interval_seconds option from wemo (#95468)
This commit is contained in:
parent
804b27cc2f
commit
03dac6e171
4 changed files with 4 additions and 60 deletions
|
@ -15,14 +15,12 @@
|
|||
"init": {
|
||||
"data": {
|
||||
"enable_subscription": "Subscribe to device local push updates",
|
||||
"enable_long_press": "Register for device long-press events",
|
||||
"polling_interval_seconds": "Seconds to wait between polling the device"
|
||||
"enable_long_press": "Register for device long-press events"
|
||||
}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"long_press_requires_subscription": "Local push update subscriptions must be enabled to use long-press events",
|
||||
"polling_interval_to_small": "Polling more frequently than 10 seconds is not supported",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -34,13 +34,9 @@ from .const import DOMAIN, WEMO_SUBSCRIPTION_EVENT
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Literal values must match options.error keys from strings.json.
|
||||
ErrorStringKey = Literal[
|
||||
"long_press_requires_subscription", "polling_interval_to_small"
|
||||
]
|
||||
ErrorStringKey = Literal["long_press_requires_subscription"]
|
||||
# Literal values must match options.step.init.data keys from strings.json.
|
||||
OptionsFieldKey = Literal[
|
||||
"enable_subscription", "enable_long_press", "polling_interval_seconds"
|
||||
]
|
||||
OptionsFieldKey = Literal["enable_subscription", "enable_long_press"]
|
||||
|
||||
|
||||
class OptionsValidationError(Exception):
|
||||
|
@ -78,9 +74,6 @@ class Options:
|
|||
# Register for device long-press events.
|
||||
enable_long_press: bool = True
|
||||
|
||||
# Polling interval for when subscriptions are not enabled or broken.
|
||||
polling_interval_seconds: int = 30
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""Validate parameters."""
|
||||
if not self.enable_subscription and self.enable_long_press:
|
||||
|
@ -89,12 +82,6 @@ class Options:
|
|||
"long_press_requires_subscription",
|
||||
"Local push update subscriptions must be enabled to use long-press events",
|
||||
)
|
||||
if self.polling_interval_seconds < 10:
|
||||
raise OptionsValidationError(
|
||||
"polling_interval_seconds",
|
||||
"polling_interval_to_small",
|
||||
"Polling more frequently than 10 seconds is not supported",
|
||||
)
|
||||
|
||||
|
||||
class DeviceCoordinator(DataUpdateCoordinator[None]):
|
||||
|
@ -108,6 +95,7 @@ class DeviceCoordinator(DataUpdateCoordinator[None]):
|
|||
hass,
|
||||
_LOGGER,
|
||||
name=wemo.name,
|
||||
update_interval=timedelta(seconds=30),
|
||||
)
|
||||
self.hass = hass
|
||||
self.wemo = wemo
|
||||
|
@ -164,11 +152,6 @@ class DeviceCoordinator(DataUpdateCoordinator[None]):
|
|||
)
|
||||
self.supports_long_press = False
|
||||
|
||||
async def _async_set_polling_interval_seconds(
|
||||
self, polling_interval_seconds: int
|
||||
) -> None:
|
||||
self.update_interval = timedelta(seconds=polling_interval_seconds)
|
||||
|
||||
async def async_set_options(
|
||||
self, hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> None:
|
||||
|
|
|
@ -61,9 +61,3 @@ async def test_invalid_options(hass: HomeAssistant) -> None:
|
|||
assert result["errors"] == {
|
||||
"enable_subscription": "long_press_requires_subscription"
|
||||
}
|
||||
|
||||
# polling_interval_seconds must be larger than 10.
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={"polling_interval_seconds": 1}
|
||||
)
|
||||
assert result["errors"] == {"polling_interval_seconds": "polling_interval_to_small"}
|
||||
|
|
|
@ -214,37 +214,6 @@ async def test_options_enable_long_press_false(hass, pywemo_device, wemo_entity)
|
|||
pywemo_device.remove_long_press_virtual_device.assert_called_once_with()
|
||||
|
||||
|
||||
async def test_options_polling_interval_seconds(hass, pywemo_device, wemo_entity):
|
||||
"""Test setting Options.polling_interval_seconds = 45."""
|
||||
config_entry = hass.config_entries.async_get_entry(wemo_entity.config_entry_id)
|
||||
assert hass.config_entries.async_update_entry(
|
||||
config_entry,
|
||||
options=asdict(
|
||||
wemo_device.Options(
|
||||
enable_subscription=False,
|
||||
enable_long_press=False,
|
||||
polling_interval_seconds=45,
|
||||
)
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Move time forward to capture the new interval.
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=31))
|
||||
await hass.async_block_till_done()
|
||||
pywemo_device.get_state.reset_mock()
|
||||
|
||||
# Make sure no polling occurs before 45 seconds.
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=31))
|
||||
await hass.async_block_till_done()
|
||||
pywemo_device.get_state.assert_not_called()
|
||||
|
||||
# Polling occurred after the interval.
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=46))
|
||||
await hass.async_block_till_done()
|
||||
pywemo_device.get_state.assert_has_calls([call(True), call()])
|
||||
|
||||
|
||||
class TestInsight:
|
||||
"""Tests specific to the WeMo Insight device."""
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue