mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add option to reverse switch behaviour in KMTronic (#47532)
This commit is contained in:
@@ -3,9 +3,9 @@ from unittest.mock import Mock, patch
|
||||
|
||||
from aiohttp import ClientConnectorError, ClientResponseError
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.kmtronic.const import DOMAIN
|
||||
from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED
|
||||
from homeassistant import config_entries, data_entry_flow, setup
|
||||
from homeassistant.components.kmtronic.const import CONF_REVERSE, DOMAIN
|
||||
from homeassistant.config_entries import ENTRY_STATE_LOADED
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -49,6 +49,43 @@ async def test_form(hass):
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_options(hass, aioclient_mock):
|
||||
"""Test that the options form."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
"host": "1.1.1.1",
|
||||
"username": "admin",
|
||||
"password": "admin",
|
||||
},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1/status.xml",
|
||||
text="<response><relay0>0</relay0><relay1>0</relay1></response>",
|
||||
)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state == ENTRY_STATE_LOADED
|
||||
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={CONF_REVERSE: True}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert config_entry.options == {CONF_REVERSE: True}
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state == "loaded"
|
||||
|
||||
|
||||
async def test_form_invalid_auth(hass):
|
||||
"""Test we handle invalid auth."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@@ -116,30 +153,3 @@ async def test_form_unknown_error(hass):
|
||||
|
||||
assert result2["type"] == "form"
|
||||
assert result2["errors"] == {"base": "unknown"}
|
||||
|
||||
|
||||
async def test_unload_config_entry(hass, aioclient_mock):
|
||||
"""Test entry unloading."""
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={"host": "1.1.1.1", "username": "admin", "password": "admin"},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1/status.xml",
|
||||
text="<response><relay0>0</relay0><relay1>0</relay1></response>",
|
||||
)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
config_entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(config_entries) == 1
|
||||
assert config_entries[0] is config_entry
|
||||
assert config_entry.state == ENTRY_STATE_LOADED
|
||||
|
||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state == ENTRY_STATE_NOT_LOADED
|
||||
|
||||
Reference in New Issue
Block a user