62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
"""Tests for the options flow and live settings updates."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.data_entry_flow import FlowResultType
|
|
|
|
from custom_components.main_gate_controller.const import (
|
|
ATTR_DURATION,
|
|
CONF_OPEN_DURATION,
|
|
CONF_PULSE_DURATION,
|
|
DOMAIN,
|
|
)
|
|
|
|
|
|
async def test_options_flow_updates_settings(
|
|
hass: HomeAssistant, loaded_entry
|
|
):
|
|
"""The options flow updates the open duration and the sensor reflects it."""
|
|
# Trigger an initial state refresh so the entity is registered.
|
|
loaded_entry.runtime_data.async_publish_update()
|
|
await hass.async_block_till_done()
|
|
|
|
result = await hass.config_entries.options.async_init(loaded_entry.entry_id)
|
|
assert result["type"] == FlowResultType.FORM
|
|
assert result["step_id"] == "init"
|
|
flow_id = result["flow_id"]
|
|
|
|
new_input = {
|
|
CONF_OPEN_DURATION: 5,
|
|
CONF_PULSE_DURATION: 0.5,
|
|
"notify_enabled": False,
|
|
"notify_entities": [],
|
|
"notify_opening_text": "Opening",
|
|
"notify_closing_text": "Closing",
|
|
}
|
|
result = await hass.config_entries.options.async_configure(flow_id, new_input)
|
|
await hass.async_block_till_done()
|
|
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
|
assert loaded_entry.options[CONF_OPEN_DURATION] == 5
|
|
assert loaded_entry.options[CONF_PULSE_DURATION] == 0.5
|
|
|
|
# Allow the update listener to push a refresh.
|
|
await asyncio.sleep(0)
|
|
await hass.async_block_till_done()
|
|
|
|
controller = loaded_entry.runtime_data
|
|
assert controller.open_duration == 5
|
|
assert controller.pulse_duration == 0.5
|
|
# The sensor attribute reflects the new duration as well.
|
|
from homeassistant.helpers import entity_registry as er
|
|
registry = er.async_get(hass)
|
|
sensor_id = registry.async_get_entity_id(
|
|
"sensor", DOMAIN, f"{loaded_entry.entry_id}_status"
|
|
)
|
|
assert sensor_id is not None
|
|
state = hass.states.get(sensor_id)
|
|
assert state.attributes[ATTR_DURATION] == 5
|