Issue #280 - enable to use central config for window configuration
This commit is contained in:
@@ -171,7 +171,7 @@ class VersatileThermostatBaseConfigFlow(FlowHandler):
|
|||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Only one window detection method should be used. Use window_sensor or auto window open detection but not both"
|
"Only one window detection method should be used. Use window_sensor or auto window open detection but not both"
|
||||||
)
|
)
|
||||||
raise WindowOpenDetectionMethod(CONF_WINDOW_SENSOR)
|
raise WindowOpenDetectionMethod(CONF_WINDOW_AUTO_OPEN_THRESHOLD)
|
||||||
|
|
||||||
# Check that is USE_CENTRAL config is used, that a central config exists
|
# Check that is USE_CENTRAL config is used, that a central config exists
|
||||||
if self._central_config is None:
|
if self._central_config is None:
|
||||||
@@ -408,7 +408,11 @@ class VersatileThermostatBaseConfigFlow(FlowHandler):
|
|||||||
next_step = self.async_step_motion
|
next_step = self.async_step_motion
|
||||||
# If comes from async_step_spec_window
|
# If comes from async_step_spec_window
|
||||||
elif self._infos.get(COMES_FROM) == "async_step_spec_window":
|
elif self._infos.get(COMES_FROM) == "async_step_spec_window":
|
||||||
schema = STEP_CENTRAL_WINDOW_DATA_SCHEMA
|
# If we have a window sensor don't display the auto window parameters
|
||||||
|
if self._infos.get(CONF_WINDOW_SENSOR) is not None:
|
||||||
|
schema = STEP_CENTRAL_WINDOW_WO_AUTO_DATA_SCHEMA
|
||||||
|
else:
|
||||||
|
schema = STEP_CENTRAL_WINDOW_DATA_SCHEMA
|
||||||
elif user_input and user_input.get(CONF_USE_WINDOW_CENTRAL_CONFIG) is False:
|
elif user_input and user_input.get(CONF_USE_WINDOW_CENTRAL_CONFIG) is False:
|
||||||
next_step = self.async_step_spec_window
|
next_step = self.async_step_spec_window
|
||||||
|
|
||||||
@@ -423,6 +427,8 @@ class VersatileThermostatBaseConfigFlow(FlowHandler):
|
|||||||
)
|
)
|
||||||
|
|
||||||
schema = STEP_CENTRAL_WINDOW_DATA_SCHEMA
|
schema = STEP_CENTRAL_WINDOW_DATA_SCHEMA
|
||||||
|
if self._infos.get(CONF_WINDOW_SENSOR) is not None:
|
||||||
|
schema = STEP_CENTRAL_WINDOW_WO_AUTO_DATA_SCHEMA
|
||||||
|
|
||||||
self._infos[COMES_FROM] = "async_step_spec_window"
|
self._infos[COMES_FROM] = "async_step_spec_window"
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,12 @@ STEP_CENTRAL_WINDOW_DATA_SCHEMA = vol.Schema( # pylint: disable=invalid-name
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
STEP_CENTRAL_WINDOW_WO_AUTO_DATA_SCHEMA = vol.Schema( # pylint: disable=invalid-name
|
||||||
|
{
|
||||||
|
vol.Optional(CONF_WINDOW_DELAY, default=30): cv.positive_int,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
STEP_MOTION_DATA_SCHEMA = vol.Schema( # pylint: disable=invalid-name
|
STEP_MOTION_DATA_SCHEMA = vol.Schema( # pylint: disable=invalid-name
|
||||||
{
|
{
|
||||||
vol.Optional(CONF_MOTION_SENSOR): selector.EntitySelector(
|
vol.Optional(CONF_MOTION_SENSOR): selector.EntitySelector(
|
||||||
|
|||||||
@@ -139,6 +139,11 @@ MOCK_PRESETS_AC_CONFIG = {
|
|||||||
|
|
||||||
MOCK_WINDOW_CONFIG = {
|
MOCK_WINDOW_CONFIG = {
|
||||||
CONF_WINDOW_SENSOR: "binary_sensor.window_sensor",
|
CONF_WINDOW_SENSOR: "binary_sensor.window_sensor",
|
||||||
|
# Not used normally only for tests to avoid rewrite all tests
|
||||||
|
CONF_WINDOW_DELAY: 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
MOCK_WINDOW_DELAY_CONFIG = {
|
||||||
CONF_WINDOW_DELAY: 10,
|
CONF_WINDOW_DELAY: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ from .commons import * # pylint: disable=wildcard-import, unused-wildcard-impor
|
|||||||
from .const import * # pylint: disable=wildcard-import, unused-wildcard-import
|
from .const import * # pylint: disable=wildcard-import, unused-wildcard-import
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
|
@pytest.mark.parametrize("expected_lingering_timers", [True])
|
||||||
async def test_add_a_central_config(hass: HomeAssistant, skip_hass_states_is_state):
|
async def test_add_a_central_config(hass: HomeAssistant, skip_hass_states_is_state):
|
||||||
"""Tests the clean_central_config_doubon of base_thermostat"""
|
"""Tests the clean_central_config_doubon of base_thermostat"""
|
||||||
central_config_entry = MockConfigEntry(
|
central_config_entry = MockConfigEntry(
|
||||||
@@ -95,6 +97,8 @@ async def test_add_a_central_config(hass: HomeAssistant, skip_hass_states_is_sta
|
|||||||
assert central_configuration is not None
|
assert central_configuration is not None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
|
@pytest.mark.parametrize("expected_lingering_timers", [True])
|
||||||
async def test_minimal_over_switch_wo_central_config(
|
async def test_minimal_over_switch_wo_central_config(
|
||||||
hass: HomeAssistant, skip_hass_states_is_state, init_vtherm_api
|
hass: HomeAssistant, skip_hass_states_is_state, init_vtherm_api
|
||||||
):
|
):
|
||||||
@@ -169,6 +173,8 @@ async def test_minimal_over_switch_wo_central_config(
|
|||||||
assert entity.is_inversed
|
assert entity.is_inversed
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
|
@pytest.mark.parametrize("expected_lingering_timers", [True])
|
||||||
async def test_full_over_switch_wo_central_config(
|
async def test_full_over_switch_wo_central_config(
|
||||||
hass: HomeAssistant, skip_hass_states_is_state, init_vtherm_api
|
hass: HomeAssistant, skip_hass_states_is_state, init_vtherm_api
|
||||||
):
|
):
|
||||||
@@ -281,6 +287,8 @@ async def test_full_over_switch_wo_central_config(
|
|||||||
assert entity._presence_sensor_entity_id == "binary_sensor.mock_presence_sensor"
|
assert entity._presence_sensor_entity_id == "binary_sensor.mock_presence_sensor"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
|
@pytest.mark.parametrize("expected_lingering_timers", [True])
|
||||||
async def test_full_over_switch_with_central_config(
|
async def test_full_over_switch_with_central_config(
|
||||||
hass: HomeAssistant, skip_hass_states_is_state, init_central_config
|
hass: HomeAssistant, skip_hass_states_is_state, init_central_config
|
||||||
):
|
):
|
||||||
@@ -388,6 +396,8 @@ async def test_full_over_switch_with_central_config(
|
|||||||
assert entity._presence_sensor_entity_id == "binary_sensor.mock_presence_sensor"
|
assert entity._presence_sensor_entity_id == "binary_sensor.mock_presence_sensor"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
|
@pytest.mark.parametrize("expected_lingering_timers", [True])
|
||||||
async def test_over_switch_with_central_config_but_no_central_config(
|
async def test_over_switch_with_central_config_but_no_central_config(
|
||||||
hass: HomeAssistant, skip_hass_states_get, init_vtherm_api
|
hass: HomeAssistant, skip_hass_states_get, init_vtherm_api
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -472,15 +472,17 @@ async def test_user_config_flow_window_auto_ko(
|
|||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input=MOCK_WINDOW_AUTO_CONFIG,
|
user_input=MOCK_WINDOW_DELAY_CONFIG,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Since issue #280 we cannot have the error because we only display the
|
||||||
|
# MOCK_WINDOW_DELAY_CONFIG form if we have a sensor configured
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
# We should stay on window with an error
|
# We should stay on window with an error
|
||||||
assert result["errors"] == {
|
assert result["errors"] == {}
|
||||||
"window_sensor_entity_id": "window_open_detection_method"
|
# "window_sensor_entity_id": "window_open_detection_method"
|
||||||
}
|
# }
|
||||||
assert result["step_id"] == "window"
|
assert result["step_id"] == "advanced"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
|
|||||||
Reference in New Issue
Block a user