hass-core/tests/components/gree/test_config_flow.py
Clifford Roche 4ce6d00a22
Improve the discovery process for Gree (#45449)
* Add support for async device discovery

* FIx missing dispatcher cleanup breaking integration reload

* Update homeassistant/components/gree/climate.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update homeassistant/components/gree/switch.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update homeassistant/components/gree/bridge.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Working on feedback

* Improving load/unload tests

* Update homeassistant/components/gree/__init__.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Working on more feedback

* Add tests covering async discovery scenarios

* Remove unnecessary shutdown

* Update homeassistant/components/gree/__init__.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Code refactor from reviews

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-04-13 11:54:03 +02:00

60 lines
2.2 KiB
Python

"""Tests for the Gree Integration."""
from unittest.mock import patch
from homeassistant import config_entries, data_entry_flow
from homeassistant.components.gree.const import DOMAIN as GREE_DOMAIN
from .common import FakeDiscovery
async def test_creating_entry_sets_up_climate(hass):
"""Test setting up Gree creates the climate components."""
with patch(
"homeassistant.components.gree.climate.async_setup_entry", return_value=True
) as setup, patch(
"homeassistant.components.gree.bridge.Discovery", return_value=FakeDiscovery()
), patch(
"homeassistant.components.gree.config_flow.Discovery",
return_value=FakeDiscovery(),
):
result = await hass.config_entries.flow.async_init(
GREE_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
# Confirmation form
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
await hass.async_block_till_done()
assert len(setup.mock_calls) == 1
async def test_creating_entry_has_no_devices(hass):
"""Test setting up Gree creates the climate components."""
with patch(
"homeassistant.components.gree.climate.async_setup_entry", return_value=True
) as setup, patch(
"homeassistant.components.gree.bridge.Discovery", return_value=FakeDiscovery()
) as discovery, patch(
"homeassistant.components.gree.config_flow.Discovery",
return_value=FakeDiscovery(),
) as discovery2:
discovery.return_value.mock_devices = []
discovery2.return_value.mock_devices = []
result = await hass.config_entries.flow.async_init(
GREE_DOMAIN, context={"source": config_entries.SOURCE_USER}
)
# Confirmation form
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
await hass.async_block_till_done()
assert len(setup.mock_calls) == 0