parent
9d79c4f617
commit
669883d416
|
@ -19,10 +19,41 @@ from homeassistant.core import callback
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||||
|
|
||||||
from .const import DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DOMAIN, ZEROCONF_MAP
|
from .const import (
|
||||||
|
API,
|
||||||
|
DEFAULT_PORT,
|
||||||
|
DEFAULT_SCAN_INTERVAL,
|
||||||
|
DEFAULT_USERNAME,
|
||||||
|
DOMAIN,
|
||||||
|
FLOW_NET,
|
||||||
|
FLOW_SMILE,
|
||||||
|
FLOW_STRETCH,
|
||||||
|
FLOW_TYPE,
|
||||||
|
FLOW_USB,
|
||||||
|
PW_TYPE,
|
||||||
|
SMILE,
|
||||||
|
STRETCH,
|
||||||
|
STRETCH_USERNAME,
|
||||||
|
ZEROCONF_MAP,
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONF_MANUAL_PATH = "Enter Manually"
|
||||||
|
|
||||||
|
CONNECTION_SCHEMA = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required(FLOW_TYPE, default=FLOW_NET): vol.In(
|
||||||
|
{
|
||||||
|
FLOW_NET: f"Network: {SMILE} / {STRETCH}",
|
||||||
|
FLOW_USB: "USB: To be added later",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
# PLACEHOLDER USB connection validation
|
||||||
|
|
||||||
|
|
||||||
def _base_gw_schema(discovery_info):
|
def _base_gw_schema(discovery_info):
|
||||||
"""Generate base schema for gateways."""
|
"""Generate base schema for gateways."""
|
||||||
|
@ -31,22 +62,18 @@ def _base_gw_schema(discovery_info):
|
||||||
if not discovery_info:
|
if not discovery_info:
|
||||||
base_gw_schema[vol.Required(CONF_HOST)] = str
|
base_gw_schema[vol.Required(CONF_HOST)] = str
|
||||||
base_gw_schema[vol.Optional(CONF_PORT, default=DEFAULT_PORT)] = int
|
base_gw_schema[vol.Optional(CONF_PORT, default=DEFAULT_PORT)] = int
|
||||||
|
base_gw_schema[vol.Required(CONF_USERNAME, default=SMILE)] = vol.In(
|
||||||
|
{SMILE: FLOW_SMILE, STRETCH: FLOW_STRETCH}
|
||||||
|
)
|
||||||
|
|
||||||
base_gw_schema.update(
|
base_gw_schema.update({vol.Required(CONF_PASSWORD): str})
|
||||||
{
|
|
||||||
vol.Required(
|
|
||||||
CONF_USERNAME, default="smile", description={"suggested_value": "smile"}
|
|
||||||
): str,
|
|
||||||
vol.Required(CONF_PASSWORD): str,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return vol.Schema(base_gw_schema)
|
return vol.Schema(base_gw_schema)
|
||||||
|
|
||||||
|
|
||||||
async def validate_gw_input(hass: core.HomeAssistant, data):
|
async def validate_gw_input(hass: core.HomeAssistant, data):
|
||||||
"""
|
"""
|
||||||
Validate whether the user input allows us to connect to the gateray.
|
Validate whether the user input allows us to connect to the gateway.
|
||||||
|
|
||||||
Data has the keys from _base_gw_schema() with values provided by the user.
|
Data has the keys from _base_gw_schema() with values provided by the user.
|
||||||
"""
|
"""
|
||||||
|
@ -71,9 +98,6 @@ async def validate_gw_input(hass: core.HomeAssistant, data):
|
||||||
return api
|
return api
|
||||||
|
|
||||||
|
|
||||||
# PLACEHOLDER USB connection validation
|
|
||||||
|
|
||||||
|
|
||||||
class PlugwiseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class PlugwiseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for Plugwise Smile."""
|
"""Handle a config flow for Plugwise Smile."""
|
||||||
|
|
||||||
|
@ -86,32 +110,43 @@ class PlugwiseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType):
|
async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType):
|
||||||
"""Prepare configuration for a discovered Plugwise Smile."""
|
"""Prepare configuration for a discovered Plugwise Smile."""
|
||||||
self.discovery_info = discovery_info
|
self.discovery_info = discovery_info
|
||||||
|
self.discovery_info[CONF_USERNAME] = DEFAULT_USERNAME
|
||||||
_properties = self.discovery_info.get("properties")
|
_properties = self.discovery_info.get("properties")
|
||||||
|
|
||||||
|
# unique_id is needed here, to be able to determine whether the discovered device is known, or not.
|
||||||
unique_id = self.discovery_info.get("hostname").split(".")[0]
|
unique_id = self.discovery_info.get("hostname").split(".")[0]
|
||||||
await self.async_set_unique_id(unique_id)
|
await self.async_set_unique_id(unique_id)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
|
if DEFAULT_USERNAME not in unique_id:
|
||||||
|
self.discovery_info[CONF_USERNAME] = STRETCH_USERNAME
|
||||||
_product = _properties.get("product", None)
|
_product = _properties.get("product", None)
|
||||||
_version = _properties.get("version", "n/a")
|
_version = _properties.get("version", "n/a")
|
||||||
_name = f"{ZEROCONF_MAP.get(_product, _product)} v{_version}"
|
_name = f"{ZEROCONF_MAP.get(_product, _product)} v{_version}"
|
||||||
|
|
||||||
|
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
|
||||||
self.context["title_placeholders"] = {
|
self.context["title_placeholders"] = {
|
||||||
CONF_HOST: discovery_info[CONF_HOST],
|
CONF_HOST: self.discovery_info[CONF_HOST],
|
||||||
CONF_PORT: discovery_info.get(CONF_PORT, DEFAULT_PORT),
|
|
||||||
CONF_NAME: _name,
|
CONF_NAME: _name,
|
||||||
|
CONF_PORT: self.discovery_info[CONF_PORT],
|
||||||
|
CONF_USERNAME: self.discovery_info[CONF_USERNAME],
|
||||||
}
|
}
|
||||||
return await self.async_step_user()
|
return await self.async_step_user_gateway()
|
||||||
|
|
||||||
|
# PLACEHOLDER USB step_user
|
||||||
|
|
||||||
async def async_step_user_gateway(self, user_input=None):
|
async def async_step_user_gateway(self, user_input=None):
|
||||||
"""Handle the initial step for gateways."""
|
"""Handle the initial step when using network/gateway setups."""
|
||||||
|
api = None
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
|
user_input.pop(FLOW_TYPE, None)
|
||||||
|
|
||||||
if self.discovery_info:
|
if self.discovery_info:
|
||||||
user_input[CONF_HOST] = self.discovery_info[CONF_HOST]
|
user_input[CONF_HOST] = self.discovery_info[CONF_HOST]
|
||||||
user_input[CONF_PORT] = self.discovery_info.get(CONF_PORT, DEFAULT_PORT)
|
user_input[CONF_PORT] = self.discovery_info[CONF_PORT]
|
||||||
|
user_input[CONF_USERNAME] = self.discovery_info[CONF_USERNAME]
|
||||||
|
|
||||||
self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]})
|
self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]})
|
||||||
|
|
||||||
|
@ -125,26 +160,36 @@ class PlugwiseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors[CONF_BASE] = "unknown"
|
errors[CONF_BASE] = "unknown"
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
await self.async_set_unique_id(
|
await self.async_set_unique_id(
|
||||||
api.smile_hostname or api.gateway_id, raise_on_progress=False
|
api.smile_hostname or api.gateway_id, raise_on_progress=False
|
||||||
)
|
)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
|
user_input[PW_TYPE] = API
|
||||||
return self.async_create_entry(title=api.smile_name, data=user_input)
|
return self.async_create_entry(title=api.smile_name, data=user_input)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user_gateway",
|
step_id="user_gateway",
|
||||||
data_schema=_base_gw_schema(self.discovery_info),
|
data_schema=_base_gw_schema(self.discovery_info),
|
||||||
errors=errors or {},
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
# PLACEHOLDER USB async_step_user_usb and async_step_user_usb_manual_paht
|
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step when using network/gateway setups."""
|
||||||
# PLACEHOLDER USB vs Gateway Logic
|
errors = {}
|
||||||
return await self.async_step_user_gateway()
|
if user_input is not None:
|
||||||
|
if user_input[FLOW_TYPE] == FLOW_NET:
|
||||||
|
return await self.async_step_user_gateway()
|
||||||
|
|
||||||
|
# PLACEHOLDER for USB_FLOW
|
||||||
|
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="user",
|
||||||
|
data_schema=CONNECTION_SCHEMA,
|
||||||
|
errors=errors,
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
|
@ -165,8 +210,9 @@ class PlugwiseOptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(title="", data=user_input)
|
return self.async_create_entry(title="", data=user_input)
|
||||||
|
|
||||||
api = self.hass.data[DOMAIN][self.config_entry.entry_id]["api"]
|
api = self.hass.data[DOMAIN][self.config_entry.entry_id][API]
|
||||||
interval = DEFAULT_SCAN_INTERVAL[api.smile_type]
|
interval = DEFAULT_SCAN_INTERVAL[api.smile_type]
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
|
|
|
@ -1,10 +1,33 @@
|
||||||
"""Constant for Plugwise component."""
|
"""Constants for Plugwise component."""
|
||||||
DOMAIN = "plugwise"
|
|
||||||
|
|
||||||
SENSOR_PLATFORMS = ["sensor", "switch"]
|
API = "api"
|
||||||
PLATFORMS_GATEWAY = ["binary_sensor", "climate", "sensor", "switch"]
|
ATTR_ILLUMINANCE = "illuminance"
|
||||||
PW_TYPE = "plugwise_type"
|
COORDINATOR = "coordinator"
|
||||||
|
DEVICE_STATE = "device_state"
|
||||||
|
DOMAIN = "plugwise"
|
||||||
|
FLOW_NET = "flow_network"
|
||||||
|
FLOW_SMILE = "smile (Adam/Anna/P1)"
|
||||||
|
FLOW_STRETCH = "stretch (Stretch)"
|
||||||
|
FLOW_TYPE = "flow_type"
|
||||||
|
FLOW_USB = "flow_usb"
|
||||||
GATEWAY = "gateway"
|
GATEWAY = "gateway"
|
||||||
|
PW_TYPE = "plugwise_type"
|
||||||
|
SCHEDULE_OFF = "false"
|
||||||
|
SCHEDULE_ON = "true"
|
||||||
|
SMILE = "smile"
|
||||||
|
STRETCH = "stretch"
|
||||||
|
STRETCH_USERNAME = "stretch"
|
||||||
|
UNDO_UPDATE_LISTENER = "undo_update_listener"
|
||||||
|
UNIT_LUMEN = "lm"
|
||||||
|
|
||||||
|
PLATFORMS_GATEWAY = ["binary_sensor", "climate", "sensor", "switch"]
|
||||||
|
SENSOR_PLATFORMS = ["sensor", "switch"]
|
||||||
|
ZEROCONF_MAP = {
|
||||||
|
"smile": "P1",
|
||||||
|
"smile_thermo": "Anna",
|
||||||
|
"smile_open_therm": "Adam",
|
||||||
|
"stretch": "Stretch",
|
||||||
|
}
|
||||||
|
|
||||||
# Sensor mapping
|
# Sensor mapping
|
||||||
SENSOR_MAP_DEVICE_CLASS = 2
|
SENSOR_MAP_DEVICE_CLASS = 2
|
||||||
|
@ -13,13 +36,17 @@ SENSOR_MAP_MODEL = 0
|
||||||
SENSOR_MAP_UOM = 1
|
SENSOR_MAP_UOM = 1
|
||||||
|
|
||||||
# Default directives
|
# Default directives
|
||||||
DEFAULT_MIN_TEMP = 4
|
|
||||||
DEFAULT_MAX_TEMP = 30
|
DEFAULT_MAX_TEMP = 30
|
||||||
|
DEFAULT_MIN_TEMP = 4
|
||||||
DEFAULT_NAME = "Smile"
|
DEFAULT_NAME = "Smile"
|
||||||
DEFAULT_PORT = 80
|
DEFAULT_PORT = 80
|
||||||
DEFAULT_USERNAME = "smile"
|
DEFAULT_SCAN_INTERVAL = {
|
||||||
DEFAULT_SCAN_INTERVAL = {"power": 10, "stretch": 60, "thermostat": 60}
|
"power": 10,
|
||||||
|
"stretch": 60,
|
||||||
|
"thermostat": 60,
|
||||||
|
}
|
||||||
DEFAULT_TIMEOUT = 60
|
DEFAULT_TIMEOUT = 60
|
||||||
|
DEFAULT_USERNAME = "smile"
|
||||||
|
|
||||||
# Configuration directives
|
# Configuration directives
|
||||||
CONF_GAS = "gas"
|
CONF_GAS = "gas"
|
||||||
|
@ -28,15 +55,7 @@ CONF_MIN_TEMP = "min_temp"
|
||||||
CONF_POWER = "power"
|
CONF_POWER = "power"
|
||||||
CONF_THERMOSTAT = "thermostat"
|
CONF_THERMOSTAT = "thermostat"
|
||||||
|
|
||||||
ATTR_ILLUMINANCE = "illuminance"
|
# Icons
|
||||||
|
|
||||||
UNIT_LUMEN = "lm"
|
|
||||||
|
|
||||||
DEVICE_STATE = "device_state"
|
|
||||||
|
|
||||||
SCHEDULE_OFF = "false"
|
|
||||||
SCHEDULE_ON = "true"
|
|
||||||
|
|
||||||
COOL_ICON = "mdi:snowflake"
|
COOL_ICON = "mdi:snowflake"
|
||||||
FLAME_ICON = "mdi:fire"
|
FLAME_ICON = "mdi:fire"
|
||||||
FLOW_OFF_ICON = "mdi:water-pump-off"
|
FLOW_OFF_ICON = "mdi:water-pump-off"
|
||||||
|
@ -45,12 +64,3 @@ IDLE_ICON = "mdi:circle-off-outline"
|
||||||
SWITCH_ICON = "mdi:electric-switch"
|
SWITCH_ICON = "mdi:electric-switch"
|
||||||
NO_NOTIFICATION_ICON = "mdi:mailbox-outline"
|
NO_NOTIFICATION_ICON = "mdi:mailbox-outline"
|
||||||
NOTIFICATION_ICON = "mdi:mailbox-up-outline"
|
NOTIFICATION_ICON = "mdi:mailbox-up-outline"
|
||||||
|
|
||||||
COORDINATOR = "coordinator"
|
|
||||||
UNDO_UPDATE_LISTENER = "undo_update_listener"
|
|
||||||
ZEROCONF_MAP = {
|
|
||||||
"smile": "P1",
|
|
||||||
"smile_thermo": "Anna",
|
|
||||||
"smile_open_therm": "Adam",
|
|
||||||
"stretch": "Stretch",
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""Test the Plugwise config flow."""
|
"""Test the Plugwise config flow."""
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
from plugwise.exceptions import (
|
from plugwise.exceptions import (
|
||||||
ConnectionFailedError,
|
ConnectionFailedError,
|
||||||
|
@ -8,11 +8,15 @@ from plugwise.exceptions import (
|
||||||
)
|
)
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow, setup
|
from homeassistant import setup
|
||||||
from homeassistant.components.plugwise.const import (
|
from homeassistant.components.plugwise.const import (
|
||||||
|
API,
|
||||||
DEFAULT_PORT,
|
DEFAULT_PORT,
|
||||||
DEFAULT_SCAN_INTERVAL,
|
DEFAULT_SCAN_INTERVAL,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
FLOW_NET,
|
||||||
|
FLOW_TYPE,
|
||||||
|
PW_TYPE,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -21,13 +25,16 @@ from homeassistant.const import (
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
|
CONF_SOURCE,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
|
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
TEST_HOST = "1.1.1.1"
|
TEST_HOST = "1.1.1.1"
|
||||||
TEST_HOSTNAME = "smileabcdef"
|
TEST_HOSTNAME = "smileabcdef"
|
||||||
|
TEST_HOSTNAME2 = "stretchabc"
|
||||||
TEST_PASSWORD = "test_password"
|
TEST_PASSWORD = "test_password"
|
||||||
TEST_PORT = 81
|
TEST_PORT = 81
|
||||||
TEST_USERNAME = "smile"
|
TEST_USERNAME = "smile"
|
||||||
|
@ -44,6 +51,17 @@ TEST_DISCOVERY = {
|
||||||
"hostname": f"{TEST_HOSTNAME}.local.",
|
"hostname": f"{TEST_HOSTNAME}.local.",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
TEST_DISCOVERY2 = {
|
||||||
|
"host": TEST_HOST,
|
||||||
|
"port": DEFAULT_PORT,
|
||||||
|
"hostname": f"{TEST_HOSTNAME2}.local.",
|
||||||
|
"server": f"{TEST_HOSTNAME2}.local.",
|
||||||
|
"properties": {
|
||||||
|
"product": "stretch",
|
||||||
|
"version": "1.2.3",
|
||||||
|
"hostname": f"{TEST_HOSTNAME2}.local.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_smile")
|
@pytest.fixture(name="mock_smile")
|
||||||
|
@ -52,20 +70,38 @@ def mock_smile():
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.plugwise.config_flow.Smile",
|
"homeassistant.components.plugwise.config_flow.Smile",
|
||||||
) as smile_mock:
|
) as smile_mock:
|
||||||
smile_mock.PlugwiseError = PlugwiseException
|
smile_mock.PlugwiseException = PlugwiseException
|
||||||
smile_mock.InvalidAuthentication = InvalidAuthentication
|
smile_mock.InvalidAuthentication = InvalidAuthentication
|
||||||
smile_mock.ConnectionFailedError = ConnectionFailedError
|
smile_mock.ConnectionFailedError = ConnectionFailedError
|
||||||
smile_mock.return_value.connect.return_value = True
|
smile_mock.return_value.connect.return_value = True
|
||||||
yield smile_mock.return_value
|
yield smile_mock.return_value
|
||||||
|
|
||||||
|
|
||||||
|
async def test_form_flow_gateway(hass):
|
||||||
|
"""Test we get the form for Plugwise Gateway product type."""
|
||||||
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={CONF_SOURCE: SOURCE_USER}
|
||||||
|
)
|
||||||
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
|
assert result["errors"] == {}
|
||||||
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"], user_input={FLOW_TYPE: FLOW_NET}
|
||||||
|
)
|
||||||
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
|
assert result["errors"] == {}
|
||||||
|
assert result["step_id"] == "user_gateway"
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass):
|
async def test_form(hass):
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={CONF_SOURCE: SOURCE_USER}, data={FLOW_TYPE: FLOW_NET}
|
||||||
)
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -77,17 +113,18 @@ async def test_form(hass):
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_HOST: TEST_HOST, CONF_PASSWORD: TEST_PASSWORD},
|
user_input={CONF_HOST: TEST_HOST, CONF_PASSWORD: TEST_PASSWORD},
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result2["data"] == {
|
assert result2["data"] == {
|
||||||
CONF_HOST: TEST_HOST,
|
CONF_HOST: TEST_HOST,
|
||||||
CONF_PASSWORD: TEST_PASSWORD,
|
CONF_PASSWORD: TEST_PASSWORD,
|
||||||
CONF_PORT: DEFAULT_PORT,
|
CONF_PORT: DEFAULT_PORT,
|
||||||
CONF_USERNAME: TEST_USERNAME,
|
CONF_USERNAME: TEST_USERNAME,
|
||||||
|
PW_TYPE: API,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
@ -98,10 +135,10 @@ async def test_zeroconf_form(hass):
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
||||||
data=TEST_DISCOVERY,
|
data=TEST_DISCOVERY,
|
||||||
)
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -113,17 +150,55 @@ async def test_zeroconf_form(hass):
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_PASSWORD: TEST_PASSWORD},
|
user_input={CONF_PASSWORD: TEST_PASSWORD},
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result2["data"] == {
|
assert result2["data"] == {
|
||||||
CONF_HOST: TEST_HOST,
|
CONF_HOST: TEST_HOST,
|
||||||
CONF_PASSWORD: TEST_PASSWORD,
|
CONF_PASSWORD: TEST_PASSWORD,
|
||||||
CONF_PORT: DEFAULT_PORT,
|
CONF_PORT: DEFAULT_PORT,
|
||||||
CONF_USERNAME: TEST_USERNAME,
|
CONF_USERNAME: TEST_USERNAME,
|
||||||
|
PW_TYPE: API,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_zeroconf_stretch_form(hass):
|
||||||
|
"""Test we get the form."""
|
||||||
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
||||||
|
data=TEST_DISCOVERY2,
|
||||||
|
)
|
||||||
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.plugwise.config_flow.Smile.connect",
|
||||||
|
return_value=True,
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.plugwise.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry:
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input={CONF_PASSWORD: TEST_PASSWORD},
|
||||||
|
)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
|
assert result2["data"] == {
|
||||||
|
CONF_HOST: TEST_HOST,
|
||||||
|
CONF_PASSWORD: TEST_PASSWORD,
|
||||||
|
CONF_PORT: DEFAULT_PORT,
|
||||||
|
CONF_USERNAME: TEST_USERNAME2,
|
||||||
|
PW_TYPE: API,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
@ -131,58 +206,68 @@ async def test_zeroconf_form(hass):
|
||||||
|
|
||||||
async def test_form_username(hass):
|
async def test_form_username(hass):
|
||||||
"""Test we get the username data back."""
|
"""Test we get the username data back."""
|
||||||
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={CONF_SOURCE: SOURCE_USER}, data={FLOW_TYPE: FLOW_NET}
|
||||||
)
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.plugwise.config_flow.Smile.connect",
|
"homeassistant.components.plugwise.config_flow.Smile",
|
||||||
return_value=True,
|
) as smile_mock, patch(
|
||||||
), patch(
|
|
||||||
"homeassistant.components.plugwise.async_setup_entry",
|
"homeassistant.components.plugwise.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
|
smile_mock.return_value.connect.side_effect = AsyncMock(return_value=True)
|
||||||
|
smile_mock.return_value.gateway_id = "abcdefgh12345678"
|
||||||
|
smile_mock.return_value.smile_hostname = TEST_HOST
|
||||||
|
smile_mock.return_value.smile_name = "Adam"
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
user_input={
|
||||||
CONF_HOST: TEST_HOST,
|
CONF_HOST: TEST_HOST,
|
||||||
CONF_PASSWORD: TEST_PASSWORD,
|
CONF_PASSWORD: TEST_PASSWORD,
|
||||||
CONF_USERNAME: TEST_USERNAME2,
|
CONF_USERNAME: TEST_USERNAME2,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result2["data"] == {
|
assert result2["data"] == {
|
||||||
CONF_HOST: TEST_HOST,
|
CONF_HOST: TEST_HOST,
|
||||||
CONF_PASSWORD: TEST_PASSWORD,
|
CONF_PASSWORD: TEST_PASSWORD,
|
||||||
CONF_PORT: DEFAULT_PORT,
|
CONF_PORT: DEFAULT_PORT,
|
||||||
CONF_USERNAME: TEST_USERNAME2,
|
CONF_USERNAME: TEST_USERNAME2,
|
||||||
}
|
PW_TYPE: API,
|
||||||
|
}
|
||||||
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
result3 = await hass.config_entries.flow.async_init(
|
result3 = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
||||||
data=TEST_DISCOVERY,
|
data=TEST_DISCOVERY,
|
||||||
)
|
)
|
||||||
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result3["type"] == RESULT_TYPE_FORM
|
||||||
assert result3["errors"] == {}
|
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.plugwise.config_flow.Smile.connect",
|
"homeassistant.components.plugwise.config_flow.Smile",
|
||||||
return_value=True,
|
) as smile_mock, patch(
|
||||||
), patch(
|
|
||||||
"homeassistant.components.plugwise.async_setup_entry",
|
"homeassistant.components.plugwise.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
|
smile_mock.return_value.side_effect = AsyncMock(return_value=True)
|
||||||
|
smile_mock.return_value.connect.side_effect = AsyncMock(return_value=True)
|
||||||
|
smile_mock.return_value.gateway_id = "abcdefgh12345678"
|
||||||
|
smile_mock.return_value.smile_hostname = TEST_HOST
|
||||||
|
smile_mock.return_value.smile_name = "Adam"
|
||||||
|
|
||||||
result4 = await hass.config_entries.flow.async_configure(
|
result4 = await hass.config_entries.flow.async_configure(
|
||||||
result3["flow_id"],
|
result3["flow_id"],
|
||||||
{CONF_PASSWORD: TEST_PASSWORD},
|
user_input={CONF_PASSWORD: TEST_PASSWORD},
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -194,7 +279,7 @@ async def test_form_username(hass):
|
||||||
async def test_form_invalid_auth(hass, mock_smile):
|
async def test_form_invalid_auth(hass, mock_smile):
|
||||||
"""Test we handle invalid auth."""
|
"""Test we handle invalid auth."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={CONF_SOURCE: SOURCE_USER}, data={FLOW_TYPE: FLOW_NET}
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_smile.connect.side_effect = InvalidAuthentication
|
mock_smile.connect.side_effect = InvalidAuthentication
|
||||||
|
@ -202,17 +287,17 @@ async def test_form_invalid_auth(hass, mock_smile):
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_HOST: TEST_HOST, CONF_PASSWORD: TEST_PASSWORD},
|
user_input={CONF_HOST: TEST_HOST, CONF_PASSWORD: TEST_PASSWORD},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result2["type"] == RESULT_TYPE_FORM
|
||||||
assert result2["errors"] == {"base": "invalid_auth"}
|
assert result2["errors"] == {"base": "invalid_auth"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect(hass, mock_smile):
|
async def test_form_cannot_connect(hass, mock_smile):
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={CONF_SOURCE: SOURCE_USER}, data={FLOW_TYPE: FLOW_NET}
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_smile.connect.side_effect = ConnectionFailedError
|
mock_smile.connect.side_effect = ConnectionFailedError
|
||||||
|
@ -220,17 +305,17 @@ async def test_form_cannot_connect(hass, mock_smile):
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_HOST: TEST_HOST, CONF_PASSWORD: TEST_PASSWORD},
|
user_input={CONF_HOST: TEST_HOST, CONF_PASSWORD: TEST_PASSWORD},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result2["type"] == RESULT_TYPE_FORM
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect_port(hass, mock_smile):
|
async def test_form_cannot_connect_port(hass, mock_smile):
|
||||||
"""Test we handle cannot connect to port error."""
|
"""Test we handle cannot connect to port error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={CONF_SOURCE: SOURCE_USER}, data={FLOW_TYPE: FLOW_NET}
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_smile.connect.side_effect = ConnectionFailedError
|
mock_smile.connect.side_effect = ConnectionFailedError
|
||||||
|
@ -238,17 +323,21 @@ async def test_form_cannot_connect_port(hass, mock_smile):
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_HOST: TEST_HOST, CONF_PASSWORD: TEST_PASSWORD, CONF_PORT: TEST_PORT},
|
user_input={
|
||||||
|
CONF_HOST: TEST_HOST,
|
||||||
|
CONF_PASSWORD: TEST_PASSWORD,
|
||||||
|
CONF_PORT: TEST_PORT,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result2["type"] == RESULT_TYPE_FORM
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_other_problem(hass, mock_smile):
|
async def test_form_other_problem(hass, mock_smile):
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={CONF_SOURCE: SOURCE_USER}, data={FLOW_TYPE: FLOW_NET}
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_smile.connect.side_effect = TimeoutError
|
mock_smile.connect.side_effect = TimeoutError
|
||||||
|
@ -256,10 +345,10 @@ async def test_form_other_problem(hass, mock_smile):
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_HOST: TEST_HOST, CONF_PASSWORD: TEST_PASSWORD},
|
user_input={CONF_HOST: TEST_HOST, CONF_PASSWORD: TEST_PASSWORD},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result2["type"] == RESULT_TYPE_FORM
|
||||||
assert result2["errors"] == {"base": "unknown"}
|
assert result2["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
|
@ -283,13 +372,13 @@ async def test_options_flow_power(hass, mock_smile) -> None:
|
||||||
|
|
||||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
|
|
||||||
result = await hass.config_entries.options.async_configure(
|
result = await hass.config_entries.options.async_configure(
|
||||||
result["flow_id"], user_input={CONF_SCAN_INTERVAL: 10}
|
result["flow_id"], user_input={CONF_SCAN_INTERVAL: 10}
|
||||||
)
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
CONF_SCAN_INTERVAL: 10,
|
CONF_SCAN_INTERVAL: 10,
|
||||||
}
|
}
|
||||||
|
@ -315,14 +404,14 @@ async def test_options_flow_thermo(hass, mock_smile) -> None:
|
||||||
|
|
||||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
|
|
||||||
result = await hass.config_entries.options.async_configure(
|
result = await hass.config_entries.options.async_configure(
|
||||||
result["flow_id"], user_input={CONF_SCAN_INTERVAL: 60}
|
result["flow_id"], user_input={CONF_SCAN_INTERVAL: 60}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
CONF_SCAN_INTERVAL: 60,
|
CONF_SCAN_INTERVAL: 60,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue