Skip to content
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
4 changes: 1 addition & 3 deletions homeassistant/components/wemo/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%]"
}
},
Expand Down
23 changes: 3 additions & 20 deletions homeassistant/components/wemo/wemo_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@
_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):
Expand Down Expand Up @@ -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:
Expand All @@ -89,12 +82,6 @@ def __post_init__(self) -> None:
"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]):
Expand All @@ -108,6 +95,7 @@ def __init__(self, hass: HomeAssistant, wemo: WeMoDevice, device_id: str) -> Non
hass,
_LOGGER,
name=wemo.name,
update_interval=timedelta(seconds=30),
)
self.hass = hass
self.wemo = wemo
Expand Down Expand Up @@ -164,11 +152,6 @@ async def _async_set_enable_long_press(self, enable_long_press: bool) -> 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:
Expand Down
6 changes: 0 additions & 6 deletions tests/components/wemo/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
31 changes: 0 additions & 31 deletions tests/components/wemo/test_wemo_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down