Created
July 18, 2020 19:49
-
-
Save CoMPaTech/8f6e20e78ae53ac50b53d60bb589ed31 to your computer and use it in GitHub Desktop.
not working testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tests/components/plugwise/test_config_flow.py b/tests/components/plugwise/test_config_flow.py | |
index feb695aae8..22a6fc6079 100644 | |
--- a/tests/components/plugwise/test_config_flow.py | |
+++ b/tests/components/plugwise/test_config_flow.py | |
@@ -2,10 +2,19 @@ | |
from Plugwise_Smile.Smile import Smile | |
import pytest | |
-from homeassistant import config_entries, setup | |
-from homeassistant.components.plugwise.const import DOMAIN | |
+from homeassistant import config_entries, data_entry_flow, setup | |
+from homeassistant.components.plugwise import config_flow | |
+from homeassistant.components.plugwise.const import DOMAIN, DEFAULT_SCAN_INTERVAL | |
+from homeassistant.config_entries import SOURCE_ZEROCONF | |
+from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_SCAN_INTERVAL | |
+from homeassistant.helpers.typing import HomeAssistantType | |
from tests.async_mock import patch | |
+from tests.common import MockConfigEntry | |
+ | |
+TEST_HOST = "1.1.1.1" | |
+TEST_HOSTNAME = "smileabcdef" | |
+TEST_PASSWORD = "test_password" | |
@pytest.fixture(name="mock_smile") | |
@@ -37,13 +46,13 @@ async def test_form(hass): | |
"homeassistant.components.plugwise.async_setup_entry", return_value=True, | |
) as mock_setup_entry: | |
result2 = await hass.config_entries.flow.async_configure( | |
- result["flow_id"], {"host": "1.1.1.1", "password": "test-password"}, | |
+ result["flow_id"], {"host": TEST_HOST, "password": TEST_PASSWORD}, | |
) | |
assert result2["type"] == "create_entry" | |
assert result2["data"] == { | |
- "host": "1.1.1.1", | |
- "password": "test-password", | |
+ "host": TEST_HOST, | |
+ "password": TEST_PASSWORD, | |
} | |
await hass.async_block_till_done() | |
assert len(mock_setup.mock_calls) == 1 | |
@@ -60,7 +69,7 @@ async def test_form_invalid_auth(hass, mock_smile): | |
mock_smile.gateway_id = "0a636a4fc1704ab4a24e4f7e37fb187a" | |
result2 = await hass.config_entries.flow.async_configure( | |
- result["flow_id"], {"host": "1.1.1.1", "password": "test-password"}, | |
+ result["flow_id"], {"host": TEST_HOST, "password": TEST_PASSWORD}, | |
) | |
assert result2["type"] == "form" | |
assert result2["errors"] == {"base": "cannot_connect"} | |
+ | |
+ | |
+async def test_show_zerconf_form(hass , mock_smile) -> None: | |
+ """Test that the zeroconf confirmation form is served.""" | |
+ | |
+ flow = config_flow.PlugwiseConfigFlow() | |
+ flow.hass = hass | |
+ flow.context = {"source": SOURCE_ZEROCONF} | |
+ result = await flow.async_step_zeroconf( | |
+ {"host": TEST_HOST, "hostname": f"{TEST_HOSTNAME}.local.", "server": f"{TEST_HOSTNAME}.local.", "properties": { "product": "smile", "version": "1.2.3"}} | |
+ ) | |
+ | |
+ assert flow.context["title_placeholders"][CONF_HOST] == TEST_HOST | |
+ assert flow.context["title_placeholders"]["name"] == "P1 DSMR v1.2.3" | |
+ assert result["step_id"] == "user" | |
+ assert result["type"] == data_entry_flow.RESULT_TYPE_FORM | |
+ | |
+ | |
+async def test_options_flow(hass: HomeAssistantType, mock_smile): | |
+ """Test config flow options.""" | |
+ config_entry = MockConfigEntry( | |
+ domain=DOMAIN, | |
+ data={ | |
+ CONF_HOST: TEST_HOST, | |
+ CONF_NAME: TEST_HOSTNAME, | |
+ CONF_PASSWORD: TEST_PASSWORD, | |
+ }, | |
+ unique_id=TEST_HOSTNAME, | |
+ ) | |
+ config_entry.add_to_hass(hass) | |
+ | |
+ print("config: %s", config_entry) | |
+ assert config_entry.options == {} | |
+ | |
+ 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" | |
+ | |
+ # Scan interval | |
+ # Default | |
+ result = await hass.config_entries.options.async_configure( | |
+ result["flow_id"], user_input={}, | |
+ ) | |
+ assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY | |
+ assert config_entry.options[CONF_SCAN_INTERVAL] == DEFAULT_SCAN_INTERVAL | |
+ | |
+ # Manual | |
+ result = await hass.config_entries.options.async_init(config_entry.entry_id) | |
+ result = await hass.config_entries.options.async_configure( | |
+ result["flow_id"], user_input={CONF_SCAN_INTERVAL: 2}, | |
+ ) | |
+ assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY | |
+ assert config_entry.options[CONF_SCAN_INTERVAL] == 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment