mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Izone component (#24550)
* iZone component * Rename constants to const. * Changes as per code review. * Stop listening if discovery times out. * Unload properly * Changes as per code review * Climate 1.0 * Use dispatcher instead of listener * Free air settings * Test case for config flow. * Changes as per code review * Fix error on shutdown * Changes as per code review * Lint fix * Black formatting * Black on test * Fix test * Lint fix * Formatting * Updated requirements * Remaining patches * Per code r/v
This commit is contained in:
committed by
Martin Hjelmare
parent
c8fb7ce98b
commit
b68b8430a4
83
tests/components/izone/test_config_flow.py
Normal file
83
tests/components/izone/test_config_flow.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""Tests for iZone."""
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.izone.const import IZONE, DISPATCH_CONTROLLER_DISCOVERED
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_disco():
|
||||
"""Mock discovery service."""
|
||||
disco = Mock()
|
||||
disco.pi_disco = Mock()
|
||||
disco.pi_disco.controllers = {}
|
||||
yield disco
|
||||
|
||||
|
||||
def _mock_start_discovery(hass, mock_disco):
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
def do_disovered(*args):
|
||||
async_dispatcher_send(hass, DISPATCH_CONTROLLER_DISCOVERED, True)
|
||||
return mock_coro(mock_disco)
|
||||
|
||||
return do_disovered
|
||||
|
||||
|
||||
async def test_not_found(hass, mock_disco):
|
||||
"""Test not finding iZone controller."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.izone.discovery.async_start_discovery_service"
|
||||
) as start_disco, patch(
|
||||
"homeassistant.components.izone.discovery.async_stop_discovery_service",
|
||||
return_value=mock_coro(),
|
||||
) as stop_disco:
|
||||
start_disco.side_effect = _mock_start_discovery(hass, mock_disco)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
IZONE, 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()
|
||||
|
||||
stop_disco.assert_called_once()
|
||||
|
||||
|
||||
async def test_found(hass, mock_disco):
|
||||
"""Test not finding iZone controller."""
|
||||
mock_disco.pi_disco.controllers["blah"] = object()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.izone.climate.async_setup_entry",
|
||||
return_value=mock_coro(True),
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.izone.discovery.async_start_discovery_service"
|
||||
) as start_disco, patch(
|
||||
"homeassistant.components.izone.async_start_discovery_service",
|
||||
return_value=mock_coro(),
|
||||
):
|
||||
start_disco.side_effect = _mock_start_discovery(hass, mock_disco)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
IZONE, 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()
|
||||
|
||||
mock_setup.assert_called_once()
|
||||
Reference in New Issue
Block a user