hass-core/tests/components/soma/test_config_flow.py
Tiit Rätsep 48d07467d9 Add support for SOMA Smartshades devices (#26226)
* Add Soma integration

* Fixed cover position get/set

* Try to list devices before creating config entries to see if Soma Connect can be polled

* Style fixes

* Updated requirements

* Updated .coveragerc to ignore Soma component

* Fixed linter errors

* Implemented stop command

* Test coverage fixes according to feedback

* Fixes to code according to feedback

* Added error logging and tested config from yaml

* Indentation fix

* Removed unnecessary method

* Wrong indentation

* Added some tests

* Added test for import step leading to entry creation

* Added feedback to user form in case of connection error

* Minor fixes according to feedback

* Changed exception type in error handling for connection to Connect

* To keep API consistent for Google Home and Alexa we swapped the open/closed position values back and I reversed them in this integration as well

* regenerated requirements, ran black, addde __init__.py to ignore file

* Added pysoma library to gen_requirements_all.py

* Added missing test case

* removed useless return value
2019-09-30 14:23:08 +02:00

60 lines
2.1 KiB
Python

"""Tests for the Soma config flow."""
from unittest.mock import patch
from api.soma_api import SomaApi
from requests import RequestException
from homeassistant import data_entry_flow
from homeassistant.components.soma import config_flow, DOMAIN
from tests.common import MockConfigEntry
MOCK_HOST = "123.45.67.89"
MOCK_PORT = 3000
async def test_form(hass):
"""Test user form showing."""
flow = config_flow.SomaFlowHandler()
flow.hass = hass
result = await flow.async_step_user()
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
async def test_import_abort(hass):
"""Test configuration from YAML aborting with existing entity."""
flow = config_flow.SomaFlowHandler()
flow.hass = hass
MockConfigEntry(domain=DOMAIN).add_to_hass(hass)
result = await flow.async_step_import()
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_setup"
async def test_import_create(hass):
"""Test configuration from YAML."""
flow = config_flow.SomaFlowHandler()
flow.hass = hass
with patch.object(SomaApi, "list_devices", return_value={}):
result = await flow.async_step_import({"host": MOCK_HOST, "port": MOCK_PORT})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
async def test_exception(hass):
"""Test if RequestException fires when no connection can be made."""
flow = config_flow.SomaFlowHandler()
flow.hass = hass
with patch.object(SomaApi, "list_devices", side_effect=RequestException()):
result = await flow.async_step_import({"host": MOCK_HOST, "port": MOCK_PORT})
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "connection_error"
async def test_full_flow(hass):
"""Check classic use case."""
hass.data[DOMAIN] = {}
flow = config_flow.SomaFlowHandler()
flow.hass = hass
with patch.object(SomaApi, "list_devices", return_value={}):
result = await flow.async_step_user({"host": MOCK_HOST, "port": MOCK_PORT})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY